Date: Wed, 15 Mar 2000 10:54:47 +0200 (IST) From: Eli Zaretskii X-Sender: eliz AT is To: Martin Str|mberg cc: DJGPP-WORKERS Subject: Re: Unnormals??? In-Reply-To: <200003142156.WAA20972@father.ludd.luth.se> Message-ID: MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII Reply-To: djgpp-workers AT delorie DOT com Errors-To: dj-admin AT delorie DOT com X-Mailing-List: djgpp-workers AT delorie DOT com X-Unsubscribes-To: listserv AT delorie DOT com Precedence: bulk On Tue, 14 Mar 2000, Martin Str|mberg wrote: > I'm looking at doprnt.c in libc. We evidently print "Unnormal" for > certain floting point numbers. We print Unnormal for something that is not a valid FP number, like if you fill a buffer with arbitrary text and then pass it to a function which expects a double. We _must_ print something special for this case, because if we let that garbage into the FPU, it produces a NaN. Since NaNs are detected early in doprnt, the rest of the code doesn't defend itself against such a calamity, and eventually crashes. (The technical reason is that a NaN produces false in every comparison, so you end up in an impossible state, whereby a loop which produces the printed representation character by character never ends and eventually blows up the stack. This was a bug in v2.02 which got fixed in v2.03.) > The standard doesn't mention them. Is this ok? The standard also doesn't say it cannot be done. The only alternative is to print NaN, which is IMHO misleading. > Can NaNs be negative? Yes. A NaN has a sign bit, as any other FP number. > The standard seems to say we should print > "[-]nan" or "[-]nan(n-char-sequence)" ("n-char-sequence" is in > italics). What is n-char-sequence supposed to be? I didn't understand this when I read it, either. Anybody?