summaryrefslogtreecommitdiff
path: root/ext/bigdecimal
diff options
context:
space:
mode:
authorKenta Murata <mrkn@mrkn.jp>2021-01-06 18:17:35 +0900
committerKenta Murata <mrkn@mrkn.jp>2021-01-07 10:20:40 +0900
commit82f6085b3edaa41be4121b218b48100d4bf78670 (patch)
treee0fcd2afa1c8129a8197017c4df27b741259c6ca /ext/bigdecimal
parent698d7947c300a5f5d63965fb2ccce59601f2563b (diff)
[ruby/bigdecimal] Fix trailing zero handling in rb_uint64_convert_to_BigDecimal
https://github.com/ruby/bigdecimal/commit/2056604d56
Diffstat (limited to 'ext/bigdecimal')
-rw-r--r--ext/bigdecimal/bigdecimal.c5
1 files changed, 4 insertions, 1 deletions
diff --git a/ext/bigdecimal/bigdecimal.c b/ext/bigdecimal/bigdecimal.c
index 63de77c..72c7b34 100644
--- a/ext/bigdecimal/bigdecimal.c
+++ b/ext/bigdecimal/bigdecimal.c
@@ -2736,12 +2736,15 @@ rb_uint64_convert_to_BigDecimal(uint64_t uval, RB_UNUSED_VAR(size_t digs), int r
vp->exponent = len;
VpSetSign(vp, 1);
- size_t i;
+ size_t i, ntz = 0;
for (i = 0; i < len; ++i) {
DECDIG r = uval % BASE;
vp->frac[len - i - 1] = r;
+ if (r == 0) ++ntz;
uval /= BASE;
}
+
+ vp->Prec -= ntz;
}
return BigDecimal_wrap_struct(obj, vp);