Mike Stok wrote: > In article <3E286515.4000301 / path.berkeley.edu>, Joel VanderWerf wrote: > >>Robert Klemme wrote: >> >>>Hi there, >>> >>>is there another way of accessing Infinity or -Infinity other than doing >>>1.0/0 or -1.0/0? I could not find any... TIA! >> >>I couldn't find anything either, so I do this sometimes: >> >>class Float >> Infinity = 1.0/0 >>end >> >>if -3.0/0 == Float::Infinity >> puts "infinite" >>end > > > Is it reasonable to compare infinities? I would tend to use > Float#finite? (there's also Float#nan? for not-a-numbers) so that I > could say > > if not (-3.0/0).finite? > puts 'infinite' > end > > Mike Well, Ruby's floating point number system does include two infinities, so I guess it's reasonable to compare with them... I think I defined the constant so I could use it in case statements, but you're right, #finite? is cleaner.