[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Re: "nan".to_f ?

Warren Brown

10/15/2004 7:51:00 PM

Matz,

> Although we can tell whether a float value is NaN by
> using isnan(), but as far as I know there's no
> portably way to generate NaN. I think it's not
> guaranteed that 0.0/0.0 generate NaN.
>
> If I'm wrong, feel free to correct me.

From what I can tell from Googling, the following operations are
*guaranteed* by IEEE Standard 754 to produce NaNs (where Inf = 1.0 /
0.0):

Inf - Inf
Inf * 0
0 / 0
Inf / Inf
x % 0
Inf % x
sqrt(x) (where x < 0)

One particularly authoritative document is at
http://grouper.ieee.org/.... The first bullet near the bottom is
a link to David Goldberg's article "What Every Computer Scientist Should
Know about Floating-Point Arithmetic". Page 199 gives a table similar
to this one.

Of course, not every floating point package is IEEE Standard 754,
but these operations should produce NaNs regardless of the standard
used, since there are no other legal values available.

Do we know of any other floating-point standards that Ruby needs to
support?

- Warren Brown