On Fri, 30 Mar 2001, Christoph Rippel wrote: > > Is there any good reason why Float's "Infinity" value is equal to itself? > > And then, is there any good reason why it shouldn't be changed? > Well, > the outcome of floating point division of 1 by +/-0.0 is either > Infinity or -Infinity and that they are different that just a > reflection of standard C double behavior. Not you can use > +/- Infinity as regular input and gets something sensible like > p Math.atan(1/-1.0) # => -0.7853981634 a.k.a -Pi/4 > p Math.atan(1/1.0) # => 0.7853981634 > so +/-Infinities have to be different. The I'm not proposing that +Infinity should be indistinguishable from -Infinity. I'm asking why is +Infinity == +Infinity and -Infinity == -Infinity. > hack is hardware independent and should work on all platforms. > The exception raising behavior of zero-division and comparison > is type specific on the method receiver end > 2**29 <=> 1/0.0 # => -1 since 2**29 is a Fixnum > 2**33 <=> 1/0.0 # FloatDomainError: Infinity since 2**33 is Bignum this should return -1 since although +Infinity is not a precise number, it is greater than all other finite values and -Infinity. (it is however noncomparable to itself and to NaN) > 1/ 0 # a ZeroDivisionError is raised for any Integer type This is ok, because the Integer domain has no equivalent of Infinities and NaNs. > I actually have a Ruby hack of logical +/- Infinity's constants. > The semantics is closer to +/- nil and but you can perform limited > Arithmetic on them - I made them instances of +/- Infinity Classes > sub-typed from Numeric but this is not really necessary. (the are > necessarily smaller/bigger then floats infinities). May I see that? Btw, what are +nil and -nil ??? > methods input of any numeric object (except for Rational, which > is an eager beaver and tries to process input it does not > understand instead of calling coerce). Do you think Rational should be fixed to act, ehm, more rationally? matju