[前][次][番号順一覧][スレッド一覧]

ruby-changes:13294

From: nobu <ko1@a...>
Date: Wed, 23 Sep 2009 21:25:35 +0900 (JST)
Subject: [ruby-changes:13294] Ruby:r25057 (trunk): * ext/bigdecimal/lib/bigdecimal/math.rb (atan): refined.

nobu	2009-09-23 21:25:20 +0900 (Wed, 23 Sep 2009)

  New Revision: 25057

  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=25057

  Log:
    * ext/bigdecimal/lib/bigdecimal/math.rb (atan): refined.

  Modified files:
    trunk/ChangeLog
    trunk/ext/bigdecimal/lib/bigdecimal/math.rb

Index: ChangeLog
===================================================================
--- ChangeLog	(revision 25056)
+++ ChangeLog	(revision 25057)
@@ -1,3 +1,7 @@
+Wed Sep 23 21:25:20 2009  Nobuyoshi Nakada  <nobu@r...>
+
+	* ext/bigdecimal/lib/bigdecimal/math.rb (atan): refined.
+
 Wed Sep 23 17:08:30 2009  Nobuyoshi Nakada  <nobu@r...>
 
 	* parse.y (assign_in_cond): also should warn assignment to dvar in
Index: ext/bigdecimal/lib/bigdecimal/math.rb
===================================================================
--- ext/bigdecimal/lib/bigdecimal/math.rb	(revision 25056)
+++ ext/bigdecimal/lib/bigdecimal/math.rb	(revision 25057)
@@ -121,6 +121,15 @@
   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 @@
       y += d
       r += 2
     end
+    y = pi / 2 - y if inv
+    y = -y if neg
     y
   end
 

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]