math.c: Fix Math.log against huge bignum [Bug #19878]

This commit is contained in:
Yusuke Endoh 2023-09-13 18:56:24 +09:00
parent 4655d2108e
commit 411572661a
Notes: git 2023-09-13 12:40:25 +00:00
2 changed files with 3 additions and 2 deletions

4
math.c
View File

@ -561,14 +561,14 @@ rb_math_log(int argc, const VALUE *argv)
return DBL2NUM(-0.0);
}
d = log_intermediate(d) / log_intermediate(b);
numbits -= numbits_2;
d += (numbits - numbits_2) * M_LN2 / log(b);
}
else {
/* check for pole error */
if (d == 0.0) return DBL2NUM(-HUGE_VAL);
d = log(d);
d += numbits * M_LN2;
}
d += numbits * M_LN2;
return DBL2NUM(d);
}

View File

@ -168,6 +168,7 @@ class TestMath < Test::Unit::TestCase
assert_nothing_raised { assert_nan(Math.log(1.0, Float::NAN)) }
assert_nothing_raised { assert_infinity(-Math.log(0)) }
assert_nothing_raised { assert_infinity(-Math.log(0, 2)) }
check(307.95368556425274, Math.log(2**1023, 10))
end
def test_log2