* 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.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@18252 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
naruse 2008-07-28 17:42:32 +00:00
Родитель 54da95b9e1
Коммит 78b5fdd5a8
3 изменённых файлов: 39 добавлений и 3 удалений

Просмотреть файл

@ -1,3 +1,15 @@
Tue Jul 29 02:39:46 2008 NARUSE, Yui <naruse@ruby-lang.org>
* 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@fsij.org>
* dir.c (struct dir_data): intenc field removed.

26
math.c
Просмотреть файл

@ -53,6 +53,24 @@ domain_check(double x, const char *msg)
}
}
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 @@ math_atanh(VALUE obj, VALUE x)
errno = 0;
d = atanh(RFLOAT_VALUE(x));
domain_check(d, "atanh");
infinity_check(x, d, "atanh");
return DOUBLE2NUM(d);
}
@ -339,6 +358,7 @@ math_log(int argc, VALUE *argv)
d /= log(RFLOAT_VALUE(base));
}
domain_check(d, "log");
infinity_check(x, d, "log");
return DOUBLE2NUM(d);
}
@ -369,9 +389,8 @@ math_log2(VALUE obj, VALUE x)
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 @@ math_log10(VALUE obj, VALUE x)
errno = 0;
d = log10(RFLOAT_VALUE(x));
domain_check(d, "log10");
infinity_check(x, d, "log10");
return DOUBLE2NUM(d);
}

Просмотреть файл

@ -110,6 +110,7 @@ class TestMath < Test::Unit::TestCase
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 @@ class TestMath < Test::Unit::TestCase
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 @@ class TestMath < Test::Unit::TestCase
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 @@ class TestMath < Test::Unit::TestCase
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