aboutsummaryrefslogtreecommitdiffstats
path: root/numeric.c
diff options
context:
space:
mode:
Diffstat (limited to 'numeric.c')
-rw-r--r--numeric.c10
1 files changed, 9 insertions, 1 deletions
diff --git a/numeric.c b/numeric.c
index 1e5f779ae9..c6c0cddf00 100644
--- a/numeric.c
+++ b/numeric.c
@@ -2905,7 +2905,15 @@ rb_fix2str(VALUE x, int base)
return rb_usascii_str_new2("0");
}
if (val < 0) {
- val = -val;
+ if (val == LONG_MIN) {
+ int last = ((int)((val = LONG_MAX) % base) + 1);
+ *--b = ruby_digitmap[last % base];
+ val /= base;
+ val += last == base; /* carry */
+ }
+ else {
+ val = -val;
+ }
neg = 1;
}
do {