Math.sqrt(NaN) behaves differently on windows and linux

G

Geert Fannes

------_=_NextPart_001_01C53901.3DA362B8
Content-Type: text/plain;
charset="us-ascii"
Content-Transfer-Encoding: quoted-printable

Hello, the following statement gives different results on windows and
linux:

=20

Linux:

irb(main):003:0> Math.sqrt(0.0/0.0)

* NaN

=20

=20

Windows:

irb(main):002:0> Math.sqrt(0.0/0.0)

Errno::EDOM: Domain error - sqrt

from (irb):2:in `sqrt'

from (irb):2

=20

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

=20

Greetings,

Geert Fannes.


------_=_NextPart_001_01C53901.3DA362B8--
 
D

Dave Baldwin

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top