ruby-changes:13300
From: nobu <ko1@a...>
Date: Thu, 24 Sep 2009 02:21:41 +0900 (JST)
Subject: [ruby-changes:13300] Ruby:r25063 (trunk): * ext/bigdecimal/lib/bigdecimal/math.rb (atan): atan(Infinity) is
nobu 2009-09-24 02:21:26 +0900 (Thu, 24 Sep 2009) New Revision: 25063 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=25063 Log: * ext/bigdecimal/lib/bigdecimal/math.rb (atan): atan(Infinity) is PI/2. Modified files: trunk/ChangeLog trunk/ext/bigdecimal/lib/bigdecimal/math.rb trunk/test/bigdecimal/test_bigmath.rb Index: ChangeLog =================================================================== --- ChangeLog (revision 25062) +++ ChangeLog (revision 25063) @@ -1,5 +1,8 @@ -Thu Sep 24 02:08:35 2009 Nobuyoshi Nakada <nobu@r...> +Thu Sep 24 02:21:23 2009 Nobuyoshi Nakada <nobu@r...> + * ext/bigdecimal/lib/bigdecimal/math.rb (atan): atan(Infinity) is + PI/2. + * ext/bigdecimal/lib/bigdecimal/math.rb (atan): reduce loop with the formula of the double corner. based on a patch from Masahiro Kanai (CanI) in [ruby-dev:39367]. Index: ext/bigdecimal/lib/bigdecimal/math.rb =================================================================== --- ext/bigdecimal/lib/bigdecimal/math.rb (revision 25062) +++ ext/bigdecimal/lib/bigdecimal/math.rb (revision 25063) @@ -117,22 +117,16 @@ # 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 Index: test/bigdecimal/test_bigmath.rb =================================================================== --- test/bigdecimal/test_bigmath.rb (revision 25062) +++ test/bigdecimal/test_bigmath.rb (revision 25063) @@ -21,7 +21,7 @@ assert_equal(0.0, sqrt(BigDecimal("-0"), N)) assert_raise(FloatDomainError) {sqrt(BigDecimal("-1.0"), N)} assert_raise(FloatDomainError) {sqrt(NAN, N)} - assert_equal(PINF, sqrt(PINF, N)) + assert_raise(FloatDomainError) {sqrt(PINF, N)} end def test_sin @@ -56,6 +56,7 @@ assert_equal(0.0, atan(BigDecimal("0.0"), N)) assert_in_delta(Math::PI/4, atan(BigDecimal("1.0"), N)) assert_in_delta(Math::PI/6, atan(sqrt(BigDecimal("3.0"), N) / 3, N)) + assert_in_delta(Math::PI/2, atan(PINF, N)) end def test_exp -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/