summaryrefslogtreecommitdiff
path: root/ext/bigdecimal/lib/bigdecimal
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2009-09-23 17:08:37 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2009-09-23 17:08:37 +0000
commit1ef3ac47384e27817f45864f65162fbc04a5d12f (patch)
treefab96e351bf6b1b24cd069b8782d6a641d17b40a /ext/bigdecimal/lib/bigdecimal
parent12fcef8829b9f514a517c606bd783eaffb401318 (diff)
* ext/bigdecimal/lib/bigdecimal/math.rb (atan): reduce loop with
the formula of the double corner. based on a patch from Masahiro Kanai (CanI) in [ruby-dev:39367]. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@25062 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'ext/bigdecimal/lib/bigdecimal')
-rw-r--r--ext/bigdecimal/lib/bigdecimal/math.rb6
1 files changed, 5 insertions, 1 deletions
diff --git a/ext/bigdecimal/lib/bigdecimal/math.rb b/ext/bigdecimal/lib/bigdecimal/math.rb
index dbc058b0b3b..d1e8dbe3266 100644
--- a/ext/bigdecimal/lib/bigdecimal/math.rb
+++ b/ext/bigdecimal/lib/bigdecimal/math.rb
@@ -125,11 +125,14 @@ module BigMath
if neg = x < 0
x = -x
end
- if x == 1
+ if x.round(prec) == 1
return pi / (neg ? -4 : 4)
elsif inv = x > 1
x = 1 / x
end
+ if dbl = x > 0.5
+ x = (-1 + sqrt(1 + x**2, prec))/x
+ end
n = prec + BigDecimal.double_fig
y = x
d = y
@@ -143,6 +146,7 @@ module BigMath
y += d
r += 2
end
+ y *= 2 if dbl
y = pi / 2 - y if inv
y = -y if neg
y