32
32
33
33
import java .math .BigDecimal ;
34
34
import java .math .BigInteger ;
35
+ import java .math .MathContext ;
35
36
import java .util .List ;
36
37
37
38
import com .oracle .graal .python .builtins .Builtin ;
41
42
import com .oracle .graal .python .builtins .objects .floats .PFloat ;
42
43
import com .oracle .graal .python .builtins .objects .ints .PInt ;
43
44
import com .oracle .graal .python .builtins .objects .tuple .PTuple ;
44
- import com .oracle .graal .python .nodes .PNode ;
45
45
import com .oracle .graal .python .nodes .SpecialMethodNames ;
46
46
import com .oracle .graal .python .nodes .call .special .LookupAndCallUnaryNode ;
47
47
import com .oracle .graal .python .nodes .function .PythonBuiltinBaseNode ;
62
62
import com .oracle .truffle .api .dsl .Specialization ;
63
63
import com .oracle .truffle .api .dsl .TypeSystemReference ;
64
64
import com .oracle .truffle .api .profiles .ConditionProfile ;
65
- import java .math .MathContext ;
66
65
67
66
@ CoreFunctions (defineModule = "math" )
68
67
public class MathModuleBuiltins extends PythonBuiltins {
@@ -153,7 +152,7 @@ public double sqrt(Object value,
153
152
}
154
153
155
154
public static SqrtNode create () {
156
- return MathModuleBuiltinsFactory .SqrtNodeFactory .create (new PNode [ 0 ] );
155
+ return MathModuleBuiltinsFactory .SqrtNodeFactory .create ();
157
156
}
158
157
}
159
158
@@ -200,10 +199,7 @@ public long ceil(long value) {
200
199
201
200
@ Specialization
202
201
public int ceil (boolean value ) {
203
- if (value ) {
204
- return 1 ;
205
- }
206
- return 0 ;
202
+ return value ? 1 : 0 ;
207
203
}
208
204
209
205
@ Specialization
@@ -212,10 +208,10 @@ public Object ceil(PFloat value,
212
208
@ Cached ("create(__CEIL__)" ) LookupAndCallUnaryNode dispatchCeil ) {
213
209
Object result = dispatchCeil .executeObject (value );
214
210
if (PNone .NO_VALUE .equals (result )) {
215
- if (value .getValue () <= Long . MAX_VALUE ) {
216
- result = Math . ceil (value .getValue ());
211
+ if (MathGuards . fitLong ( value .getValue ()) ) {
212
+ return ceilLong (value .getValue ());
217
213
} else {
218
- result = factory (). createInt ( BigDecimal . valueOf ( Math . ceil (value .getValue ())). toBigInteger ());
214
+ return ceil (value .getValue ());
219
215
}
220
216
}
221
217
return result ;
@@ -745,7 +741,7 @@ public boolean isinf(Object value,
745
741
}
746
742
747
743
protected static IsNanNode create () {
748
- return MathModuleBuiltinsFactory .IsNanNodeFactory .create (new PNode [ 0 ] );
744
+ return MathModuleBuiltinsFactory .IsNanNodeFactory .create ();
749
745
}
750
746
}
751
747
@@ -940,7 +936,7 @@ public double acos(Object value,
940
936
}
941
937
942
938
protected static AcosNode create () {
943
- return MathModuleBuiltinsFactory .AcosNodeFactory .create (new PNode [ 0 ] );
939
+ return MathModuleBuiltinsFactory .AcosNodeFactory .create ();
944
940
}
945
941
}
946
942
@@ -993,7 +989,7 @@ public double acosh(Object value,
993
989
}
994
990
995
991
protected static AcoshNode create () {
996
- return MathModuleBuiltinsFactory .AcoshNodeFactory .create (new PNode [ 0 ] );
992
+ return MathModuleBuiltinsFactory .AcoshNodeFactory .create ();
997
993
}
998
994
}
999
995
@@ -1039,7 +1035,7 @@ public double asin(Object value,
1039
1035
}
1040
1036
1041
1037
protected static AsinNode create () {
1042
- return MathModuleBuiltinsFactory .AsinNodeFactory .create (new PNode [ 0 ] );
1038
+ return MathModuleBuiltinsFactory .AsinNodeFactory .create ();
1043
1039
}
1044
1040
}
1045
1041
@@ -1079,7 +1075,7 @@ public double cosh(Object value,
1079
1075
}
1080
1076
1081
1077
protected static CosNode create () {
1082
- return MathModuleBuiltinsFactory .CosNodeFactory .create (new PNode [ 0 ] );
1078
+ return MathModuleBuiltinsFactory .CosNodeFactory .create ();
1083
1079
}
1084
1080
}
1085
1081
@@ -1124,7 +1120,7 @@ public double coshO(Object value,
1124
1120
}
1125
1121
1126
1122
protected static CoshNode create () {
1127
- return MathModuleBuiltinsFactory .CoshNodeFactory .create (new PNode [ 0 ] );
1123
+ return MathModuleBuiltinsFactory .CoshNodeFactory .create ();
1128
1124
}
1129
1125
}
1130
1126
@@ -1164,7 +1160,7 @@ public double cosh(Object value,
1164
1160
}
1165
1161
1166
1162
protected static SinNode create () {
1167
- return MathModuleBuiltinsFactory .SinNodeFactory .create (new PNode [ 0 ] );
1163
+ return MathModuleBuiltinsFactory .SinNodeFactory .create ();
1168
1164
}
1169
1165
}
1170
1166
@@ -1209,7 +1205,7 @@ public double sinhO(Object value,
1209
1205
}
1210
1206
1211
1207
protected static SinhNode create () {
1212
- return MathModuleBuiltinsFactory .SinhNodeFactory .create (new PNode [ 0 ] );
1208
+ return MathModuleBuiltinsFactory .SinhNodeFactory .create ();
1213
1209
}
1214
1210
}
1215
1211
@@ -1249,7 +1245,7 @@ public double tanO(Object value,
1249
1245
}
1250
1246
1251
1247
protected static TanNode create () {
1252
- return MathModuleBuiltinsFactory .TanNodeFactory .create (new PNode [ 0 ] );
1248
+ return MathModuleBuiltinsFactory .TanNodeFactory .create ();
1253
1249
}
1254
1250
}
1255
1251
@@ -1289,7 +1285,7 @@ public double tanhO(Object value,
1289
1285
}
1290
1286
1291
1287
protected static TanhNode create () {
1292
- return MathModuleBuiltinsFactory .TanhNodeFactory .create (new PNode [ 0 ] );
1288
+ return MathModuleBuiltinsFactory .TanhNodeFactory .create ();
1293
1289
}
1294
1290
}
1295
1291
@@ -1329,7 +1325,7 @@ public double atanO(Object value,
1329
1325
}
1330
1326
1331
1327
protected static AtanNode create () {
1332
- return MathModuleBuiltinsFactory .AtanNodeFactory .create (new PNode [ 0 ] );
1328
+ return MathModuleBuiltinsFactory .AtanNodeFactory .create ();
1333
1329
}
1334
1330
}
1335
1331
@@ -1376,7 +1372,7 @@ public double atanhO(Object value,
1376
1372
}
1377
1373
1378
1374
protected static AtanhNode create () {
1379
- return MathModuleBuiltinsFactory .AtanhNodeFactory .create (new PNode [ 0 ] );
1375
+ return MathModuleBuiltinsFactory .AtanhNodeFactory .create ();
1380
1376
}
1381
1377
}
1382
1378
@@ -1420,7 +1416,7 @@ public double asinhO(Object value,
1420
1416
}
1421
1417
1422
1418
protected static AsinhNode create () {
1423
- return MathModuleBuiltinsFactory .AsinhNodeFactory .create (new PNode [ 0 ] );
1419
+ return MathModuleBuiltinsFactory .AsinhNodeFactory .create ();
1424
1420
}
1425
1421
}
1426
1422
@@ -1459,7 +1455,7 @@ public boolean isinf(Object value,
1459
1455
}
1460
1456
1461
1457
protected static IsFiniteNode create () {
1462
- return MathModuleBuiltinsFactory .IsFiniteNodeFactory .create (new PNode [ 0 ] );
1458
+ return MathModuleBuiltinsFactory .IsFiniteNodeFactory .create ();
1463
1459
}
1464
1460
}
1465
1461
@@ -1498,15 +1494,15 @@ public boolean isinf(Object value,
1498
1494
}
1499
1495
1500
1496
protected static IsInfNode create () {
1501
- return MathModuleBuiltinsFactory .IsInfNodeFactory .create (new PNode [ 0 ] );
1497
+ return MathModuleBuiltinsFactory .IsInfNodeFactory .create ();
1502
1498
}
1503
1499
}
1504
1500
1505
1501
@ Builtin (name = "log" , minNumOfArguments = 1 , maxNumOfArguments = 2 )
1506
1502
@ TypeSystemReference (PythonArithmeticTypes .class )
1507
1503
@ ImportStatic (MathGuards .class )
1508
1504
@ GenerateNodeFactory
1509
- public abstract static class LogNode extends PythonUnaryBuiltinNode {
1505
+ public abstract static class LogNode extends PythonBinaryBuiltinNode {
1510
1506
1511
1507
@ Child private LookupAndCallUnaryNode valueDispatchNode ;
1512
1508
@ Child private LookupAndCallUnaryNode baseDispatchNode ;
@@ -1718,13 +1714,13 @@ private Object getRealNumber(Object object, LookupAndCallUnaryNode dispatchNode,
1718
1714
}
1719
1715
1720
1716
public static LogNode create () {
1721
- return MathModuleBuiltinsFactory .LogNodeFactory .create (new PNode [ 0 ] );
1717
+ return MathModuleBuiltinsFactory .LogNodeFactory .create ();
1722
1718
}
1723
1719
}
1724
1720
1725
1721
@ Builtin (name = "fabs" , fixedNumOfArguments = 1 )
1726
1722
@ GenerateNodeFactory
1727
- public abstract static class fabsNode extends PythonBuiltinNode {
1723
+ public abstract static class FabsNode extends PythonBuiltinNode {
1728
1724
1729
1725
@ Specialization
1730
1726
public double fabs (int value ) {
@@ -1879,7 +1875,7 @@ public abstract static class PowNode extends PythonBinaryBuiltinNode {
1879
1875
}
1880
1876
1881
1877
public static PowNode create () {
1882
- return MathModuleBuiltinsFactory .PowNodeFactory .create (new PNode [ 0 ] );
1878
+ return MathModuleBuiltinsFactory .PowNodeFactory .create ();
1883
1879
}
1884
1880
}
1885
1881
@@ -1969,7 +1965,7 @@ public abstract static class Atan2Node extends PythonBinaryBuiltinNode {
1969
1965
}
1970
1966
1971
1967
protected Atan2Node create () {
1972
- return MathModuleBuiltinsFactory .Atan2NodeFactory .create (new PNode [ 0 ] );
1968
+ return MathModuleBuiltinsFactory .Atan2NodeFactory .create ();
1973
1969
}
1974
1970
}
1975
1971
}
0 commit comments