summaryrefslogtreecommitdiff
path: root/math.c
diff options
context:
space:
mode:
authornaruse <naruse@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2008-07-28 17:42:32 +0000
committernaruse <naruse@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2008-07-28 17:42:32 +0000
commit78b5fdd5a88b001c7576f23df49ed6cdd030229e (patch)
tree9d098daf1252783b3195a9e79ffd3600eaa56c8b /math.c
parent54da95b9e1f25d02d1580578fdf21e7cf8001e31 (diff)
* 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
Diffstat (limited to 'math.c')
-rw-r--r--math.c26
1 files changed, 23 insertions, 3 deletions
diff --git a/math.c b/math.c
index d3577f9..e23734a 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);
}