Skip to content

Commit 8459a3c

Browse files
authored
Increase BigMath.atan(x,prec) precision when |x|>0.5 (#320)
BigMath.atan(x, prec) is calculated with precision=prec+BigDecimal.double_fig when |x| <= 0.5. But this safe margin was not properly applied when |x| > 0.5.
1 parent 87c487e commit 8459a3c

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

lib/bigdecimal/math.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -149,9 +149,9 @@ def atan(x, prec)
149149
x = -x if neg = x < 0
150150
return pi.div(neg ? -2 : 2, prec) if x.infinite?
151151
return pi / (neg ? -4 : 4) if x.round(prec) == 1
152-
x = BigDecimal("1").div(x, prec) if inv = x > 1
153-
x = (-1 + sqrt(1 + x**2, prec))/x if dbl = x > 0.5
154-
n = prec + BigDecimal.double_fig
152+
n = prec + BigDecimal.double_fig
153+
x = BigDecimal("1").div(x, n) if inv = x > 1
154+
x = (-1 + sqrt(1 + x.mult(x, n), n)).div(x, n) if dbl = x > 0.5
155155
y = x
156156
d = y
157157
t = x

0 commit comments

Comments
 (0)