Skip to content

Bigdecimal division fix for bug#9316 #11

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jan 14, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
Tue Jan 14 02:20:00 2014 Kenta Murata <mrkn@mrkn.jp>

* ext/bigdecimal/bigdecimal.c (BigDecimal_divide): Add an additional
digit for the quotient to be compatible with bigdecimal 1.2.1 and
the former. [ruby-core:59365] [#9316] [#9305]

* test/bigdecimal/test_bigdecimal.rb: tests for the above change.

* ext/bigdecimal/bigdecimal.gemspec: bigdecimal version 1.2.4.

Thu Dec 26 03:28:11 2013 Koichi Sasada <ko1@atdot.net>

* vm_insnhelper.c (argument_error): insert dummy frame to make
Expand Down
8 changes: 4 additions & 4 deletions ext/bigdecimal/bigdecimal.c
Original file line number Diff line number Diff line change
Expand Up @@ -1221,9 +1221,10 @@ BigDecimal_divide(Real **c, Real **res, Real **div, VALUE self, VALUE r)

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

mx = a->Prec + vabs(a->exponent);
if (mx<b->Prec + vabs(b->exponent)) mx = b->Prec + vabs(b->exponent);
if (mx<3) mx = 3;
mx = (mx + 1) * VpBaseFig();
GUARD_OBJ(c, VpCreateRbObject(mx, "0"));
GUARD_OBJ(res, VpCreateRbObject((mx+1) * 2 +(VpBaseFig() + 1), "#0"));
Expand Down
2 changes: 1 addition & 1 deletion ext/bigdecimal/bigdecimal.gemspec
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# -*- ruby -*-
_VERSION = "1.2.3"
_VERSION = "1.2.4"
date = %w$Date:: $[1]

Gem::Specification.new do |s|
Expand Down
4 changes: 4 additions & 0 deletions test/bigdecimal/test_bigdecimal.rb
Original file line number Diff line number Diff line change
Expand Up @@ -701,6 +701,10 @@ def test_div
assert_equal(BigDecimal::SIGN_NEGATIVE_ZERO, (BigDecimal.new("-0") / 1).sign)
assert_equal(2, BigDecimal.new("2") / 1)
assert_equal(-2, BigDecimal.new("2") / -1)

assert_equal(BigDecimal('1486.868686869'), BigDecimal('1472.0') / BigDecimal('0.99'), '[ruby-core:59365] [#9316]')

assert_equal(4.124045235, BigDecimal('0.9932') / (700 * BigDecimal('0.344045') / BigDecimal('1000.0')), '[#9305]')
end

def test_div_with_float
Expand Down