diff options
-rw-r--r-- | ext/bigdecimal/bigdecimal.c | 15 |
1 files changed, 14 insertions, 1 deletions
diff --git a/ext/bigdecimal/bigdecimal.c b/ext/bigdecimal/bigdecimal.c index 29bc1e5ca4..7b23826ac1 100644 --- a/ext/bigdecimal/bigdecimal.c +++ b/ext/bigdecimal/bigdecimal.c @@ -9,6 +9,8 @@ * of this BigDecimal distribution. * * NOTES: + * 2003-04-17 + * Bug in negative.exp(n) reported by Hitoshi Miyazaki fixed. * 2003-03-28 * V1.0 checked in to CVS(ruby/ext/bigdecimal). * use rb_str2cstr() instead of STR2CSTR(). @@ -4007,6 +4009,7 @@ VpExp(Real *y, Real *x) U_LONG p; U_LONG nc; U_LONG i; + short fNeg=0; if(!VpIsDef(x)) { VpSetNaN(y); /* Not sure */ @@ -4022,6 +4025,9 @@ VpExp(Real *y, Real *x) if(p<maxnr) nc = maxnr; else nc = p; + fNeg = x->sign; + if(fNeg<0) x->sign = -fNeg; + /* allocate temporally variables */ z = VpAlloc(p, "#1"); div = VpAlloc(p, "#1"); @@ -4047,9 +4053,16 @@ VpExp(Real *y, Real *x) VpAsgn(y, div, 1); /* y = y(new) */ } while(((!VpIsZero(c)) &&(c->exponent >= 0 ||((U_LONG)(-c->exponent)) <= y->MaxPrec)) && i<nc - ); + ); + + if(fNeg < 0) { + x->sign = fNeg; + VpDivd(div, r, VpConstOne, y); + VpAsgn(y, div, 1); + } Exit: + #ifdef _DEBUG if(gfDebug) { VPrint(stdout, "vpexp e=%\n", y); |