Skip to content

Commit a6a11e7

Browse files
committed
Use decimal_shift in log and exp calculation
1 parent 34f5524 commit a6a11e7

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

lib/bigdecimal.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ def self.log(x, prec)
174174
if x > 10 || x < 0.1
175175
log10 = log(BigDecimal(10), prec)
176176
exponent = x.exponent
177-
x = x * BigDecimal("1e#{-x.exponent}")
177+
x = x._decimal_shift(-exponent)
178178
if x > 3
179179
x /= 10
180180
exponent += 1
@@ -240,7 +240,7 @@ def self.exp(x, prec)
240240
# exp(x * 10**cnt) = exp(x)**(10**cnt)
241241
cnt = x > 1 ? x.exponent : 0
242242
prec2 = prec + BigDecimal.double_fig + cnt
243-
x *= BigDecimal("1e-#{cnt}")
243+
x = x._decimal_shift(-cnt)
244244
xn = BigDecimal(1)
245245
y = BigDecimal(1)
246246

0 commit comments

Comments
 (0)