summaryrefslogtreecommitdiff
path: root/ext/bigdecimal/lib
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2009-09-23 17:21:26 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2009-09-23 17:21:26 +0000
commit39ea1c8c7c68e2b09c5d2b8641f049f702ca9805 (patch)
tree4acfdf113505668bec6bf86d80e2933370e6b1ff /ext/bigdecimal/lib
parent1ef3ac47384e27817f45864f65162fbc04a5d12f (diff)
* ext/bigdecimal/lib/bigdecimal/math.rb (atan): atan(Infinity) is
PI/2. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@25063 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'ext/bigdecimal/lib')
-rw-r--r--ext/bigdecimal/lib/bigdecimal/math.rb20
1 files changed, 7 insertions, 13 deletions
diff --git a/ext/bigdecimal/lib/bigdecimal/math.rb b/ext/bigdecimal/lib/bigdecimal/math.rb
index d1e8dbe..eeffde4 100644
--- a/ext/bigdecimal/lib/bigdecimal/math.rb
+++ b/ext/bigdecimal/lib/bigdecimal/math.rb
@@ -117,22 +117,16 @@ module BigMath
# Computes the arctangent of x to the specified number of digits of precision.
#
- # If x is infinite or NaN, returns NaN.
+ # If x is NaN, returns NaN.
def atan(x, prec)
raise ArgumentError, "Zero or negative precision for atan" if prec <= 0
- return BigDecimal("NaN") if x.infinite? || x.nan?
+ return BigDecimal("NaN") if x.nan?
pi = PI(prec)
- if neg = x < 0
- x = -x
- end
- 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
+ x = -x if neg = x < 0
+ return pi.div(neg ? -2 : 2, prec) if x.infinite?
+ return pi / (neg ? -4 : 4) if x.round(prec) == 1
+ x = 1 / x if inv = x > 1
+ x = (-1 + sqrt(1 + x**2, prec))/x if dbl = x > 0.5
n = prec + BigDecimal.double_fig
y = x
d = y