From: mike@... (Mike Stok) Date: 2003-08-12T11:41:11+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. If you are using IEEE 754 math then you can try [mike@ratdog mike]$ irb --simple-prompt >> negInf = *['FFF0000000000000'].pack('H*').unpack('G') => -Infinity >> inf = *['7FF0000000000000'].pack('H*').unpack('G') => Infinity >> negInf.infinite? => -1 >> nan = *['7FF8000000000000'].pack('H*').unpack('G') => NaN >> nan.nan? => true >> nan == nan => false (though there are a lot of ways to initialise a nan...) Once you have them in a variable then there's not much you can do with them. Hope this helps, 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