Jeff Abrahamson on 18 Aug 2004 12:00:04 -0000


[Date Prev] [Date Next] [Thread Prev] [Thread Next] [Date Index] [Thread Index]

Re: [PLUG] Re: How to specify NaN in C programs?


On Tue, Aug 17, 2004 at 05:09:46PM -0400, Chip Salzenberg wrote:
>   [26 lines, 82 words, 886 characters]  Top characters: _itnlsau
> 
> According to Walt Mankowski:
> > Since I'm writing this in C (well, really C++, but in this case I
> > don't think it makes any difference)
> 
> Actually, it does.  :-)  After:
> 
>   #include <limits>
> 
> You want to use one of:
> 
>   std::numeric_limits<double>::quiet_NaN()
>   std::numeric_limits<double>::signaling_NaN()
> 
> But (at this point my research is fuzzy) you may want to check these
> first:
> 
>   std::numeric_limits<double>::has_quiet_NaN
>   std::numeric_limits<double>::has_signaling_NaN

And if you want to stay compatible with C, you can always set it by
dividing by zero:

    float f = 0.0 / 0.0;

You may have to fiddle with signals to avoid faulting, but I've
certainly done this by accident. ;-)

-- 
 Jeff

 Jeff Abrahamson  <http://www.purple.com/jeff/>    +1 215/837-2287
 GPG fingerprint: 1A1A BA95 D082 A558 A276  63C6 16BF 8C4C 0D1D AE4B

 A cool book of games, highly worth checking out:
 http://www.amazon.com/exec/obidos/ASIN/1931686963/purple-20

Attachment: signature.asc
Description: Digital signature