summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ChangeLog4
-rw-r--r--ext/bigdecimal/lib/bigdecimal/math.rb11
2 files changed, 15 insertions, 0 deletions
diff --git a/ChangeLog b/ChangeLog
index 94ffa631eec..a0ec66fc21a 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,7 @@
+Wed Sep 23 21:25:20 2009 Nobuyoshi Nakada <nobu@ruby-lang.org>
+
+ * ext/bigdecimal/lib/bigdecimal/math.rb (atan): refined.
+
Wed Sep 23 17:08:30 2009 Nobuyoshi Nakada <nobu@ruby-lang.org>
* parse.y (assign_in_cond): also should warn assignment to dvar in
diff --git a/ext/bigdecimal/lib/bigdecimal/math.rb b/ext/bigdecimal/lib/bigdecimal/math.rb
index 2771c77b6fe..dbc058b0b3b 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