* 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
This commit is contained in:
parent
98b0d9f922
commit
8c3926aea0
@ -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>
|
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
|
* parse.y (assign_in_cond): also should warn assignment to dvar in
|
||||||
|
@ -121,6 +121,15 @@ module BigMath
|
|||||||
def atan(x, prec)
|
def atan(x, prec)
|
||||||
raise ArgumentError, "Zero or negative precision for atan" if prec <= 0
|
raise ArgumentError, "Zero or negative precision for atan" if prec <= 0
|
||||||
return BigDecimal("NaN") if x.infinite? || x.nan?
|
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
|
n = prec + BigDecimal.double_fig
|
||||||
y = x
|
y = x
|
||||||
d = y
|
d = y
|
||||||
@ -134,6 +143,8 @@ module BigMath
|
|||||||
y += d
|
y += d
|
||||||
r += 2
|
r += 2
|
||||||
end
|
end
|
||||||
|
y = pi / 2 - y if inv
|
||||||
|
y = -y if neg
|
||||||
y
|
y
|
||||||
end
|
end
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user