On Wed, 29 Apr 2026 08:34:37 GMT, Anton Artemov <[email protected]> wrote:

> Hi, please consider the following changes:
> 
> This is a fix for the `StrictMath.pow()` method, which corrects its numerical 
> behavior in certain cases. 
> 
> It was recently reported by [Gladman et 
> al](https://members.loria.fr/PZimmermann/papers/accuracy.pdf) that the 
> `pow()` method in the original FDLIBM returns with error of 636 ulps in 
> certain cases. `StrictMath.pow()` is a direct port of FDLIBM `pow()`.
> 
> It turned out that `ivln2` constant split into high  and low parts (`ivln2_h` 
> and `ivln2_l` respectively) in the original method is not sufficient to 
> compute `u = ivln2_h * t` exactly in certain cases, namely when the span of 
> non-zero bits in `t` is wide. 
> 
> By the default split, the high part `ivln2_h` contains 24 high bits of 
> `ivln2`, and by changing the split so that `ivln2_h` contains only 21 bits of 
> `ivln2` we ensure that `u = ivln2_h * t` is computed exactly in all cases 
> when pow(x,y) does no overflow.
> 
> New testcases added.
> 
> ---------
> - [x] I confirm that I make this contribution in accordance with the [OpenJDK 
> Interim AI Policy](https://openjdk.org/legal/ai).

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

> 2208:             if (y_abs > 0x1.00000_ffff_ffffp31) { // if |y| > ~2**31
> 2209:                 final double INV_LN2   =  0x1.7154_7652_b82fep0;   //  
> 1.44269504088896338700e+00 = 1/ln2
> 2210:                 final double INV_LN2_H =  0x1.715476p0;            //  
> 1.44269502162933349609e+00 = 24 bits of 1/ln2

Please update the comment at the class-level of this file


  31  * Port of the "Freely Distributable Math Library", version 5.3, from
  32  * C to Java.


to mention a fix to pow. Otherwise, I think the change looks good to go back.

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

PR Review Comment: https://git.openjdk.org/jdk/pull/30984#discussion_r3262278845

Reply via email to