105
105
import com .oracle .truffle .api .profiles .InlinedConditionProfile ;
106
106
import com .oracle .truffle .api .profiles .InlinedLoopConditionProfile ;
107
107
import com .oracle .truffle .api .profiles .LoopConditionProfile ;
108
+ import com .oracle .truffle .api .utilities .MathUtils ;
108
109
109
110
@ CoreFunctions (defineModule = "math" )
110
111
public final class MathModuleBuiltins extends PythonBuiltins {
@@ -1258,7 +1259,6 @@ private static double compute(Node inliningTarget, double value, PRaiseNode.Lazy
1258
1259
@ GenerateNodeFactory
1259
1260
public abstract static class AcoshNode extends PythonUnaryBuiltinNode {
1260
1261
1261
- private static final double TWO_POW_P28 = 0x1.0p28 ;
1262
1262
private static final double LN_2 = 6.93147180559945286227e-01 ;
1263
1263
1264
1264
@ Specialization
@@ -1285,14 +1285,7 @@ static double doGeneric(VirtualFrame frame, Object value,
1285
1285
1286
1286
private static double compute (Node inliningTarget , double value , PRaiseNode .Lazy raiseNode ) {
1287
1287
checkMathDomainError (value < 1 , inliningTarget , raiseNode );
1288
- if (value >= TWO_POW_P28 ) {
1289
- return Math .log (value ) + LN_2 ;
1290
- }
1291
- if (value <= 2.0 ) {
1292
- double t = value - 1.0 ;
1293
- return Math .log1p (t + Math .sqrt (2.0 * t + t * t ));
1294
- }
1295
- return Math .log (value + Math .sqrt (value * value - 1.0 ));
1288
+ return MathUtils .acosh (value );
1296
1289
}
1297
1290
}
1298
1291
@@ -1433,8 +1426,6 @@ private static double compute(Node inliningTarget, double value, PRaiseNode.Lazy
1433
1426
@ GenerateNodeFactory
1434
1427
public abstract static class AtanhNode extends PythonUnaryBuiltinNode {
1435
1428
1436
- private static final double TWO_POW_M28 = 0x1.0p-28 ;
1437
-
1438
1429
@ Specialization
1439
1430
static double doGeneric (VirtualFrame frame , Object value ,
1440
1431
@ Bind ("this" ) Node inliningTarget ,
@@ -1445,17 +1436,7 @@ static double doGeneric(VirtualFrame frame, Object value,
1445
1436
private static double compute (Node inliningTarget , double value , PRaiseNode .Lazy raiseNode ) {
1446
1437
double abs = Math .abs (value );
1447
1438
checkMathDomainError (abs >= 1.0 , inliningTarget , raiseNode );
1448
- if (abs < TWO_POW_M28 ) {
1449
- return value ;
1450
- }
1451
- double t ;
1452
- if (abs < 0.5 ) {
1453
- t = abs + abs ;
1454
- t = 0.5 * Math .log1p (t + t * abs / (1.0 - abs ));
1455
- } else {
1456
- t = 0.5 * Math .log1p ((abs + abs ) / (1.0 - abs ));
1457
- }
1458
- return Math .copySign (t , value );
1439
+ return MathUtils .atanh (value );
1459
1440
}
1460
1441
}
1461
1442
@@ -1465,41 +1446,15 @@ private static double compute(Node inliningTarget, double value, PRaiseNode.Lazy
1465
1446
@ GenerateNodeFactory
1466
1447
public abstract static class AsinhNode extends PythonUnaryBuiltinNode {
1467
1448
1468
- private static final double LN_2 = 6.93147180559945286227e-01 ;
1469
- private static final double TWO_POW_P28 = 0x1.0p28 ;
1470
- private static final double TWO_POW_M28 = 0x1.0p-28 ;
1471
-
1472
1449
@ Specialization
1473
1450
static double doGeneric (VirtualFrame frame , Object value ,
1474
1451
@ Bind ("this" ) Node inliningTarget ,
1475
1452
@ Cached MathUnaryHelperNode helperNode ) {
1476
1453
return helperNode .execute (frame , inliningTarget , value , AsinhNode ::compute );
1477
1454
}
1478
1455
1479
- @ TruffleBoundary
1480
1456
private static double compute (Node inliningTarget , double value , PRaiseNode .Lazy raiseNode ) {
1481
- return compute (value );
1482
- }
1483
-
1484
- static double compute (double value ) {
1485
- double absx = Math .abs (value );
1486
-
1487
- if (Double .isNaN (value ) || Double .isInfinite (value )) {
1488
- return value + value ;
1489
- }
1490
- if (absx < TWO_POW_M28 ) {
1491
- return value ;
1492
- }
1493
- double w ;
1494
- if (absx > TWO_POW_P28 ) {
1495
- w = Math .log (absx ) + LN_2 ;
1496
- } else if (absx > 2.0 ) {
1497
- w = Math .log (2.0 * absx + 1.0 / (Math .sqrt (value * value + 1.0 ) + absx ));
1498
- } else {
1499
- double t = value * value ;
1500
- w = Math .log1p (absx + t / (1.0 + Math .sqrt (1.0 + t )));
1501
- }
1502
- return Math .copySign (w , value );
1457
+ return MathUtils .asinh (value );
1503
1458
}
1504
1459
1505
1460
public static AsinhNode create () {
0 commit comments