Skip to content

Commit 07044c7

Browse files
committed
Use decimal_shift in log and exp calculation
1 parent a837536 commit 07044c7

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
@@ -203,7 +203,7 @@ def self.log(x, prec)
203203
if x > 10 || x < 0.1
204204
log10 = log(BigDecimal(10), prec)
205205
exponent = x.exponent
206-
x = x * BigDecimal("1e#{-x.exponent}")
206+
x = x._decimal_shift(-exponent)
207207
if x < 0.3
208208
x *= 10
209209
exponent -= 1
@@ -269,7 +269,7 @@ def self.exp(x, prec)
269269
# exp(x * 10**cnt) = exp(x)**(10**cnt)
270270
cnt = x > 1 ? x.exponent : 0
271271
prec2 = prec + BigDecimal.double_fig + cnt
272-
x *= BigDecimal("1e-#{cnt}")
272+
x = x._decimal_shift(-cnt)
273273
xn = BigDecimal(1)
274274
y = BigDecimal(1)
275275

0 commit comments

Comments
 (0)