From 04fe7852b49919014552e75eae1ebba6cbee5b47 Mon Sep 17 00:00:00 2001 From: naruse Date: Mon, 28 Jul 2008 17:42:32 +0000 Subject: * 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: http://svn.ruby-lang.org/repos/ruby/trunk@18252 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- math.c | 26 +++++++++++++++++++++++--- 1 file changed, 23 insertions(+), 3 deletions(-) (limited to 'math.c') diff --git a/math.c b/math.c index d3577f983..e23734a81 100644 --- a/math.c +++ b/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); } -- cgit