1
1
/*
2
- * Copyright (c) 1998, 2024 , Oracle and/or its affiliates. All rights reserved.
2
+ * Copyright (c) 1998, 2025 , Oracle and/or its affiliates. All rights reserved.
3
3
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4
4
*
5
5
* This code is free software; you can redistribute it and/or modify it
25
25
26
26
package java .lang ;
27
27
28
+ import jdk .internal .vm .annotation .Stable ;
29
+
28
30
/**
29
31
* Port of the "Freely Distributable Math Library", version 5.3, from
30
32
* C to Java.
@@ -451,8 +453,10 @@ static double compute(double x) {
451
453
*/
452
454
private static final double
453
455
pio4 = 0x1.921fb54442d18p-1 , // 7.85398163397448278999e-01
454
- pio4lo = 0x1.1a62633145c07p-55 , // 3.06161699786838301793e-17
455
- T [] = {
456
+ pio4lo = 0x1.1a62633145c07p-55 ; // 3.06161699786838301793e-17
457
+ @ Stable
458
+ private static final double []
459
+ T = {
456
460
0x1.5555555555563p-2 , // 3.33333333333334091986e-01
457
461
0x1.111111110fe7ap-3 , // 1.33333333333201242699e-01
458
462
0x1.ba1ba1bb341fep-5 , // 5.39682539762260521377e-02
@@ -546,6 +550,7 @@ static final class RemPio2 {
546
550
/*
547
551
* Table of constants for 2/pi, 396 Hex digits (476 decimal) of 2/pi
548
552
*/
553
+ @ Stable
549
554
private static final int [] two_over_pi = {
550
555
0xA2F983 , 0x6E4E44 , 0x1529FC , 0x2757D1 , 0xF534DD , 0xC0DB62 ,
551
556
0x95993C , 0x439041 , 0xFE5163 , 0xABDEBB , 0xC561B7 , 0x246E3A ,
@@ -560,6 +565,7 @@ static final class RemPio2 {
560
565
0x4D7327 , 0x310606 , 0x1556CA , 0x73A8C9 , 0x60E27B , 0xC08C6B ,
561
566
};
562
567
568
+ @ Stable
563
569
private static final int [] npio2_hw = {
564
570
0x3FF921FB , 0x400921FB , 0x4012D97C , 0x401921FB , 0x401F6A7A , 0x4022D97C ,
565
571
0x4025FDBB , 0x402921FB , 0x402C463A , 0x402F6A7A , 0x4031475C , 0x4032D97C ,
@@ -807,8 +813,10 @@ static final class KernelRemPio2 {
807
813
* to produce the hexadecimal values shown.
808
814
*/
809
815
816
+ @ Stable
810
817
private static final int init_jk [] = {2 , 3 , 4 , 6 }; // initial value for jk
811
818
819
+ @ Stable
812
820
private static final double PIo2 [] = {
813
821
0x1.921fb4p0 , // 1.57079625129699707031e+00
814
822
0x1.4442dp-24 , // 7.54978941586159635335e-08
@@ -1232,20 +1240,23 @@ static double compute(double x) {
1232
1240
static final class Atan {
1233
1241
private Atan () {throw new UnsupportedOperationException ();}
1234
1242
1243
+ @ Stable
1235
1244
private static final double atanhi [] = {
1236
1245
0x1.dac670561bb4fp-2 , // atan(0.5)hi 4.63647609000806093515e-01
1237
1246
0x1.921fb54442d18p-1 , // atan(1.0)hi 7.85398163397448278999e-01
1238
1247
0x1.f730bd281f69bp-1 , // atan(1.5)hi 9.82793723247329054082e-01
1239
1248
0x1.921fb54442d18p0 , // atan(inf)hi 1.57079632679489655800e+00
1240
1249
};
1241
1250
1251
+ @ Stable
1242
1252
private static final double atanlo [] = {
1243
1253
0x1.a2b7f222f65e2p-56 , // atan(0.5)lo 2.26987774529616870924e-17
1244
1254
0x1.1a62633145c07p-55 , // atan(1.0)lo 3.06161699786838301793e-17
1245
1255
0x1.007887af0cbbdp-56 , // atan(1.5)lo 1.39033110312309984516e-17
1246
1256
0x1.1a62633145c07p-54 , // atan(inf)lo 6.12323399573676603587e-17
1247
1257
};
1248
1258
1259
+ @ Stable
1249
1260
private static final double aT [] = {
1250
1261
0x1.555555555550dp-2 , // 3.33333333333329318027e-01
1251
1262
-0x1.999999998ebc4p-3 , // -1.99999999998764832476e-01
@@ -2245,12 +2256,8 @@ else if (j < 0xBB67A)
2245
2256
2246
2257
// Compute ss = s_h + s_l = (x-1)/(x+1) or (x-1.5)/(x+1.5)
2247
2258
2248
- final double BP [] = {1.0 ,
2249
- 1.5 };
2250
- final double DP_H [] = {0.0 ,
2251
- 0x1.2b80_34p-1 }; // 5.84962487220764160156e-01
2252
- final double DP_L [] = {0.0 ,
2253
- 0x1.cfde_b43c_fd006p-27 };// 1.35003920212974897128e-08
2259
+ final double DP_H = 0x1.2b80_34p-1 ; // 5.84962487220764160156e-01
2260
+ final double DP_L = 0x1.cfde_b43c_fd006p-27 ; // 1.35003920212974897128e-08
2254
2261
2255
2262
// Poly coefs for (3/2)*(log(x)-2s-2/3*s**3
2256
2263
final double L1 = 0x1.3333_3333_33303p-1 ; // 5.99999999999994648725e-01
@@ -2259,15 +2266,17 @@ else if (j < 0xBB67A)
2259
2266
final double L4 = 0x1.1746_0a91_d4101p-2 ; // 2.72728123808534006489e-01
2260
2267
final double L5 = 0x1.d864_a93c_9db65p-3 ; // 2.30660745775561754067e-01
2261
2268
final double L6 = 0x1.a7e2_84a4_54eefp-3 ; // 2.06975017800338417784e-01
2262
- u = x_abs - BP [k ]; // BP[0]=1.0, BP[1]=1.5
2263
- v = 1.0 / (x_abs + BP [k ]);
2269
+
2270
+ double BP_k = 1.0 + 0.5 *k ; // BP[0]=1.0, BP[1]=1.5
2271
+ u = x_abs - BP_k ;
2272
+ v = 1.0 / (x_abs + BP_k );
2264
2273
ss = u * v ;
2265
2274
s_h = ss ;
2266
2275
s_h = __LO (s_h , 0 );
2267
2276
// t_h=x_abs + BP[k] High
2268
2277
t_h = 0.0 ;
2269
2278
t_h = __HI (t_h , ((ix >> 1 ) | 0x20000000 ) + 0x00080000 + (k << 18 ) );
2270
- t_l = x_abs - (t_h - BP [ k ] );
2279
+ t_l = x_abs - (t_h - BP_k );
2271
2280
s_l = v * ((u - s_h * t_h ) - s_h * t_l );
2272
2281
// Compute log(x_abs)
2273
2282
s2 = ss * ss ;
@@ -2285,12 +2294,12 @@ else if (j < 0xBB67A)
2285
2294
p_h = __LO (p_h , 0 );
2286
2295
p_l = v - (p_h - u );
2287
2296
z_h = CP_H * p_h ; // CP_H + CP_L = 2/(3*log2)
2288
- z_l = CP_L * p_h + p_l * CP + DP_L [ k ] ;
2297
+ z_l = CP_L * p_h + p_l * CP + DP_L * k ;
2289
2298
// log2(x_abs) = (ss + ..)*2/(3*log2) = n + DP_H + z_h + z_l
2290
2299
t = (double )n ;
2291
- t1 = (((z_h + z_l ) + DP_H [ k ] ) + t );
2300
+ t1 = (((z_h + z_l ) + DP_H * k ) + t );
2292
2301
t1 = __LO (t1 , 0 );
2293
- t2 = z_l - (((t1 - t ) - DP_H [ k ] ) - z_h );
2302
+ t2 = z_l - (((t1 - t ) - DP_H * k ) - z_h );
2294
2303
}
2295
2304
2296
2305
// Split up y into (y1 + y2) and compute (y1 + y2) * (t1 + t2)
@@ -2430,13 +2439,13 @@ else if (j < 0xBB67A)
2430
2439
static final class Exp {
2431
2440
private Exp () {throw new UnsupportedOperationException ();}
2432
2441
2433
- private static final double [] half = {0.5 , -0.5 ,};
2434
2442
private static final double huge = 1.0e+300 ;
2435
2443
private static final double twom1000 = 0x1.0p-1000 ; // 9.33263618503218878990e-302 = 2^-1000
2436
2444
private static final double o_threshold = 0x1.62e42fefa39efp9 ; // 7.09782712893383973096e+02
2437
2445
private static final double u_threshold = -0x1.74910d52d3051p9 ; // -7.45133219101941108420e+02;
2438
- private static final double [] ln2HI ={ 0x1.62e42feep-1 , // 6.93147180369123816490e-01
2439
- -0x1.62e42feep-1 }; // -6.93147180369123816490e-01
2446
+ private static final double ln2HI = 0x1.62e42feep-1 ; // 6.93147180369123816490e-01
2447
+
2448
+ @ Stable
2440
2449
private static final double [] ln2LO ={ 0x1.a39ef35793c76p-33 , // 1.90821492927058770002e-10
2441
2450
-0x1.a39ef35793c76p-33 }; // -1.90821492927058770002e-10
2442
2451
private static final double invln2 = 0x1.71547652b82fep0 ; // 1.44269504088896338700e+00
@@ -2478,13 +2487,13 @@ public static double compute(double x) {
2478
2487
/* argument reduction */
2479
2488
if (hx > 0x3fd62e42 ) { /* if |x| > 0.5 ln2 */
2480
2489
if (hx < 0x3FF0A2B2 ) { /* and |x| < 1.5 ln2 */
2481
- hi = x - ln2HI [ xsb ];
2490
+ hi = x - ln2HI *( 1 - 2 * xsb ); /* +/- ln2HI */
2482
2491
lo =ln2LO [xsb ];
2483
2492
k = 1 - xsb - xsb ;
2484
2493
} else {
2485
- k = (int )(invln2 * x + half [ xsb ] );
2494
+ k = (int )(invln2 * x + 0.5 * ( 1 - 2 * xsb ) /* +/- 0.5 */ );
2486
2495
t = k ;
2487
- hi = x - t *ln2HI [ 0 ] ; /* t*ln2HI is exact here */
2496
+ hi = x - t *ln2HI ; /* t*ln2HI is exact here */
2488
2497
lo = t *ln2LO [0 ];
2489
2498
}
2490
2499
x = hi - lo ;
0 commit comments