1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

* 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
This commit is contained in:
mame 2010-01-26 12:52:49 +00:00
parent 96542c3678
commit 05d80e2fc6
3 changed files with 22 additions and 7 deletions

View file

@ -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.

View file

@ -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;

View file

@ -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