diff options
author | akr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2012-07-16 09:08:58 +0000 |
---|---|---|
committer | akr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2012-07-16 09:08:58 +0000 |
commit | 94735e9e54b7a64af86adf36ad8a5b849f11a938 (patch) | |
tree | b7cfebe287720b03fa19e36c35e12b3e69cfef3e /test | |
parent | 984729ba3016a1fd4b371edef71fcb8b7f3956b4 (diff) | |
download | ruby-94735e9e54b7a64af86adf36ad8a5b849f11a938.tar.gz |
* bignum.c (rb_big_float_cmp): compare an integer and float precisely.
[ruby-core:31376] [Bug #3589] reported by Tomasz Wegrzanowski.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@36404 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'test')
-rw-r--r-- | test/ruby/test_float.rb | 49 |
1 files changed, 49 insertions, 0 deletions
diff --git a/test/ruby/test_float.rb b/test/ruby/test_float.rb index f561d00158..a63c18f8bc 100644 --- a/test/ruby/test_float.rb +++ b/test/ruby/test_float.rb @@ -57,6 +57,55 @@ class TestFloat < Test::Unit::TestCase assert_equal(a == b, b == a) end + def test_cmp_int + 100.times {|i| + int0 = 1 << i + [int0, -int0].each {|int| + flt = int.to_f + bigger = int + 1 + smaller = int - 1 + assert_operator(flt, :==, int) + assert_operator(flt, :>, smaller) + assert_operator(flt, :>=, smaller) + assert_operator(flt, :<, bigger) + assert_operator(flt, :<=, bigger) + assert_equal(0, flt <=> int) + assert_equal(-1, flt <=> bigger) + assert_equal(1, flt <=> smaller) + assert_operator(int, :==, flt) + assert_operator(bigger, :>, flt) + assert_operator(bigger, :>=, flt) + assert_operator(smaller, :<, flt) + assert_operator(smaller, :<=, flt) + assert_equal(0, int <=> flt) + assert_equal(-1, smaller <=> flt) + assert_equal(1, bigger <=> flt) + [ + [int, flt + 0.5, bigger], + [smaller, flt - 0.5, int] + ].each {|smaller2, flt2, bigger2| + next if flt2 == flt2.round + assert_operator(flt2, :!=, smaller2) + assert_operator(flt2, :!=, bigger2) + assert_operator(flt2, :>, smaller2) + assert_operator(flt2, :>=, smaller2) + assert_operator(flt2, :<, bigger2) + assert_operator(flt2, :<=, bigger2) + assert_equal(-1, flt2 <=> bigger2) + assert_equal(1, flt2 <=> smaller2) + assert_operator(smaller2, :!=, flt2) + assert_operator(bigger2, :!=, flt2) + assert_operator(bigger2, :>, flt2) + assert_operator(bigger2, :>=, flt2) + assert_operator(smaller2, :<, flt2) + assert_operator(smaller2, :<=, flt2) + assert_equal(-1, smaller2 <=> flt2) + assert_equal(1, bigger2 <=> flt2) + } + } + } + end + def test_strtod a = Float("0") assert(a.abs < Float::EPSILON) |