RFR: 8377223: Port fdlibm atanh to Java

Raffaello Giulietti rgiulietti at openjdk.org
Thu Feb 19 12:48:40 UTC 2026


On Wed, 18 Feb 2026 10:10:31 GMT, Anton Artemov <aartemov at openjdk.org> wrote:

> Hi, please consider the following changes:
> 
> This is a port of FDLIBM atanh method.

src/java.base/share/classes/java/lang/FdLibm.java line 3623:

> 3621:      *                   := 0.5 * log1p(2x + 2x * x/(1 - x)), if |x| < 0.5.
> 3622:      *
> 3623:      *

Not sure how useful this is in the context here.

src/java.base/share/classes/java/lang/FdLibm.java line 3638:

> 3636:             double t;
> 3637:             int hx,ix;
> 3638:             /*unsigned*/ int lx;

Suggestion:

            int lx;  // unsigned

src/java.base/share/classes/java/lang/FdLibm.java line 3642:

> 3640:             lx = __LO(x);                                        /* low word */
> 3641:             ix = hx & 0x7fff_ffff;
> 3642:             if ((ix | ((lx | (-lx)) >> 31)) > 0x3ff0_0000) {     /* |x| > 1 */

Hmm, since `lx` is unsigned this should really be
Suggestion:

            if ((ix | ((lx | (-lx)) >>> 31)) > 0x3ff0_0000) {     /* |x| > 1 */

The tests didn't reveal this bug, so I suggest adding some test cases for this, if feasible.

src/java.base/share/classes/java/lang/FdLibm.java line 3654:

> 3652:             if (ix < 0x3fe0_0000) {                              /* x < 0.5 */
> 3653:                 t = x + x;
> 3654:                 t = 0.5 * Log1p.compute(t + t*x/(one - x));

Suggestion:

                t = 0.5 * Log1p.compute(t + t * x / (one - x));

src/java.base/share/classes/java/lang/FdLibm.java line 3656:

> 3654:                 t = 0.5 * Log1p.compute(t + t*x/(one - x));
> 3655:             } else
> 3656:                 t = 0.5 * Log1p.compute((x + x)/(one - x));

Suggestion:

                t = 0.5 * Log1p.compute((x + x) / (one - x));

test/jdk/java/lang/StrictMath/FdlibmTranslit.java line 2880:

> 2878:             lx = __LO(x);       /* low word */
> 2879:             ix = hx&0x7fffffff;
> 2880:             if ((ix|((lx|(-lx))>>31))>0x3ff00000) /* |x|>1 */

As above,
Suggestion:

            if ((ix|((lx|(-lx))>>>31))>0x3ff00000) /* |x|>1 */

-------------

PR Review Comment: https://git.openjdk.org/jdk/pull/29782#discussion_r2827658243
PR Review Comment: https://git.openjdk.org/jdk/pull/29782#discussion_r2827658821
PR Review Comment: https://git.openjdk.org/jdk/pull/29782#discussion_r2827659802
PR Review Comment: https://git.openjdk.org/jdk/pull/29782#discussion_r2827660221
PR Review Comment: https://git.openjdk.org/jdk/pull/29782#discussion_r2827660365
PR Review Comment: https://git.openjdk.org/jdk/pull/29782#discussion_r2827665306


More information about the core-libs-dev mailing list