From: Scott Thompson Date: 2003-08-12T11:44:53+09:00 Subject: Re: NaN and Inifinity >> 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: In the C library that I am trying to expose to Ruby there is a constant for a NULL rectangle. You would get a NULL rectangle, for example, if you asked for the intersection of two disjoint rectangles. The NULL rectangle is very different from the "zero rectangle" (a rectangle whose corner is at the origin and whose height and width are zero). The NULL rectangle is implemented as a rectangle whose lower left corner is at (+Infinity, +Infinity) and whose height and width are both zero. I wanted to make sure that if I exposed that constant to Ruby that it would behave as expected. As a result, I was trying to experiment with "irb" and I wanted to create an instance of my "Point" object whose x and y coordinates were +Infinity. I was looking to do something like: apoint = CGPoint.new(Float::Infinity, Float::Infinity) when I couldn't find Infinity I started looking for NaN as well. I found some sample code on the internet that showed how to generate a NaN result, but not how to initialize a float to NaN or +/-Infinity. It seems, in some cases, it might be valuable to assign a float to "a value that is not a legal value" similar to the way one might assign a pointer to NULL in C, or even a object reference to nil in Ruby. But that may be just me :-) Scott