3232
3333import java .math .BigDecimal ;
3434import java .math .BigInteger ;
35+ import java .math .MathContext ;
3536import java .util .List ;
3637
3738import com .oracle .graal .python .builtins .Builtin ;
4142import com .oracle .graal .python .builtins .objects .floats .PFloat ;
4243import com .oracle .graal .python .builtins .objects .ints .PInt ;
4344import com .oracle .graal .python .builtins .objects .tuple .PTuple ;
44- import com .oracle .graal .python .nodes .PNode ;
4545import com .oracle .graal .python .nodes .SpecialMethodNames ;
4646import com .oracle .graal .python .nodes .call .special .LookupAndCallUnaryNode ;
4747import com .oracle .graal .python .nodes .function .PythonBuiltinBaseNode ;
6262import com .oracle .truffle .api .dsl .Specialization ;
6363import com .oracle .truffle .api .dsl .TypeSystemReference ;
6464import com .oracle .truffle .api .profiles .ConditionProfile ;
65- import java .math .MathContext ;
6665
6766@ CoreFunctions (defineModule = "math" )
6867public class MathModuleBuiltins extends PythonBuiltins {
@@ -153,7 +152,7 @@ public double sqrt(Object value,
153152 }
154153
155154 public static SqrtNode create () {
156- return MathModuleBuiltinsFactory .SqrtNodeFactory .create (new PNode [ 0 ] );
155+ return MathModuleBuiltinsFactory .SqrtNodeFactory .create ();
157156 }
158157 }
159158
@@ -200,10 +199,7 @@ public long ceil(long value) {
200199
201200 @ Specialization
202201 public int ceil (boolean value ) {
203- if (value ) {
204- return 1 ;
205- }
206- return 0 ;
202+ return value ? 1 : 0 ;
207203 }
208204
209205 @ Specialization
@@ -212,10 +208,10 @@ public Object ceil(PFloat value,
212208 @ Cached ("create(__CEIL__)" ) LookupAndCallUnaryNode dispatchCeil ) {
213209 Object result = dispatchCeil .executeObject (value );
214210 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 ());
217213 } else {
218- result = factory (). createInt ( BigDecimal . valueOf ( Math . ceil (value .getValue ())). toBigInteger ());
214+ return ceil (value .getValue ());
219215 }
220216 }
221217 return result ;
@@ -745,7 +741,7 @@ public boolean isinf(Object value,
745741 }
746742
747743 protected static IsNanNode create () {
748- return MathModuleBuiltinsFactory .IsNanNodeFactory .create (new PNode [ 0 ] );
744+ return MathModuleBuiltinsFactory .IsNanNodeFactory .create ();
749745 }
750746 }
751747
@@ -940,7 +936,7 @@ public double acos(Object value,
940936 }
941937
942938 protected static AcosNode create () {
943- return MathModuleBuiltinsFactory .AcosNodeFactory .create (new PNode [ 0 ] );
939+ return MathModuleBuiltinsFactory .AcosNodeFactory .create ();
944940 }
945941 }
946942
@@ -993,7 +989,7 @@ public double acosh(Object value,
993989 }
994990
995991 protected static AcoshNode create () {
996- return MathModuleBuiltinsFactory .AcoshNodeFactory .create (new PNode [ 0 ] );
992+ return MathModuleBuiltinsFactory .AcoshNodeFactory .create ();
997993 }
998994 }
999995
@@ -1039,7 +1035,7 @@ public double asin(Object value,
10391035 }
10401036
10411037 protected static AsinNode create () {
1042- return MathModuleBuiltinsFactory .AsinNodeFactory .create (new PNode [ 0 ] );
1038+ return MathModuleBuiltinsFactory .AsinNodeFactory .create ();
10431039 }
10441040 }
10451041
@@ -1079,7 +1075,7 @@ public double cosh(Object value,
10791075 }
10801076
10811077 protected static CosNode create () {
1082- return MathModuleBuiltinsFactory .CosNodeFactory .create (new PNode [ 0 ] );
1078+ return MathModuleBuiltinsFactory .CosNodeFactory .create ();
10831079 }
10841080 }
10851081
@@ -1124,7 +1120,7 @@ public double coshO(Object value,
11241120 }
11251121
11261122 protected static CoshNode create () {
1127- return MathModuleBuiltinsFactory .CoshNodeFactory .create (new PNode [ 0 ] );
1123+ return MathModuleBuiltinsFactory .CoshNodeFactory .create ();
11281124 }
11291125 }
11301126
@@ -1164,7 +1160,7 @@ public double cosh(Object value,
11641160 }
11651161
11661162 protected static SinNode create () {
1167- return MathModuleBuiltinsFactory .SinNodeFactory .create (new PNode [ 0 ] );
1163+ return MathModuleBuiltinsFactory .SinNodeFactory .create ();
11681164 }
11691165 }
11701166
@@ -1209,7 +1205,7 @@ public double sinhO(Object value,
12091205 }
12101206
12111207 protected static SinhNode create () {
1212- return MathModuleBuiltinsFactory .SinhNodeFactory .create (new PNode [ 0 ] );
1208+ return MathModuleBuiltinsFactory .SinhNodeFactory .create ();
12131209 }
12141210 }
12151211
@@ -1249,7 +1245,7 @@ public double tanO(Object value,
12491245 }
12501246
12511247 protected static TanNode create () {
1252- return MathModuleBuiltinsFactory .TanNodeFactory .create (new PNode [ 0 ] );
1248+ return MathModuleBuiltinsFactory .TanNodeFactory .create ();
12531249 }
12541250 }
12551251
@@ -1289,7 +1285,7 @@ public double tanhO(Object value,
12891285 }
12901286
12911287 protected static TanhNode create () {
1292- return MathModuleBuiltinsFactory .TanhNodeFactory .create (new PNode [ 0 ] );
1288+ return MathModuleBuiltinsFactory .TanhNodeFactory .create ();
12931289 }
12941290 }
12951291
@@ -1329,7 +1325,7 @@ public double atanO(Object value,
13291325 }
13301326
13311327 protected static AtanNode create () {
1332- return MathModuleBuiltinsFactory .AtanNodeFactory .create (new PNode [ 0 ] );
1328+ return MathModuleBuiltinsFactory .AtanNodeFactory .create ();
13331329 }
13341330 }
13351331
@@ -1376,7 +1372,7 @@ public double atanhO(Object value,
13761372 }
13771373
13781374 protected static AtanhNode create () {
1379- return MathModuleBuiltinsFactory .AtanhNodeFactory .create (new PNode [ 0 ] );
1375+ return MathModuleBuiltinsFactory .AtanhNodeFactory .create ();
13801376 }
13811377 }
13821378
@@ -1420,7 +1416,7 @@ public double asinhO(Object value,
14201416 }
14211417
14221418 protected static AsinhNode create () {
1423- return MathModuleBuiltinsFactory .AsinhNodeFactory .create (new PNode [ 0 ] );
1419+ return MathModuleBuiltinsFactory .AsinhNodeFactory .create ();
14241420 }
14251421 }
14261422
@@ -1459,7 +1455,7 @@ public boolean isinf(Object value,
14591455 }
14601456
14611457 protected static IsFiniteNode create () {
1462- return MathModuleBuiltinsFactory .IsFiniteNodeFactory .create (new PNode [ 0 ] );
1458+ return MathModuleBuiltinsFactory .IsFiniteNodeFactory .create ();
14631459 }
14641460 }
14651461
@@ -1498,15 +1494,15 @@ public boolean isinf(Object value,
14981494 }
14991495
15001496 protected static IsInfNode create () {
1501- return MathModuleBuiltinsFactory .IsInfNodeFactory .create (new PNode [ 0 ] );
1497+ return MathModuleBuiltinsFactory .IsInfNodeFactory .create ();
15021498 }
15031499 }
15041500
15051501 @ Builtin (name = "log" , minNumOfArguments = 1 , maxNumOfArguments = 2 )
15061502 @ TypeSystemReference (PythonArithmeticTypes .class )
15071503 @ ImportStatic (MathGuards .class )
15081504 @ GenerateNodeFactory
1509- public abstract static class LogNode extends PythonUnaryBuiltinNode {
1505+ public abstract static class LogNode extends PythonBinaryBuiltinNode {
15101506
15111507 @ Child private LookupAndCallUnaryNode valueDispatchNode ;
15121508 @ Child private LookupAndCallUnaryNode baseDispatchNode ;
@@ -1718,13 +1714,13 @@ private Object getRealNumber(Object object, LookupAndCallUnaryNode dispatchNode,
17181714 }
17191715
17201716 public static LogNode create () {
1721- return MathModuleBuiltinsFactory .LogNodeFactory .create (new PNode [ 0 ] );
1717+ return MathModuleBuiltinsFactory .LogNodeFactory .create ();
17221718 }
17231719 }
17241720
17251721 @ Builtin (name = "fabs" , fixedNumOfArguments = 1 )
17261722 @ GenerateNodeFactory
1727- public abstract static class fabsNode extends PythonBuiltinNode {
1723+ public abstract static class FabsNode extends PythonBuiltinNode {
17281724
17291725 @ Specialization
17301726 public double fabs (int value ) {
@@ -1879,7 +1875,7 @@ public abstract static class PowNode extends PythonBinaryBuiltinNode {
18791875 }
18801876
18811877 public static PowNode create () {
1882- return MathModuleBuiltinsFactory .PowNodeFactory .create (new PNode [ 0 ] );
1878+ return MathModuleBuiltinsFactory .PowNodeFactory .create ();
18831879 }
18841880 }
18851881
@@ -1969,7 +1965,7 @@ public abstract static class Atan2Node extends PythonBinaryBuiltinNode {
19691965 }
19701966
19711967 protected Atan2Node create () {
1972- return MathModuleBuiltinsFactory .Atan2NodeFactory .create (new PNode [ 0 ] );
1968+ return MathModuleBuiltinsFactory .Atan2NodeFactory .create ();
19731969 }
19741970 }
19751971}
0 commit comments