[#39222] [Bug #2036] AIX 5L 5.2にて、ruby-1.8.7-p174のビルド時にmake testをするとエラーになった。not ok float 7 -- ./sample/test.rb:1232 — 和弥 寺元 <redmine@...>

Bug #2036: AIX 5L 5.2にて、ruby-1.8.7-p174のビルド時にmake testをするとエラーになった。not ok float 7 -- ./sample/test.rb:1232

13 messages 2009/09/03

[#39249] [Bug #2060] DLをCからRubyに変換する事を勧めます — Aaron Patterson <redmine@...>

Bug #2060: DLをCからRubyに変換する事を勧めます

10 messages 2009/09/07

[#39282] [Bug #2067] bodyが大きいエラーページをopen-uriで取得するとfdがリークしている — takeru sasaki <redmine@...>

チケット #2067 が更新されました。 (by takeru sasaki)

15 messages 2009/09/10
[#39283] Re: [Bug #2067] bodyが大きいエラーページをopen-uriで取得するとfdがリークしている — Yukihiro Matsumoto <matz@...> 2009/09/10

まつもと ゆきひろです

[#39284] Re: [Bug #2067] bodyが大きいエラーページをopen-uriで取得するとfdがリークしている — Nobuyoshi Nakada <nobu@...> 2009/09/10

なかだです。

[#39297] Re: [Bug #2067] bodyが大きいエラーページをopen-uriで取得するとfdがリークしている — Yukihiro Matsumoto <matz@...> 2009/09/10

まつもと ゆきひろです

[#39298] Re: [Bug #2067] bodyが大きいエラーページをopen-uriで取得するとfdがリークしている — Tanaka Akira <akr@...> 2009/09/10

In article <E1MliJq-0000yc-4o@x61.netlab.jp>,

[#39302] Re: [Bug #2067] bodyが大きいエラーページをopen-uriで取得するとfdがリークしている — takeru sasaki <sasaki.takeru@...> 2009/09/10

言いだしっぺの佐々木です。

[#39307] Re: [Bug #2067] bodyが大きいエラーページをopen-uriで取得するとfdがリークしている — Yukihiro Matsumoto <matz@...> 2009/09/10

まつもと ゆきひろです

[#39345] [Bug #2111] Error:test_rm_f(TestFileUtils) — Kazuhiro NISHIYAMA <redmine@...>

Bug #2111: Error:test_rm_f(TestFileUtils)

11 messages 2009/09/17

[#39352] [ruby19] Thread 切替えが異常に遅い? — Hidetoshi NAGAI <nagai@...>

永井@知能.九工大です.

12 messages 2009/09/20

[#39367] Almost endless loop of BigMath::atan(x) when x.abs >= 1 — "Masahiro Kanai (CanI)" <cani.m.61st@...>

金井 仁弘と申します。

13 messages 2009/09/23
[#39980] Re: Almost endless loop of BigMath::atan(x) when x.abs >= 1 — TOYOFUKU Chikanobu <nobu_toyofuku@...> 2010/01/07

豊福です。遅い反応ですが。

[#39982] Re: Almost endless loop of BigMath::atan(x) when x.abs >= 1 — TOYOFUKU Chikanobu <nobu_toyofuku@...> 2010/01/07

豊福です。

[#39388] Re: [ruby-cvs:32331] Ruby:r25113 (trunk): String#inspect's encoding should be fixed. — "Martin J. Dürst" <duerst@...>

成瀬さん、こんにちは。

9 messages 2009/09/28

[ruby-dev:39367] Almost endless loop of BigMath::atan(x) when x.abs >= 1

From: "Masahiro Kanai (CanI)" <cani.m.61st@...>
Date: 2009-09-23 10:12:28 UTC
List: ruby-dev #39367
金井 仁弘と申します。

以下のようにすると、計算量の増大により、
ほぼ無限ループに入ります。

$ ./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)
'

これは、BigMath::atan(x)のx.absが1以上の時に、発生する問題のようです。
これにより、make test-allも途中で無限ループに入ります。

x.abs >= 1のとき、
atan(x) = pi/2 - atan(1/x)
を用いて、以下のように書き直しました。

また、上の式でも、xが1に非常に近い数値の場合は、
近似値を求めるために莫大な計算量が必要なため、
x.abs.round(prec) == 1のとき、
atan(x) = atan((-1+sqrt(1+x**2, prec))/x)
としました。

よろしくお願いいたします。

--- /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


--
Masahiro Kanai (CanI)
http://d.hatena.ne.jp/CanI/

In This Thread

Prev Next