From: mike@... (Mike Stok) Date: 2003-08-12T11:21:04+09:00 Subject: Re: NaN and Inifinity In article , Scott Thompson wrote: >If I do something like > >a = Math::log(-1) > >then a properly takes the value NaN. > >Is there any way to explicitly assign the variable "a" to NaN (or >Inifinity or -Infinity) to begin with? I tried finding "NaN" as a >constant but couldn't locate it. It doesn't appear to be a constant in >Float or Math. I don't understand what you mean by 'assign the variable "a" to NaN'. NaNs and infinite values are best tested for using the nan? and infinite? methods. Note that infinite? returns +1 or -1 for positive and negative infinities and nil for finite numbers: >> a = 0.0/0.0 => NaN >> a.nan? => true >> a.infinite? => nil >> b = 0.0/0.0 => NaN >> b.nan? => true >> a == b => false >> (+1/0.0).infinite? => 1 >> (-1/0.0).infinite? => -1 >> 1.0.infinite? => nil >> 1 / (-1/0.0) => -0.0 I'm avoiding the mathematical justification for these behaviours, they're just what IEEE 754 math does. There are plenty of references on the web - http://grouper.ieee.org/groups/754/reading.html is a good starting point. Mike -- mike@stok.co.uk | The "`Stok' disclaimers" apply. http://www.stok.co.uk/~mike/ | GPG PGP Key 1024D/059913DA mike@exegenix.com | Fingerprint 0570 71CD 6790 7C28 3D60 http://www.exegenix.com/ | 75D2 9EC4 C1C0 0599 13DA