diff options
author | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2009-09-23 12:25:20 +0000 |
---|---|---|
committer | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2009-09-23 12:25:20 +0000 |
commit | 8c3926aea0d782d28fc42ca8d391ce7ec9533e31 (patch) | |
tree | e74afa9dbc0a64adda06381b1c51e0412b6980d5 /ext/bigdecimal/lib | |
parent | 98b0d9f9224bdf4aaf9487ca9a0af216bc6f9cc1 (diff) | |
download | ruby-8c3926aea0d782d28fc42ca8d391ce7ec9533e31.tar.gz |
* 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.rb | 11 |
1 files changed, 11 insertions, 0 deletions
diff --git a/ext/bigdecimal/lib/bigdecimal/math.rb b/ext/bigdecimal/lib/bigdecimal/math.rb index 2771c77b6f..dbc058b0b3 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 |