mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
Fix Math.cbrt(0.0) on glibc
This should return 0, but on glibc it returned NaN. Fixes [Bug #17804]
This commit is contained in:
parent
b7fec2e3e5
commit
406ae7fb03
Notes:
git
2021-05-09 06:45:55 +09:00
2 changed files with 2 additions and 1 deletions
2
math.c
2
math.c
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue