diff --git a/ext/bigdecimal/bigdecimal.c b/ext/bigdecimal/bigdecimal.c index beedb7c2..83816297 100644 --- a/ext/bigdecimal/bigdecimal.c +++ b/ext/bigdecimal/bigdecimal.c @@ -3176,7 +3176,7 @@ BigDecimal_power(int argc, VALUE*argv, VALUE self) } VpPowerByInt(y.real, x.real, int_exp); if (!NIL_P(prec) && VpIsDef(y.real)) { - VpMidRound(y.real, VpGetRoundMode(), n); + VpMidRound(y.real, VpGetRoundMode(), n - VpExponent10(y.real)); } return CheckGetValue(y); } diff --git a/test/bigdecimal/test_bigdecimal.rb b/test/bigdecimal/test_bigdecimal.rb index e14a9f0f..fe0cb786 100644 --- a/test/bigdecimal/test_bigdecimal.rb +++ b/test/bigdecimal/test_bigdecimal.rb @@ -1709,7 +1709,10 @@ def test_power_with_prec assert_equal(pow, pi.power(e, 20)) b = BigDecimal('1.034482758620689655172413793103448275862068965517241379310344827586206896551724') - assert_equal(BigDecimal('0.114523E1'), b.power(4, 5), '[Bug #8818] [ruby-core:56802]') + assert_equal(BigDecimal('0.11452E1'), b.power(4, 5), '[Bug #8818] [ruby-core:56802]') + + assert_equal(BigDecimal('0.537676775108E-7'), BigDecimal('0.1234').power(8, 12)) + assert_equal(BigDecimal('0.537676775108E9'), BigDecimal('12.34').power(8, 12)) end def test_limit