Project

General

Profile

Actions

Bug #17804

closed

Math.cbrt(0.0) returns NaN

Added by chasonr (Ray Chason) over 3 years ago. Updated over 3 years ago.

Status:
Closed
Assignee:
-
Target version:
-
ruby -v:
ruby 3.0.1p64 (2021-04-05 revision 0fb782ee38) [x86_64-linux]
[ruby-core:103453]

Description

Math.cbrt(0.0) returns NaN. It should return 0.0.

From reading the implementation, I expect this bug to happen only if glibc is in use. The failing section reads:

#if defined GLIBC
if (isfinite(r)) {
r = (2.0 * r + (f / r / r)) / 3.0;
}
#endif

and this produces a NaN when f and r are both 0.

Updated by xtkoba (Tee KOBAYASHI) over 3 years ago

FWIW, that code was introduced by commit c995315153f7403636ec0d6119b7885668b32039.

Updated by jeremyevans0 (Jeremy Evans) over 3 years ago

I've submitted a pull request to fix this: https://github.com/ruby/ruby/pull/4425

Actions #3

Updated by jeremyevans (Jeremy Evans) over 3 years ago

  • Status changed from Open to Closed

Applied in changeset git|406ae7fb03640e11e200382ef61cd450b952b7aa.


Fix Math.cbrt(0.0) on glibc

This should return 0, but on glibc it returned NaN.

Fixes [Bug #17804]

Actions

Also available in: Atom PDF

Like0
Like0Like0Like0