diff options
author | naruse <naruse@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2009-12-29 07:05:39 +0000 |
---|---|---|
committer | naruse <naruse@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2009-12-29 07:05:39 +0000 |
commit | 7ed0640ffb938fcf246f5167c7062fbf2a46dcd3 (patch) | |
tree | 03fe926eaafee97c67c833d82daa2137779b758f /test/ruby | |
parent | 92ab16fac66eeb9baba090af2976b27956ac56d4 (diff) | |
download | ruby-7ed0640ffb938fcf246f5167c7062fbf2a46dcd3.tar.gz |
Add Float::INFINITY and Float::NAN.
* numeric.c (Init_Numeric): Add Float::INFINITY and Float::NAN.
[ruby-dev:1657] [ruby-dev:4760] [ruby-list:7023] [ruby-list:46690]
[ruby-core:26632] [ruby-talk:41352] [ruby-talk:203333]
* include/ruby/defines.h (INFINITY): defined.
* include/ruby/defines.h (NAN): defined.
* include/ruby/util.h (ruby_div0): removed.
* numeric.c (fix_pow): use INFINITY and NAN instead of ruby_div0(1.0).
* marshal.c (r_object0): ditto.
* bignum.c (big_fdiv): ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@26197 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'test/ruby')
-rw-r--r-- | test/ruby/test_float.rb | 22 |
1 files changed, 11 insertions, 11 deletions
diff --git a/test/ruby/test_float.rb b/test/ruby/test_float.rb index 15e17ad92a..c18e4f0422 100644 --- a/test/ruby/test_float.rb +++ b/test/ruby/test_float.rb @@ -24,7 +24,7 @@ class TestFloat < Test::Unit::TestCase assert_equal(false, (x >= y)) end def test_nan - nan = 0.0/0 + nan = Float::NAN nan_test(nan, nan) nan_test(nan, 0) nan_test(nan, 1) @@ -118,7 +118,7 @@ class TestFloat < Test::Unit::TestCase end def test_to_s - inf = 1.0 / 0.0 + inf = Float::INFINITY assert_equal("Infinity", inf.to_s) assert_equal("-Infinity", (-inf).to_s) assert_equal("NaN", (inf / inf).to_s) @@ -171,7 +171,7 @@ class TestFloat < Test::Unit::TestCase assert_equal([1.0, 0.0], 2.0.divmod(2.0)) assert_raise(TypeError) { 2.0.divmod(nil) } - inf = 1.0 / 0.0 + inf = Float::INFINITY assert_raise(ZeroDivisionError) {inf.divmod(0)} a, b = (2.0**32).divmod(1.0) @@ -186,8 +186,8 @@ class TestFloat < Test::Unit::TestCase end def test_eql - inf = 1.0 / 0.0 - nan = inf / inf + inf = Float::INFINITY + nan = Float::NAN assert(1.0.eql?(1.0)) assert(inf.eql?(inf)) assert(!(nan.eql?(nan))) @@ -200,8 +200,8 @@ class TestFloat < Test::Unit::TestCase end def test_cmp - inf = 1.0 / 0.0 - nan = inf / inf + inf = Float::INFINITY + nan = Float::NAN assert_equal(0, 1.0 <=> 1.0) assert_equal(1, 1.0 <=> 0.0) assert_equal(-1, 1.0 <=> 2.0) @@ -232,14 +232,14 @@ class TestFloat < Test::Unit::TestCase end def test_infinite_p - inf = 1.0 / 0.0 + inf = Float::INFINITY assert(1, inf.infinite?) assert(1, (-inf).infinite?) assert_nil(1.0.infinite?) end def test_finite_p - inf = 1.0 / 0.0 + inf = Float::INFINITY assert(!(inf.finite?)) assert(!((-inf).finite?)) assert(1.0.finite?) @@ -266,7 +266,7 @@ class TestFloat < Test::Unit::TestCase assert_equal(-2, (-2.0).round) assert_equal(-2, (-2.0).truncate) - inf = 1.0/0.0 + inf = Float::INFINITY assert_raise(FloatDomainError) { inf.floor } assert_raise(FloatDomainError) { inf.ceil } assert_raise(FloatDomainError) { inf.round } @@ -413,7 +413,7 @@ class TestFloat < Test::Unit::TestCase assert(Float("1e10_00").infinite?) assert_raise(TypeError) { Float(nil) } o = Object.new - def o.to_f; inf = 1.0/0.0; inf/inf; end + def o.to_f; inf = Float::INFINITY; inf/inf; end assert(Float(o).nan?) end |