Mail Archives: djgpp-workers/2000/03/15/05:13:36
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?
- Raw text -