From: Joel VanderWerf Date: 2003-01-18T07:48:36+09:00 Subject: Re: Accessing Infinity Kent Dahl wrote: > Joel VanderWerf wrote: > >>Well, Ruby's floating point number system does include two infinities, >>so I guess it's reasonable to compare with them... > > > This might sound a bit pedantic but: > > Ruby doesn't provide the two infinitive numbers. The underlying floating > point routines do. So you don't have two infinities, since any Float > object can be infinite. You can have an infinite number of infinities. > > $ irb > irb(main):001:0> a = 1.0/0 > Infinity > irb(main):002:0> b = 1.0/0 > Infinity > irb(main):003:0> a.id > 537929428 > irb(main):004:0> b.id > 537915848 > irb(main):005:0> a.equal? b > false But... (1.2).equal?(1.2) # ==> false (10**100).equal?(10**100) # ==> false Does that mean there are an infinity of googols? I don't think #equal? is the mathematically correct comparison for numbers that may be implemented as heap allocated entities. That's the job of #==. > So the only use for the Infinity constants I can see, is for clarity > (and space conserving) when you explicitly assign Infinity to more than > one variable. Creating them for comparison is just plain wasteful, as it > is one more object in ObjectSpace and a more complicated comparison, > having to look into two objects instead of one. That's why I define a constant... (and also so I can use it in case statements, though I'm not sure I ever have, so I will shut up now :-)