diff options
author | mame <mame@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2010-01-26 12:52:49 +0000 |
---|---|---|
committer | mame <mame@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2010-01-26 12:52:49 +0000 |
commit | 05d80e2fc68675be7339a7b5a909c90680ed23bc (patch) | |
tree | f41c0daba7de5cf74e1da9d8ec9e7f7aac3c5fb0 | |
parent | 96542c36786fb4dd6a94d0b83834f267478f2241 (diff) | |
download | ruby-05d80e2fc68675be7339a7b5a909c90680ed23bc.tar.gz |
* ext/bigdecimal/bigdecimal.c (VpCtoV): BigDecimal("0E200000000000")
was Infinity, not 0.
* test/bigdecimal/test_bigdecimal.rb: add a test for above.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@26428 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r-- | ChangeLog | 7 | ||||
-rw-r--r-- | ext/bigdecimal/bigdecimal.c | 21 | ||||
-rw-r--r-- | test/bigdecimal/test_bigdecimal.rb | 1 |
3 files changed, 22 insertions, 7 deletions
@@ -1,3 +1,10 @@ +Tue Jan 26 21:50:31 2010 Yusuke Endoh <mame@tsg.ne.jp> + + * ext/bigdecimal/bigdecimal.c (VpCtoV): BigDecimal("0E200000000000") + was Infinity, not 0. + + * test/bigdecimal/test_bigdecimal.rb: add a test for above. + Tue Jan 26 21:36:22 2010 Tanaka Akira <akr@fsij.org> * configure.in: test unsetenv returns a value. diff --git a/ext/bigdecimal/bigdecimal.c b/ext/bigdecimal/bigdecimal.c index 38772f68f6..5a532e14e0 100644 --- a/ext/bigdecimal/bigdecimal.c +++ b/ext/bigdecimal/bigdecimal.c @@ -4009,13 +4009,14 @@ VpCtoV(Real *a, const char *int_chr, U_LONG ni, const char *frac, U_LONG nf, con U_LONG i, j, ind_a, ma, mi, me; U_LONG loc; S_INT e,es, eb, ef; - S_INT sign, signe; + S_INT sign, signe, exponent_overflow; /* get exponent part */ e = 0; ma = a->MaxPrec; mi = ni; me = ne; signe = 1; + exponent_overflow = 0; memset(a->frac, 0, ma * sizeof(U_LONG)); if(ne > 0) { i = 0; @@ -4031,12 +4032,8 @@ VpCtoV(Real *a, const char *int_chr, U_LONG ni, const char *frac, U_LONG nf, con es = e*((S_INT)BASE_FIG); e = e * 10 + exp_chr[i] - '0'; if(es>e*((S_INT)BASE_FIG)) { - VpException(VP_EXCEPTION_INFINITY,"exponent overflow",0); - sign = 1; - if(int_chr[0] == '-') sign = -1; - if(signe > 0) VpSetInf(a, sign); - else VpSetZero(a, sign); - return 1; + exponent_overflow = 1; + break; } ++i; } @@ -4078,6 +4075,16 @@ VpCtoV(Real *a, const char *int_chr, U_LONG ni, const char *frac, U_LONG nf, con eb = e / ((S_INT)BASE_FIG); + if(exponent_overflow) { + int zero = 1; + for( ; i < mi && zero; i++) zero = int_chr[i] == '0'; + for(i = 0; i < nf && zero; i++) zero = frac[i] == '0'; + if(!zero && signe > 0) VpSetInf(a, sign); + else VpSetZero(a, sign); + VpException(VP_EXCEPTION_INFINITY,"exponent overflow",0); + return 1; + } + ind_a = 0; while(i < mi) { a->frac[ind_a] = 0; diff --git a/test/bigdecimal/test_bigdecimal.rb b/test/bigdecimal/test_bigdecimal.rb index 4d2a28514e..a9dae35274 100644 --- a/test/bigdecimal/test_bigdecimal.rb +++ b/test/bigdecimal/test_bigdecimal.rb @@ -177,6 +177,7 @@ class TestBigDecimal < Test::Unit::TestCase def test_zero_p assert_equal(true, BigDecimal.new("0").zero?) assert_equal(false, BigDecimal.new("1").zero?) + assert_equal(true, BigDecimal.new("0E200000000000000").zero?) end def test_nonzero_p |