ruby-changes:13299
From: nobu <ko1@a...>
Date: Thu, 24 Sep 2009 02:08:58 +0900 (JST)
Subject: [ruby-changes:13299] Ruby:r25062 (trunk): * ext/bigdecimal/lib/bigdecimal/math.rb (atan): reduce loop with
nobu 2009-09-24 02:08:37 +0900 (Thu, 24 Sep 2009) New Revision: 25062 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=25062 Log: * 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]. Modified files: trunk/ChangeLog trunk/ext/bigdecimal/lib/bigdecimal/math.rb Index: ChangeLog =================================================================== --- ChangeLog (revision 25061) +++ ChangeLog (revision 25062) @@ -1,3 +1,9 @@ +Thu Sep 24 02:08:35 2009 Nobuyoshi Nakada <nobu@r...> + + * 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]. + Thu Sep 24 01:14:18 2009 Yutaka Kanemoto <kanemoto@r...> * dln.c (aix_loaderror): fixed typo. suppress warnings. Index: ext/bigdecimal/lib/bigdecimal/math.rb =================================================================== --- ext/bigdecimal/lib/bigdecimal/math.rb (revision 25061) +++ ext/bigdecimal/lib/bigdecimal/math.rb (revision 25062) @@ -125,11 +125,14 @@ if neg = x < 0 x = -x end - if x == 1 + 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 n = prec + BigDecimal.double_fig y = x d = y @@ -143,6 +146,7 @@ y += d r += 2 end + y *= 2 if dbl y = pi / 2 - y if inv y = -y if neg y -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/