From: Dave Baldwin Date: 2005-04-04T21:49:55+09:00 Subject: Re: Math.sqrt(NaN) behaves differently on windows and linux 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. >