e$B6b0fe(B e$B?N90$H?=$7$^$9!#e(B
e$B0J2<$N$h$&$K$9$k$H!"7W;;NL$NA}Bg$K$h$j!"e(B
e$B$[$\L58B%k!<%W$KF~$j$^$9!#e(B
$ ./ruby -v
ruby 1.9.2dev (2009-09-23 trunk 25052) [i686-linux]
$ ./ruby -e ’
require “bigdecimal”
require “bigdecimal/math”
N = 20
p BigMath::atan(BigDecimal(“1.0”), N)
’
e$B$3$l$O!"e(BBigMath::atan(x)e$B$Ne(Bx.abse$B$,e(B1e$B0J>e$N;~$K!"H/@8$9$kLdBj$N$h$&$G$9!#e(B
e$B$3$l$K$h$j!"e(Bmake test-alle$B$bESCf$GL58B%k!<%W$KF~$j$^$9!#e(B
x.abs >= 1e$B$N$H$-!"e(B
atan(x) = pi/2 - atan(1/x)
e$B$rMQ$$$F!"0J2<$N$h$&$K=q$-D>$7$^$7$?!#e(B
e$B$^$?!">e$N<0$G$b!"e(Bxe$B$,e(B1e$B$KHs>o$K6a$$?tCM$N>l9g$O!"e(B
e$B6a;wCM$r5a$a$k$?$a$KG|Bg$J7W;;NL$,I,MW$J$?$a!"e(B
x.abs.round(prec) == 1e$B$N$H$-!"e(B
atan(x) = atan((-1+sqrt(1+x**2, prec))/x)
e$B$H$7$^$7$?!#e(B
e$B$h$m$7$/$*4j$$$$$?$7$^$9!#e(B
— /ext/bigdecimal/lib/bigdecimal/math.rb (revision 25052)
+++ /ext/bigdecimal/lib/bigdecimal/math.rb (working copy)
@@ -122,11 +122,18 @@
raise ArgumentError, “Zero or negative precision for atan” if prec
<= 0
return BigDecimal(“NaN”) if x.infinite? || x.nan?
n = prec + BigDecimal.double_fig
- y = x
- if 1 > x.abs
-
x1 = x
- elsif 1 == x.abs.round(prec)
-
x1 = (-1 + sqrt(1 + x**2, prec))/x
- else
-
x1 = 1 / x
- end
- y = x1
d = y
- t = x
- t = x1
r = BigDecimal(“3”)
- x2 = x.mult(x,n)
- x2 = x1.mult(x1,n)
while d.nonzero? && ((m = n - (y.exponent - d.exponent).abs) > 0)
m = BigDecimal.double_fig if m < BigDecimal.double_fig
t = -t.mult(x2,n)
@@ -134,7 +141,13 @@
y += d
r += 2
end
- y
- if 1 > x.abs
-
y
- elsif 1 == x.abs.round(prec)
-
y*2
- else
-
PI(prec)*y.sign/4 - y
- end
end
Computes the value of e (the base of natural logarithms) raised to
the