diff options
-rw-r--r-- | math.c | 2 | ||||
-rw-r--r-- | test/ruby/test_math.rb | 1 |
2 files changed, 2 insertions, 1 deletions
@@ -703,7 +703,7 @@ math_cbrt(VALUE unused_obj, VALUE x) double f = Get_Double(x); double r = cbrt(f); #if defined __GLIBC__ - if (isfinite(r)) { + if (isfinite(r) && !(f == 0.0 && r == 0.0)) { r = (2.0 * r + (f / r / r)) / 3.0; } #endif diff --git a/test/ruby/test_math.rb b/test/ruby/test_math.rb index 5cc12bcfeb..6c2b25787f 100644 --- a/test/ruby/test_math.rb +++ b/test/ruby/test_math.rb @@ -201,6 +201,7 @@ class TestMath < Test::Unit::TestCase check(-2, Math.cbrt(-8)) check(3, Math.cbrt(27)) check(-0.1, Math.cbrt(-0.001)) + check(0.0, Math.cbrt(0.0)) assert_nothing_raised { assert_infinity(Math.cbrt(1.0/0)) } assert_operator(Math.cbrt(1.0 - Float::EPSILON), :<=, 1.0) end |