ruby-changes:6736
From: naruse <ko1@a...>
Date: Tue, 29 Jul 2008 02:46:47 +0900 (JST)
Subject: [ruby-changes:6736] Ruby:r18252 (trunk): * math.c (math_atanh): raise EDOM on FreeBSD when atanh(1).
naruse 2008-07-29 02:42:32 +0900 (Tue, 29 Jul 2008) New Revision: 18252 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=18252 Log: * math.c (math_atanh): raise EDOM on FreeBSD when atanh(1). * math.c (math_log): ditto. * math.c (math_log2): ditto. * math.c (math_log10): ditto. * test/ruby/test_math.rb: test for above. Modified files: trunk/ChangeLog trunk/math.c trunk/test/ruby/test_math.rb Index: math.c =================================================================== --- math.c (revision 18251) +++ math.c (revision 18252) @@ -53,6 +53,24 @@ } } +static void +infinity_check(VALUE arg, double res, const char *msg) +{ + while(1) { + if (errno) { + rb_sys_fail(msg); + } + if (isinf(res) && !isinf(RFLOAT_VALUE(arg))) { +#if defined(EDOM) + errno = EDOM; +#elif defined(ERANGE) + errno = ERANGE; +#endif + continue; + } + break; + } +} /* * call-seq: @@ -288,6 +306,7 @@ errno = 0; d = atanh(RFLOAT_VALUE(x)); domain_check(d, "atanh"); + infinity_check(x, d, "atanh"); return DOUBLE2NUM(d); } @@ -339,6 +358,7 @@ d /= log(RFLOAT_VALUE(base)); } domain_check(d, "log"); + infinity_check(x, d, "log"); return DOUBLE2NUM(d); } @@ -369,9 +389,8 @@ Need_Float(x); errno = 0; d = log2(RFLOAT_VALUE(x)); - if (errno) { - rb_sys_fail("log2"); - } + domain_check(d, "log2"); + infinity_check(x, d, "log2"); return DOUBLE2NUM(d); } @@ -391,6 +410,7 @@ errno = 0; d = log10(RFLOAT_VALUE(x)); domain_check(d, "log10"); + infinity_check(x, d, "log10"); return DOUBLE2NUM(d); } Index: ChangeLog =================================================================== --- ChangeLog (revision 18251) +++ ChangeLog (revision 18252) @@ -1,3 +1,15 @@ +Tue Jul 29 02:39:46 2008 NARUSE, Yui <naruse@r...> + + * math.c (math_atanh): raise EDOM on FreeBSD when atanh(1). + + * math.c (math_log): ditto. + + * math.c (math_log2): ditto. + + * math.c (math_log10): ditto. + + * test/ruby/test_math.rb: test for above. + Tue Jul 29 01:41:15 2008 Tanaka Akira <akr@f...> * dir.c (struct dir_data): intenc field removed. Index: test/ruby/test_math.rb =================================================================== --- test/ruby/test_math.rb (revision 18251) +++ test/ruby/test_math.rb (revision 18252) @@ -110,6 +110,7 @@ check(0, Math.log(1, 10)) check(1, Math.log(10, 10)) check(2, Math.log(100, 10)) + assert_equal(1.0/0, Math.log(1.0/0)) assert_raise(Errno::EDOM, Errno::ERANGE) { Math.log(0) } assert_raise(Errno::EDOM, Errno::ERANGE) { Math.log(-1) } end @@ -118,6 +119,7 @@ check(0, Math.log2(1)) check(1, Math.log2(2)) check(2, Math.log2(4)) + assert_equal(1.0/0, Math.log2(1.0/0)) assert_raise(Errno::EDOM, Errno::ERANGE) { Math.log2(0) } assert_raise(Errno::EDOM, Errno::ERANGE) { Math.log2(-1) } end @@ -126,6 +128,7 @@ check(0, Math.log10(1)) check(1, Math.log10(10)) check(2, Math.log10(100)) + assert_equal(1.0/0, Math.log10(1.0/0)) assert_raise(Errno::EDOM, Errno::ERANGE) { Math.log10(0) } assert_raise(Errno::EDOM, Errno::ERANGE) { Math.log10(-1) } end @@ -134,6 +137,7 @@ check(0, Math.sqrt(0)) check(1, Math.sqrt(1)) check(2, Math.sqrt(4)) + assert_equal(1.0/0, Math.sqrt(1.0/0)) assert_raise(Errno::EDOM, Errno::ERANGE) { Math.sqrt(-1) } end -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/