@@ -1456,13 +1456,20 @@ public double count(double value) {
1456
1456
@ GenerateNodeFactory
1457
1457
public abstract static class AcoshNode extends MathDoubleUnaryBuiltinNode {
1458
1458
1459
+ private static final double TWO_POW_P28 = 0x1.0p28 ;
1460
+ private static final double LN_2 = 6.93147180559945286227e-01 ;
1461
+
1459
1462
@ Specialization
1460
1463
@ TruffleBoundary
1461
1464
@ Override
1462
1465
public double doPI (PInt value ) {
1463
1466
BigInteger bValue = value .getValue ();
1464
1467
checkMathDomainError (bValue .compareTo (BigInteger .ONE ) < 0 );
1465
1468
1469
+ if (bValue .bitLength () >= 28 ) {
1470
+ return Math .log (bValue .doubleValue ()) + LN_2 ;
1471
+ }
1472
+
1466
1473
BigDecimal sqrt = SqrtNode .sqrtBigNumber (bValue .multiply (bValue ).subtract (BigInteger .ONE ));
1467
1474
BigDecimal bd = new BigDecimal (bValue );
1468
1475
return Math .log (bd .add (sqrt ).doubleValue ());
@@ -1471,6 +1478,13 @@ public double doPI(PInt value) {
1471
1478
@ Override
1472
1479
public double count (double value ) {
1473
1480
checkMathDomainError (value < 1 );
1481
+ if (value >= TWO_POW_P28 ) {
1482
+ return Math .log (value ) + LN_2 ;
1483
+ }
1484
+ if (value <= 2.0 ) {
1485
+ double t = value - 1.0 ;
1486
+ return Math .log1p (t + Math .sqrt (2.0 * t + t * t ));
1487
+ }
1474
1488
return Math .log (value + Math .sqrt (value * value - 1.0 ));
1475
1489
}
1476
1490
}
@@ -1564,13 +1578,23 @@ public double count(double value) {
1564
1578
@ GenerateNodeFactory
1565
1579
public abstract static class AtanhNode extends MathDoubleUnaryBuiltinNode {
1566
1580
1581
+ private static final double TWO_POW_M28 = 0x1.0p-28 ;
1582
+
1567
1583
@ Override
1568
1584
public double count (double value ) {
1569
- if (value == 0 ) {
1570
- return 0 ;
1585
+ double abs = Math .abs (value );
1586
+ checkMathDomainError (abs >= 1.0 );
1587
+ if (abs < TWO_POW_M28 ) {
1588
+ return value ;
1589
+ }
1590
+ double t ;
1591
+ if (abs < 0.5 ) {
1592
+ t = abs + abs ;
1593
+ t = 0.5 * Math .log1p (t + t * abs / (1.0 - abs ));
1594
+ } else {
1595
+ t = 0.5 * Math .log1p ((abs + abs ) / (1.0 - abs ));
1571
1596
}
1572
- checkMathDomainError (value <= -1 || value >= 1 );
1573
- return Math .log ((1 / value + 1 ) / (1 / value - 1 )) / 2 ;
1597
+ return Math .copySign (t , value );
1574
1598
}
1575
1599
}
1576
1600
0 commit comments