diff options
Diffstat (limited to 'ext/bigdecimal')
-rw-r--r-- | ext/bigdecimal/bigdecimal.c | 22 | ||||
-rw-r--r-- | ext/bigdecimal/bigdecimal.gemspec | 2 |
2 files changed, 18 insertions, 6 deletions
diff --git a/ext/bigdecimal/bigdecimal.c b/ext/bigdecimal/bigdecimal.c index adce9de5a8..bc7fcc6ee8 100644 --- a/ext/bigdecimal/bigdecimal.c +++ b/ext/bigdecimal/bigdecimal.c @@ -25,7 +25,6 @@ #include <string.h> #include <errno.h> #include <math.h> -#include "math.h" #ifdef HAVE_IEEEFP_H #include <ieeefp.h> @@ -1792,10 +1791,10 @@ BigDecimal_fix(VALUE self) * more than that many digits. * * If n is specified and negative, at least that many digits to the left of the - * decimal point will be 0 in the result. + * decimal point will be 0 in the result, and return value will be an Integer. * * BigDecimal('3.14159').round(3) #=> 3.142 - * BigDecimal('13345.234').round(-2) #=> 13300.0 + * BigDecimal('13345.234').round(-2) #=> 13300 * * The value of the optional mode argument can be used to determine how * rounding is performed; see BigDecimal.mode. @@ -1808,6 +1807,7 @@ BigDecimal_round(int argc, VALUE *argv, VALUE self) int iLoc = 0; VALUE vLoc; VALUE vRound; + int round_to_int = 0; size_t mx, pl; unsigned short sw = VpGetRoundMode(); @@ -1815,6 +1815,7 @@ BigDecimal_round(int argc, VALUE *argv, VALUE self) switch (rb_scan_args(argc, argv, "02", &vLoc, &vRound)) { case 0: iLoc = 0; + round_to_int = 1; break; case 1: if (RB_TYPE_P(vLoc, T_HASH)) { @@ -1822,6 +1823,7 @@ BigDecimal_round(int argc, VALUE *argv, VALUE self) } else { iLoc = NUM2INT(vLoc); + if (iLoc < 1) round_to_int = 1; } break; case 2: @@ -1843,7 +1845,7 @@ BigDecimal_round(int argc, VALUE *argv, VALUE self) GUARD_OBJ(c, VpCreateRbObject(mx, "0")); VpSetPrecLimit(pl); VpActiveRound(c, a, sw, iLoc); - if (argc == 0) { + if (round_to_int) { return BigDecimal_to_i(ToValue(c)); } return ToValue(c); @@ -2363,7 +2365,10 @@ BigDecimal_power(int argc, VALUE*argv, VALUE self) } goto retry; } - exp = GetVpValueWithPrec(vexp, DBL_DIG+1, 1); + if (NIL_P(prec)) { + n += DBLE_FIG; + } + exp = GetVpValueWithPrec(vexp, DBLE_FIG, 1); break; case T_RATIONAL: @@ -2378,6 +2383,9 @@ BigDecimal_power(int argc, VALUE*argv, VALUE self) goto retry; } exp = GetVpValueWithPrec(vexp, n, 1); + if (NIL_P(prec)) { + n += n; + } break; case T_DATA: @@ -2388,6 +2396,10 @@ BigDecimal_power(int argc, VALUE*argv, VALUE self) vexp = BigDecimal_to_i(vexp); goto retry; } + if (NIL_P(prec)) { + GUARD_OBJ(y, GetVpValue(vexp, 1)); + n += y->Prec*VpBaseFig(); + } exp = DATA_PTR(vexp); break; } diff --git a/ext/bigdecimal/bigdecimal.gemspec b/ext/bigdecimal/bigdecimal.gemspec index 5cf0726e1e..980deb07b4 100644 --- a/ext/bigdecimal/bigdecimal.gemspec +++ b/ext/bigdecimal/bigdecimal.gemspec @@ -1,6 +1,6 @@ # coding: utf-8 -bigdecimal_version = '2.0.1' +bigdecimal_version = '2.0.2' Gem::Specification.new do |s| s.name = "bigdecimal" |