Skip to content

Commit 1fa512f

Browse files
authored
Fix VpNumOfChars calculation for the longest case (#366)
1 parent d246504 commit 1fa512f

2 files changed

Lines changed: 4 additions & 1 deletion

File tree

ext/bigdecimal/bigdecimal.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5028,7 +5028,7 @@ VpNumOfChars(Real *vp,const char *pszFmt)
50285028
case 'E':
50295029
/* fall through */
50305030
default:
5031-
nc = BASE_FIG*(vp->Prec + 2)+6; /* 3: sign + exponent chars */
5031+
nc = BASE_FIG * vp->Prec + 25; /* "-0."(3) + digits_chars + "e-"(2) + 64bit_exponent_chars(19) + null(1) */
50325032
}
50335033
return nc;
50345034
}

test/bigdecimal/test_bigdecimal.rb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1503,6 +1503,9 @@ def test_inspect
15031503
assert_equal("0.123456789012e0", BigDecimal("0.123456789012").inspect)
15041504
assert_equal("0.123456789012e4", BigDecimal("1234.56789012").inspect)
15051505
assert_equal("0.123456789012e-4", BigDecimal("0.0000123456789012").inspect)
1506+
s = '-0.123456789e-1000000000000000008'
1507+
x = BigDecimal(s)
1508+
assert_equal(s, x.inspect) unless x.infinite?
15061509
end
15071510

15081511
def test_power

0 commit comments

Comments
 (0)