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) {                      // 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));

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

Commit messages:
 - 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.
 - 8375285: Port of fdlibm asinh function

Changes: https://git.openjdk.org/jdk/pull/29488/files
  Webrev: https://webrevs.openjdk.org/?repo=jdk&pr=29488&range=00
  Issue: https://bugs.openjdk.org/browse/JDK-8376665
  Stats: 1163 lines in 7 files changed: 1149 ins; 0 del; 14 mod
  Patch: https://git.openjdk.org/jdk/pull/29488.diff
  Fetch: git fetch https://git.openjdk.org/jdk.git pull/29488/head:pull/29488

PR: https://git.openjdk.org/jdk/pull/29488

Reply via email to