summaryrefslogtreecommitdiff
path: root/ext/bigdecimal/lib
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2009-09-23 12:25:20 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2009-09-23 12:25:20 +0000
commit8c3926aea0d782d28fc42ca8d391ce7ec9533e31 (patch)
treee74afa9dbc0a64adda06381b1c51e0412b6980d5 /ext/bigdecimal/lib
parent98b0d9f9224bdf4aaf9487ca9a0af216bc6f9cc1 (diff)
* ext/bigdecimal/lib/bigdecimal/math.rb (atan): refined.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@25057 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'ext/bigdecimal/lib')
-rw-r--r--ext/bigdecimal/lib/bigdecimal/math.rb11
1 files changed, 11 insertions, 0 deletions
diff --git a/ext/bigdecimal/lib/bigdecimal/math.rb b/ext/bigdecimal/lib/bigdecimal/math.rb
index 2771c77..dbc058b 100644
--- a/ext/bigdecimal/lib/bigdecimal/math.rb
+++ b/ext/bigdecimal/lib/bigdecimal/math.rb
@@ -121,6 +121,15 @@ module BigMath
def atan(x, prec)
raise ArgumentError, "Zero or negative precision for atan" if prec <= 0
return BigDecimal("NaN") if x.infinite? || x.nan?
+ pi = PI(prec)
+ if neg = x < 0
+ x = -x
+ end
+ if x == 1
+ return pi / (neg ? -4 : 4)
+ elsif inv = x > 1
+ x = 1 / x
+ end
n = prec + BigDecimal.double_fig
y = x
d = y
@@ -134,6 +143,8 @@ module BigMath
y += d
r += 2
end
+ y = pi / 2 - y if inv
+ y = -y if neg
y
end