On Wed, 11 Feb 2026 09:26:25 GMT, Anton Artemov <[email protected]> wrote:
>> Hi, please consider the following changes:
>>
>> This is a port of FDLIBM acosh method.
>>
>> Original C vs transliteration port:
>>
>>
>> $ diff -w fdlib_acosh.c.txt Acosh.translit.java
>> 1c1,3
>> < /* __ieee754_acosh(x)
>> ---
>>> /**
>>> * Return the Inverse Hyperbolic Cosine of x
>>> *
>> 7,8c9,10
>> < * acosh(x) := log(2x-1/(sqrt(x*x-1)+x)) if x>2; else
>> < * acosh(x) := log1p(t+sqrt(2.0*t+t*t)); where t=x-1.
>> ---
>>> * := log(2x-1/(sqrt(x*x-1)+x)) if x>2; else
>>> * := log1p(t+sqrt(2.0*t+t*t)); where t=x-1.
>> 14,31c16,19
>> <
>> < #include "fdlibm.h"
>> <
>> < #ifdef __STDC__
>> < static const double
>> < #else
>> < static double
>> < #endif
>> < one = 1.0,
>> < ln2 = 6.93147180559945286227e-01; /* 0x3FE62E42, 0xFEFA39EF */
>> <
>> < #ifdef __STDC__
>> < double __ieee754_acosh(double x)
>> < #else
>> < double __ieee754_acosh(x)
>> < double x;
>> < #endif
>> < {
>> ---
>>> private static final class Acosh {
>>> private static final double one = 1.0;
>>> private static final double ln2 = 6.93147180559945286227e-01;
>>> static double compute(double x) {
>> 41c29
>> < return __ieee754_log(x)+ln2; /* acosh(huge)=log(2x) */
>> ---
>>> return log(x)+ln2; /* acosh(huge)=log(2x) */
>> 46c34
>> < return __ieee754_log(2.0*x-one/(x+sqrt(t-one)));
>> ---
>>> return log(2.0*x-one/(x+sqrt(t-one)));
>> 49a38
>>> }
>>
>>
>>
>> Transliteration vs more idiomatic port:
>>
>> $ diff -w Acosh.translit.java Acosh.fdlibm.java
>> 5,7c5,9
>> < * Based on
>> < * acosh(x) = log [ x + sqrt(x*x-1) ]
>> < * we have
>> ---
>>> *
>>> *
>>> * acosh(x) is defined so that acosh(cosh(alpha)) = alpha, -INF <
>>> alpha < < INF
>>> * and cosh(acosh(x)) = x, 1 <= x < INF.
>>> * It can be written as acosh(x) = ln(x + sqrt(x^2 - 1)), 1 <= x <
>>> INF.
>> 11a14,15
>>> *
>>> *
>> 16,17c20
>> < private static final class Acosh {
>> < private static final double one = 1.0;
>> ---
>>> static final class Acosh {
>> 18a22
>>>
>> 23c27
>> < if(hx<0x3ff00000) { /* x < 1 */
>> ---
>>> if(hx < 0x3ff00000) { // x < 1 */
>> 25,26c29,30
>> < } else if(hx >=0x41b00000) { /* x > 2**28 */
>> < if(hx >=0x7ff00000) { /* x is inf of NaN */
>> ---
>>> } else if (hx >= 0x41b00000) { // x > 2**28
>>> if(hx >= 0x7ff00000) { ...
>
> Anton Artemov has updated the pull request with a new target base due to a
> merge or a rebase. The pull request now contains 11 commits:
>
> - 8376665: Resolved merge conflicts.
> - 8376665: Fixed definition of inverse cosh.
> - 8376665: Fixed range, added special test case.
> - 8376665: Fixed whitespaces.
> - 8376665: Fixed whitespaces.
> - 8376665: Ported fdlibm acosh function. Added tests.
> - Merge remote-tracking branch 'origin/master' into
> JDK-8375285-port-fdlibm-asinh-to-java
> - 8375285: Added versions.
> - 8375285: Addressed the reviewer's comments, fixed year in the copyright
> notice.
> - 8375285: Addressed the reviewer's comments.
> - ... and 1 more: https://git.openjdk.org/jdk/compare/56afb460...32e51c37
Original C vs transliteration port:
$ diff -w fdlib_acosh.c.txt Acosh.translit.java
1c1,3
< /* __ieee754_acosh(x)
---
> /**
> * Return the Inverse Hyperbolic Cosine of x
> *
7,8c9,10
< * acosh(x) := log(2x-1/(sqrt(x*x-1)+x)) if x>2; else
< * acosh(x) := log1p(t+sqrt(2.0*t+t*t)); where t=x-1.
---
> * := log(2x-1/(sqrt(x*x-1)+x)) if x>2; else
> * := log1p(t+sqrt(2.0*t+t*t)); where t=x-1.
14,31c16,19
<
< #include "fdlibm.h"
<
< #ifdef __STDC__
< static const double
< #else
< static double
< #endif
< one = 1.0,
< ln2 = 6.93147180559945286227e-01; /* 0x3FE62E42, 0xFEFA39EF */
<
< #ifdef __STDC__
< double __ieee754_acosh(double x)
< #else
< double __ieee754_acosh(x)
< double x;
< #endif
< {
---
> private static final class Acosh {
> private static final double one = 1.0;
> private static final double ln2 = 6.93147180559945286227e-01;
> static double compute(double x) {
41c29
< return __ieee754_log(x)+ln2; /* acosh(huge)=log(2x) */
---
> return log(x)+ln2; /* acosh(huge)=log(2x) */
46c34
< return __ieee754_log(2.0*x-one/(x+sqrt(t-one)));
---
> return log(2.0*x-one/(x+sqrt(t-one)));
49a38
> }
Transliteration vs more idiomatic port:
$ diff -w Acosh.translit.java Acosh.fdlibm.java
5,7c5,9
< * Based on
< * acosh(x) = log [ x + sqrt(x*x-1) ]
< * we have
---
> *
> *
> * acosh(x) is defined so that acosh(cosh(alpha)) = alpha, -INF < alpha
> < < INF
> * and cosh(acosh(x)) = x, 1 <= x < INF.
> * It can be written as acosh(x) = ln(x + sqrt(x^2 - 1)), 1 <= x < INF.
11a14,15
> *
> *
16,17c20
< private static final class Acosh {
< private static final double one = 1.0;
---
> static final class Acosh {
18a22
>
23c27
< if(hx<0x3ff00000) { /* x < 1 */
---
> if(hx < 0x3ff00000) { // x < 1 */
25,26c29,30
< } else if(hx >=0x41b00000) { /* x > 2**28 */
< if(hx >=0x7ff00000) { /* x is inf of NaN */
---
> } else if (hx >= 0x41b00000) { // x > 2**28
> if(hx >= 0x7ff00000) { // x is inf
> of NaN
28,29c32,34
< } else
< return log(x)+ln2; /* acosh(huge)=log(2x) */
---
> } else {
> return Log.compute(x) + ln2; //
> acosh(huge) = log(2x)
> }
31,32c36,37
< return 0.0; /* acosh(1) = 0 */
< } else if (hx > 0x40000000) { /* 2**28 > x > 2 */
---
> return 0.0; // acosh(1)
> = 0
> } else if (hx > 0x40000000) { // 2**28 > x > 2
34,37c39,42
< return log(2.0*x-one/(x+sqrt(t-one)));
< } else { /* 1<x<2 */
< t = x-one;
< return log1p(t+sqrt(2.0*t+t*t));
---
> return Log.compute(2.0 * x - 1.0 / (x + Sqrt.compute(t
> - 1.0)));
> } else { // 1< x <2
> t = x - 1.0;
> return Log1p.compute(t + Sqrt.compute(2.0 * t + t * t));
-------------
PR Comment: https://git.openjdk.org/jdk/pull/29488#issuecomment-3883252611