delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp-workers/2003/04/07/14:01:16

Sender: rich AT phekda DOT freeserve DOT co DOT uk
Message-ID: <3E91BCDD.5789AD76@phekda.freeserve.co.uk>
Date: Mon, 07 Apr 2003 19:01:01 +0100
From: Richard Dawe <rich AT phekda DOT freeserve DOT co DOT uk>
X-Mailer: Mozilla 4.77 [en] (X11; U; Linux 2.2.23 i586)
X-Accept-Language: de,fr
MIME-Version: 1.0
To: djgpp-workers AT delorie DOT com
Subject: Re: Support for nan(0x[0-9a-f]*) in strto*, *printf
References: <200304071443 DOT QAA22691 AT lws256 DOT lu DOT erisoft DOT se>
Reply-To: djgpp-workers AT delorie DOT com

Hello.

Martin Stromberg wrote:
> 
> I said:
> > I propose all strto*() do use an unsigned long long to store the
> > mantissa (X) given in "nan(X)". If X > the maximum for float or
> > double, set the mantissa to all-ones (we clamp the value to the
> > maximum possible).
> >
> > This will make ``strtof(sprintf(s, "%d", NAN), NULL)'' return a
> > NaN.
> 
> Am I confused or what? ``strtof(sprintf(s, "%d", NAN), NULL)'' would
> return a NaN even in my earlier posted implementation. The only
> difference is that the bits might be set differently.
> 
> Do you have any preferences (clamping or masking)?

I think I prefer masking. It just "feels" better - probably because the NaN
will look more like NAN than nan(0x0) (or whatever).

> > If *printf() will handle NaN in a double separately from long doubles
> > this should make ``double value1 =
> > extreme_cpu_use_generating_unusual_nans();
> > double value2 = strtod(sprintf(s, "%d", value1), NULL)'' make the bit
> > pattern of value1 == the bit pattern of value2.
> 
> This is sane though (IMO).

Yes, I think that the identity should hold for doubles and long doubles.
Whether that is true in reality is another question. (In other words, I have
to write some code. ;) )

Bye, Rich =]

-- 
Richard Dawe [ http://www.phekda.freeserve.co.uk/richdawe/ ]

- Raw text -


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