summaryrefslogtreecommitdiff
path: root/ext/bigdecimal
diff options
context:
space:
mode:
authorKenta Murata <mrkn@mrkn.jp>2021-01-22 13:50:26 +0900
committerKenta Murata <mrkn@mrkn.jp>2021-12-24 02:28:56 +0900
commit75f552e973ba565ef8615a0c5fd375d3a052b82e (patch)
tree6aadd84ddc6f903c1fc9566241d9eccaab387a58 /ext/bigdecimal
parent7b2cfce543b876744544c8b43abdee3c72cab910 (diff)
[ruby/bigdecimal] Fix the precision of the adjusted quotient
https://github.com/ruby/bigdecimal/commit/8dc8cd339d
Diffstat (limited to 'ext/bigdecimal')
-rw-r--r--ext/bigdecimal/bigdecimal.c6
1 files changed, 4 insertions, 2 deletions
diff --git a/ext/bigdecimal/bigdecimal.c b/ext/bigdecimal/bigdecimal.c
index 0558a17fd9..1cbdbd8832 100644
--- a/ext/bigdecimal/bigdecimal.c
+++ b/ext/bigdecimal/bigdecimal.c
@@ -1630,9 +1630,11 @@ BigDecimal_DoDivmod(VALUE self, VALUE r, Real **div, Real **mod)
VpAddSub(c, a, res, -1);
if (!VpIsZero(c) && (VpGetSign(a) * VpGetSign(b) < 0)) {
- /* remainder adjustment for negative case */
+ /* result adjustment for negative case */
+ res = VpReallocReal(res, d->MaxPrec);
+ res->MaxPrec = d->MaxPrec;
VpAddSub(res, d, VpOne(), -1);
- GUARD_OBJ(d, VpCreateRbObject(GetAddSubPrec(c, b)*(VpBaseFig() + 1), "0", true));
+ GUARD_OBJ(d, VpCreateRbObject(GetAddSubPrec(c, b) * 2*BASE_FIG, "0", true));
VpAddSub(d, c, b, 1);
*div = res;
*mod = d;