From 1c3e07f0d6d237222192f41c84716c15731b3158 Mon Sep 17 00:00:00 2001 From: mrkn Date: Sat, 3 Jul 2010 07:47:00 +0000 Subject: * ext/bigdecimal/bigdecimal.c (Init_bigdecimal): add two new constants BigDecimal::INFINITY and BigDecimal::NAN. * ext/bigdecimal/lib/bigdecimal/math.rb (BigMath.exp): modify the behaviors for infinity arguments as same as Math.exp. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@28533 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- test/bigdecimal/test_bigdecimal.rb | 8 ++++++++ test/bigdecimal/test_bigmath.rb | 8 ++++++++ 2 files changed, 16 insertions(+) (limited to 'test') diff --git a/test/bigdecimal/test_bigdecimal.rb b/test/bigdecimal/test_bigdecimal.rb index b622358758..a699d0c488 100644 --- a/test/bigdecimal/test_bigdecimal.rb +++ b/test/bigdecimal/test_bigdecimal.rb @@ -709,4 +709,12 @@ class TestBigDecimal < Test::Unit::TestCase ensure GC.stress = stress end + + def test_INFINITY + assert(BigDecimal::INFINITY.infinite?, "BigDecimal::INFINITY is not a infinity") + end + + def test_NAN + assert(BigDecimal::NAN.nan?, "BigDecimal::NAN is not NaN") + end end diff --git a/test/bigdecimal/test_bigmath.rb b/test/bigdecimal/test_bigmath.rb index 453c47ec6b..ae3cb9d5f9 100644 --- a/test/bigdecimal/test_bigmath.rb +++ b/test/bigdecimal/test_bigmath.rb @@ -67,6 +67,14 @@ class TestBigMath < Test::Unit::TestCase assert_in_epsilon(Math.exp(40), exp(BigDecimal("40"), N)) assert_in_epsilon(Math.exp(-N), exp(BigDecimal("-20"), N)) assert_in_epsilon(Math.exp(-40), exp(BigDecimal("-40"), N)) + begin + old_mode = BigDecimal.mode(BigDecimal::EXCEPTION_INFINITY) + BigDecimal.mode(BigDecimal::EXCEPTION_INFINITY, false) + assert(exp(BigDecimal::INFINITY, N).infinite?, "exp(INFINITY) is not an infinity") + ensure + #BigDecimal.mode(BigDecimal::EXCEPTION_INFINITY, old_mode) + end + assert_equal(0.0, exp(-BigDecimal::INFINITY, N)) end def test_log -- cgit v1.2.3