diff options
Diffstat (limited to 'test/ruby/test_bignum.rb')
-rw-r--r-- | test/ruby/test_bignum.rb | 23 |
1 files changed, 19 insertions, 4 deletions
diff --git a/test/ruby/test_bignum.rb b/test/ruby/test_bignum.rb index b77fd8f683..40c4f21c3f 100644 --- a/test/ruby/test_bignum.rb +++ b/test/ruby/test_bignum.rb @@ -175,6 +175,8 @@ class TestBignum < Test::Unit::TestCase def test_to_f assert_nothing_raised { T31P.to_f.to_i } assert_raise(FloatDomainError) { (1024**1024).to_f.to_i } + assert_equal(1, (2**50000).to_f.infinite?) + assert_equal(-1, (-(2**50000)).to_f.infinite?) end def test_cmp @@ -208,8 +210,9 @@ class TestBignum < Test::Unit::TestCase assert_equal(-1, (x+1) - (x+2)) assert_equal(0, (2**100) - (2.0**100)) o = Object.new - def o.coerce(x); [2**100+2, x]; end - assert_equal(1, (2**100+1) - o) + def o.coerce(x); [x, 2**100+2]; end + assert_equal(-1, (2**100+1) - o) + assert_equal(-1, T_ONE - 2) end def test_plus @@ -219,7 +222,7 @@ class TestBignum < Test::Unit::TestCase assert_equal(1267651809154049016125877911552, (2**80) + (2**100)) assert_equal(2**101, (2**100) + (2.0**100)) o = Object.new - def o.coerce(x); [2**80, x]; end + def o.coerce(x); [x, 2**80]; end assert_equal(1267651809154049016125877911552, (2**100) + o) end @@ -232,7 +235,7 @@ class TestBignum < Test::Unit::TestCase assert_equal(T32.to_f, T32 * 1.0) assert_raise(TypeError) { T32 * "foo" } o = Object.new - def o.coerce(x); [2**100, x]; end + def o.coerce(x); [x, 2**100]; end assert_equal(2**180, (2**80) * o) end @@ -413,4 +416,16 @@ class TestBignum < Test::Unit::TestCase assert_in_delta(1.0, @fmax2.fdiv(@fmax2), 0.01) end + def test_float_fdiv + b = 1E+300.to_i + assert_equal(b, (b ** 2).fdiv(b)) + assert(@big.fdiv(0.0 / 0.0).nan?) + assert_in_delta(1E+300, (10**500).fdiv(1E+200), 1E+285) + end + + def test_obj_fdiv + o = Object.new + def o.coerce(x); [x, 2**100]; end + assert_equal((2**200).to_f, (2**300).fdiv(o)) + end end |