@@ -83,7 +83,7 @@ public abstract static class SqrtNode extends PythonUnaryBuiltinNode {
83
83
84
84
public abstract double executeObject (Object value );
85
85
86
- private static BigDecimal sqrtBigNumber (BigInteger value ) {
86
+ protected static BigDecimal sqrtBigNumber (BigInteger value ) {
87
87
BigDecimal number = new BigDecimal (value );
88
88
BigDecimal result = BigDecimal .ZERO ;
89
89
BigDecimal guess = BigDecimal .ONE ;
@@ -147,7 +147,7 @@ public double acosh(Object value,
147
147
return sqrtNode .executeObject (result );
148
148
}
149
149
150
- protected SqrtNode create () {
150
+ public static SqrtNode create () {
151
151
return MathModuleBuiltinsFactory .SqrtNodeFactory .create (new PNode [0 ]);
152
152
}
153
153
}
@@ -709,9 +709,9 @@ public PTuple frexpO(Object value) {
709
709
@ TypeSystemReference (PythonArithmeticTypes .class )
710
710
@ ImportStatic (MathGuards .class )
711
711
@ GenerateNodeFactory
712
- public abstract static class IsNanNode extends PythonBuiltinNode {
712
+ public abstract static class IsNanNode extends PythonUnaryBuiltinNode {
713
713
714
- public abstract boolean execute (Object value );
714
+ public abstract boolean executeObject (Object value );
715
715
716
716
@ Specialization
717
717
public boolean isNan (@ SuppressWarnings ("unused" ) long value ) {
@@ -736,10 +736,10 @@ public boolean isinf(Object value,
736
736
if (result == PNone .NO_VALUE ) {
737
737
throw raise (TypeError , "must be real number, not %p" , value );
738
738
}
739
- return isNanNode .execute (result );
739
+ return isNanNode .executeObject (result );
740
740
}
741
741
742
- protected IsNanNode create () {
742
+ protected static IsNanNode create () {
743
743
return MathModuleBuiltinsFactory .IsNanNodeFactory .create (new PNode [0 ]);
744
744
}
745
745
}
@@ -895,9 +895,9 @@ public double ldexpOO(Object mantissa, Object exp) {
895
895
@ TypeSystemReference (PythonArithmeticTypes .class )
896
896
@ ImportStatic (MathGuards .class )
897
897
@ GenerateNodeFactory
898
- public abstract static class AcosNode extends PythonBuiltinNode {
898
+ public abstract static class AcosNode extends PythonUnaryBuiltinNode {
899
899
900
- public abstract double execute (Object value );
900
+ public abstract double executeObject (Object value );
901
901
902
902
@ Specialization
903
903
public double acos (long value ,
@@ -931,10 +931,10 @@ public double acos(Object value,
931
931
if (result == PNone .NO_VALUE ) {
932
932
throw raise (TypeError , "must be real number, not %p" , value );
933
933
}
934
- return acosNode .execute (result );
934
+ return acosNode .executeObject (result );
935
935
}
936
936
937
- protected AcosNode create () {
937
+ protected static AcosNode create () {
938
938
return MathModuleBuiltinsFactory .AcosNodeFactory .create (new PNode [0 ]);
939
939
}
940
940
}
@@ -962,6 +962,20 @@ public double acoshDouble(double value,
962
962
return Math .log (value + Math .sqrt (value * value - 1.0 ));
963
963
}
964
964
965
+ @ Specialization
966
+ @ TruffleBoundary
967
+ public double acoshDouble (PInt value ,
968
+ @ Cached ("createBinaryProfile()" ) ConditionProfile doNotFit ) {
969
+ BigInteger bValue = value .getValue ();
970
+ if (doNotFit .profile (bValue .compareTo (BigInteger .ONE ) == -1 )) {
971
+ throw raise (ValueError , "math domain error" );
972
+ }
973
+
974
+ BigDecimal sqrt = SqrtNode .sqrtBigNumber (bValue .multiply (bValue ).subtract (BigInteger .ONE ));
975
+ BigDecimal bd = new BigDecimal (bValue );
976
+ return Math .log (bd .add (sqrt ).doubleValue ());
977
+ }
978
+
965
979
@ Specialization (guards = "!isNumber(value)" )
966
980
public double acosh (Object value ,
967
981
@ Cached ("create(__FLOAT__)" ) LookupAndCallUnaryNode dispatchFloat ,
@@ -973,7 +987,7 @@ public double acosh(Object value,
973
987
return acoshNode .executeObject (result );
974
988
}
975
989
976
- protected AcoshNode create () {
990
+ protected static AcoshNode create () {
977
991
return MathModuleBuiltinsFactory .AcoshNodeFactory .create (new PNode [0 ]);
978
992
}
979
993
}
@@ -1019,7 +1033,7 @@ public double acosh(Object value,
1019
1033
return asinNode .executeObject (result );
1020
1034
}
1021
1035
1022
- protected AsinNode create () {
1036
+ protected static AsinNode create () {
1023
1037
return MathModuleBuiltinsFactory .AsinNodeFactory .create (new PNode [0 ]);
1024
1038
}
1025
1039
}
@@ -1058,9 +1072,9 @@ public double sin(double value) {
1058
1072
@ TypeSystemReference (PythonArithmeticTypes .class )
1059
1073
@ ImportStatic (MathGuards .class )
1060
1074
@ GenerateNodeFactory
1061
- public abstract static class IsFiniteNode extends PythonBuiltinNode {
1075
+ public abstract static class IsFiniteNode extends PythonUnaryBuiltinNode {
1062
1076
1063
- public abstract boolean execute (Object value );
1077
+ public abstract boolean executeObject (Object value );
1064
1078
1065
1079
@ Specialization
1066
1080
public boolean isfinite (@ SuppressWarnings ("unused" ) long value ) {
@@ -1085,10 +1099,10 @@ public boolean isinf(Object value,
1085
1099
if (result == PNone .NO_VALUE ) {
1086
1100
throw raise (TypeError , "must be real number, not %p" , value );
1087
1101
}
1088
- return isFiniteNode .execute (result );
1102
+ return isFiniteNode .executeObject (result );
1089
1103
}
1090
1104
1091
- protected IsFiniteNode create () {
1105
+ protected static IsFiniteNode create () {
1092
1106
return MathModuleBuiltinsFactory .IsFiniteNodeFactory .create (new PNode [0 ]);
1093
1107
}
1094
1108
}
@@ -1097,9 +1111,9 @@ protected IsFiniteNode create() {
1097
1111
@ TypeSystemReference (PythonArithmeticTypes .class )
1098
1112
@ ImportStatic (MathGuards .class )
1099
1113
@ GenerateNodeFactory
1100
- public abstract static class IsInfNode extends PythonBuiltinNode {
1114
+ public abstract static class IsInfNode extends PythonUnaryBuiltinNode {
1101
1115
1102
- public abstract boolean execute (Object value );
1116
+ public abstract boolean executeObject (Object value );
1103
1117
1104
1118
@ Specialization
1105
1119
public boolean isinf (@ SuppressWarnings ("unused" ) long value ) {
@@ -1124,10 +1138,10 @@ public boolean isinf(Object value,
1124
1138
if (result == PNone .NO_VALUE ) {
1125
1139
throw raise (TypeError , "must be real number, not %p" , value );
1126
1140
}
1127
- return isInfNode .execute (result );
1141
+ return isInfNode .executeObject (result );
1128
1142
}
1129
1143
1130
- protected IsInfNode create () {
1144
+ protected static IsInfNode create () {
1131
1145
return MathModuleBuiltinsFactory .IsInfNodeFactory .create (new PNode [0 ]);
1132
1146
}
1133
1147
}
@@ -1366,7 +1380,7 @@ public double log(PInt value, Object base,
1366
1380
return logNode .executeObject (value , resultBase );
1367
1381
}
1368
1382
1369
- protected LogNode create () {
1383
+ public static LogNode create () {
1370
1384
return MathModuleBuiltinsFactory .LogNodeFactory .create (new PNode [0 ]);
1371
1385
}
1372
1386
}
0 commit comments