delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp-workers/2000/03/15/05:13:36

Date: Wed, 15 Mar 2000 10:54:47 +0200 (IST)
From: Eli Zaretskii <eliz AT is DOT elta DOT co DOT il>
X-Sender: eliz AT is
To: Martin Str|mberg <ams AT ludd DOT luth DOT se>
cc: DJGPP-WORKERS <djgpp-workers AT delorie DOT com>
Subject: Re: Unnormals???
In-Reply-To: <200003142156.WAA20972@father.ludd.luth.se>
Message-ID: <Pine.SUN.3.91.1000315105430.17230R-100000@is>
MIME-Version: 1.0
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

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 -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019