From: Colin Bartlett Date: 2010-04-02T04:48:32+09:00 Subject: Re: Is there a method to set variable to NaN or Infinity? On Thu, Apr 1, 2010 at 3:57 PM, Alex DeCaria wrote: > Is there a built-in method to set a floating point value to NaN or > Infinity?  Or, is the only way to do this by > a = 0.0/0.0  #  set a to NaN > b = 3.0/0.0  #  set b to Infinity > c = -3.0/0.0  # set c to -Infinity In the past I have done something like: Float::NaN = 0.0 / 0.0 #=> NaN Float::Infinity = 3.0 / 1.0 #=> Infinity -Float::Infinity #=> -Infinity In other words, do they have to be methods? Can they just be constants? (But I think it might be useful to have those constants automatically in Float?) > Also, how can I set value to -NaN?  This is possible in other languages, > but I can't do it in Ruby.  I've tried: > a = 0.0/0.0 > b = -a > but b still comes out NaN. I'm curious: which languages have a -NaN value and why would you want to use it instead of just NaN? I've just tried Octave, and in that n = 0.0 / 0.0 #=> NaN nn = -n #=> NaN so I assume that there isn't a "-NaN" in Octave, although as Nan == NaN returns 0 (false) I'd need to look at the documentation to be sure. Colin Bartlett