On Wednesday 13 October 2004 08:38 am, Yukihiro Matsumoto wrote:
| Hi,
|
| In message "Re: "nan".to_f ?"
|
|     on Wed, 13 Oct 2004 21:18:38 +0900, Markus <markus / reality.com> writes:
| |> It's not valid string representation of a float.
| |
| |      Then why does:
| |
| |x = 0.0/0.0
| |x.class      #Float
| |x.to_s      #NaN
| |
| |      If "NaN" is not the valid string representation of a Float, why
| |does calling Float#to_s return it?
|
| 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.

Not sure if portable, but one might try

  (-1.0) ** 0.5

(Interesting also that '**' precedence is greater than '-'.)

T.