On Apr 16, 2009, at 12:29 PM, Shot (Piotr Szotkowski) wrote:
>> I would have thought that z.eql?(nz) might be false. There doesn't
>> seem to be a way to query a float to distinguish between -Infinity
>> and Infinity
>
> These actually aren√’ ==, eql? nor equal?

I wasn't very clear.  My point was that you have to do two tests to  
determine if an arbitrary float is negative infinity or positive  
infinity.

def negative_infinity?(x)
   !x.finite? and x < 0
end

I believe (but I didn't check...) there is just a single bit pattern  
in IEEE floating point that means 'negative infinity' or 'positive  
infinity' and so it should be implementable as a simple equality  
comparison.  Since Ruby floats are 'boxed' values I believe that test  ould have to be implemented in the runtime.

>> or between -0.0 and 0.0 other than via #to_s.
>
> -0.0.equal? 0.0 # => false

Yes but:

z1 = (0.0/1)
z2 = (0.0/1)
z3 = (0.0/-1)

z1 == z2  # true
z1 == z3  # true

z1.eql?(z2) # true
z1.eql?(z3) # true

z1.equal?(z2) # false
z1.equal?(z3) # false