Also "NaN".to_f returns 0 instead of NaN.
A:
0.0 / 0.0
works for me on ruby 1.8.6.
The thread linked to by Pesto has this function, which should work on platforms where floating-point numbers are implemented according to IEEE 754:
def aNaN
s, e, m = rand(2), 2047, rand(2**52-1)+1
[sprintf("%1b%011b%052b", s,e,m)].pack("B*").unpack("G").first
end
Nathan Kitchen
2009-04-30 19:40:25
that gives ZeroDivisionError: divided by 0
2009-04-30 19:54:28
Which version of Ruby are you using?
Nathan Kitchen
2009-04-30 20:55:17
+3
A:
The simplest way is to use 0.0 / 0.0
. "NaN".to_f doesn't work, and there's some discussion in this thread about why.
Pesto
2009-04-30 19:41:39