Dave Baldwin
4/4/2005 12:50:00 PM
On 4 Apr 2005, at 12:48, Geert Fannes wrote:
> Hello, the following statement gives different results on windows and
> linux:
> Linux:
>
> irb(main):003:0> Math.sqrt(0.0/0.0)
>
> * NaN
>
Mac OS X gives this result.
> Windows:
>
> irb(main):002:0> Math.sqrt(0.0/0.0)
>
> Errno::EDOM: Domain error - sqrt
>
> from (irb):2:in `sqrt'
>
> from (irb):2
>
> I guess this is not as it should be. Which is the correct way to handle
> NaNs?
>
> How can I generate NaN without using the trick 0.0/0.0. Why does 0/0
> give a ZeroDivisionError and 0.0/0.0 a NaN
>
>
0/0 is integer division and all bit patterns are used.
0.0/0.0 is floating point division and for IEEE floating point numbers
the result is defined by the standard to be NaN. Bit patterns has been
reserved to all information like this to be encoded in the number.
Can't help you with what Windows is doing or how to generate a NaN more
cleanly from Ruby. It would be very simple to generate one as part of
a C extension.
Dave.
>
> Greetings,
>
> Geert Fannes.
>