Skip to content

Commit 3f2d8f3

Browse files
committed
Merge pull request #11 from zzak/bigdecimal_division_bug_9316
Bigdecimal division fix for bug#9316
2 parents a8d112b + eaa20bd commit 3f2d8f3

File tree

4 files changed

+19
-5
lines changed

4 files changed

+19
-5
lines changed

ChangeLog

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,13 @@
1+
Tue Jan 14 02:20:00 2014 Kenta Murata <[email protected]>
2+
3+
* ext/bigdecimal/bigdecimal.c (BigDecimal_divide): Add an additional
4+
digit for the quotient to be compatible with bigdecimal 1.2.1 and
5+
the former. [ruby-core:59365] [#9316] [#9305]
6+
7+
* test/bigdecimal/test_bigdecimal.rb: tests for the above change.
8+
9+
* ext/bigdecimal/bigdecimal.gemspec: bigdecimal version 1.2.4.
10+
111
Thu Dec 26 03:28:11 2013 Koichi Sasada <[email protected]>
212

313
* vm_insnhelper.c (argument_error): insert dummy frame to make

ext/bigdecimal/bigdecimal.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1221,9 +1221,10 @@ BigDecimal_divide(Real **c, Real **res, Real **div, VALUE self, VALUE r)
12211221

12221222
*div = b;
12231223
mx = a->Prec + vabs(a->exponent);
1224-
if (mx<b->Prec + vabs(b->exponent)) mx = b->Prec + vabs(b->exponent);
1225-
if (mx<3) mx = 3;
1226-
mx =(mx + 1) * VpBaseFig();
1224+
if (mx < b->Prec + vabs(b->exponent)) mx = b->Prec + vabs(b->exponent);
1225+
mx++; /* NOTE: An additional digit is needed for the compatibility to
1226+
the version 1.2.1 and the former. */
1227+
mx = (mx + 1) * VpBaseFig();
12271228
GUARD_OBJ((*c), VpCreateRbObject(mx, "#0"));
12281229
GUARD_OBJ((*res), VpCreateRbObject((mx+1) * 2 +(VpBaseFig() + 1), "#0"));
12291230
VpDivd(*c, *res, a, b);
@@ -1324,7 +1325,6 @@ BigDecimal_DoDivmod(VALUE self, VALUE r, Real **div, Real **mod)
13241325

13251326
mx = a->Prec + vabs(a->exponent);
13261327
if (mx<b->Prec + vabs(b->exponent)) mx = b->Prec + vabs(b->exponent);
1327-
if (mx<3) mx = 3;
13281328
mx = (mx + 1) * VpBaseFig();
13291329
GUARD_OBJ(c, VpCreateRbObject(mx, "0"));
13301330
GUARD_OBJ(res, VpCreateRbObject((mx+1) * 2 +(VpBaseFig() + 1), "#0"));

ext/bigdecimal/bigdecimal.gemspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# -*- ruby -*-
2-
_VERSION = "1.2.3"
2+
_VERSION = "1.2.4"
33
date = %w$Date:: $[1]
44

55
Gem::Specification.new do |s|

test/bigdecimal/test_bigdecimal.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -701,6 +701,10 @@ def test_div
701701
assert_equal(BigDecimal::SIGN_NEGATIVE_ZERO, (BigDecimal.new("-0") / 1).sign)
702702
assert_equal(2, BigDecimal.new("2") / 1)
703703
assert_equal(-2, BigDecimal.new("2") / -1)
704+
705+
assert_equal(BigDecimal('1486.868686869'), BigDecimal('1472.0') / BigDecimal('0.99'), '[ruby-core:59365] [#9316]')
706+
707+
assert_equal(4.124045235, BigDecimal('0.9932') / (700 * BigDecimal('0.344045') / BigDecimal('1000.0')), '[#9305]')
704708
end
705709

706710
def test_div_with_float

0 commit comments

Comments
 (0)