From: Tomasz Wegrzanowski Date: 2010-07-24T13:14:59+09:00 Subject: [ruby-core:31470] [Bug #3609] Float Infinity comparisons in 1.9 Bug #3609: Float Infinity comparisons in 1.9 http://redmine.ruby-lang.org/issues/show/3609 Author: Tomasz Wegrzanowski Status: Open, Priority: Normal ruby -v: ruby 1.9.1p429 (2010-07-02 revision 28523) [i386-darwin9] The way <=> works on pretty much everything in Ruby is that if a <=> b return 0, 1, or -1, it completely determines the entire set of comparisons a==b, a>=b, a>b, a<=b, aa, b==a, b>=a, b>a, b<=a, b "foo" # => 1 "foo" <=> inf # ArgumentError: comparison of String with Float failed This interacts even more strangely with very large bignums and the "if bignum converts to float, it equals that float" thing Ruby currently does [ruby-core:31376]. inf=1.0/0.0 huge=10**500 Consistent either way: inf >= huge # => true huge <= inf # => true inf < huge # => false huge > inf # => false Consistent only with mathematical interpretation (or with "equal if converts, except for special cases for infinities"): inf <=> huge # => 1 huge<=> inf # => -1 huge < inf # => true huge >= inf # => false Consistent only with "equal if converts": inf == huge # => true huge == inf # => true inf > huge # => false inf <= huge # => true Now I'd definitely prefer mathematical interpretation of floats, to "equal if converts", but this just doesn't make any sense no matter which way I look at it. ---------------------------------------- http://redmine.ruby-lang.org