@@ -641,17 +641,20 @@ public PTuple frexpO(Object value) {
641
641
}
642
642
643
643
@ Builtin (name = "isnan" , fixedNumOfArguments = 1 )
644
+ @ TypeSystemReference (PythonArithmeticTypes .class )
645
+ @ ImportStatic (MathGuards .class )
644
646
@ GenerateNodeFactory
645
- @ SuppressWarnings ("unused" )
646
647
public abstract static class IsNanNode extends PythonBuiltinNode {
647
648
649
+ public abstract boolean execute (Object value );
650
+
648
651
@ Specialization
649
- public boolean isNan (int value ) {
652
+ public boolean isNan (@ SuppressWarnings ( "unused" ) long value ) {
650
653
return false ;
651
654
}
652
655
653
656
@ Specialization
654
- public boolean isNan (long value ) {
657
+ public boolean isNan (@ SuppressWarnings ( "unused" ) PInt value ) {
655
658
return false ;
656
659
}
657
660
@@ -660,24 +663,19 @@ public boolean isNan(double value) {
660
663
return Double .isNaN (value );
661
664
}
662
665
663
- @ Specialization
664
- public boolean isNan (PInt value ) {
665
- return false ;
666
- }
667
-
668
- @ Specialization
669
- public boolean isNan (PFloat value ) {
670
- return Double .isNaN (value .getValue ());
666
+ @ Specialization (guards = "!isNumber(value)" )
667
+ public boolean isinf (Object value ,
668
+ @ Cached ("create(__FLOAT__)" ) LookupAndCallUnaryNode dispatchFloat ,
669
+ @ Cached ("create()" ) IsNanNode isNanNode ) {
670
+ Object result = dispatchFloat .executeObject (value );
671
+ if (result == PNone .NO_VALUE ) {
672
+ throw raise (TypeError , "must be real number, not %p" , value );
673
+ }
674
+ return isNanNode .execute (result );
671
675
}
672
676
673
- @ Specialization
674
- public boolean isNan (boolean value ) {
675
- return false ;
676
- }
677
-
678
- @ Fallback
679
- public boolean isNan (Object value ) {
680
- throw raise (TypeError , "must be real number, not %p" , value );
677
+ protected IsNanNode create () {
678
+ return MathModuleBuiltinsFactory .IsNanNodeFactory .create (new PNode [0 ]);
681
679
}
682
680
}
683
681
@@ -837,7 +835,7 @@ public abstract static class AcosNode extends PythonBuiltinNode {
837
835
public abstract double execute (Object value );
838
836
839
837
@ Specialization
840
- public double acos (int value ,
838
+ public double acos (long value ,
841
839
@ Cached ("createBinaryProfile()" ) ConditionProfile doNotFit ) {
842
840
if (doNotFit .profile (value > 1 || value < -1 )) {
843
841
throw raise (ValueError , "math domain error" );
@@ -906,6 +904,84 @@ public double sin(double value) {
906
904
}
907
905
}
908
906
907
+ @ Builtin (name = "isfinite" , fixedNumOfArguments = 1 )
908
+ @ TypeSystemReference (PythonArithmeticTypes .class )
909
+ @ ImportStatic (MathGuards .class )
910
+ @ GenerateNodeFactory
911
+ public abstract static class IsFiniteNode extends PythonBuiltinNode {
912
+
913
+ public abstract boolean execute (Object value );
914
+
915
+ @ Specialization
916
+ public boolean isfinite (@ SuppressWarnings ("unused" ) long value ) {
917
+ return true ;
918
+ }
919
+
920
+ @ Specialization
921
+ public boolean isfinite (@ SuppressWarnings ("unused" ) PInt value ) {
922
+ return true ;
923
+ }
924
+
925
+ @ Specialization
926
+ public boolean isfinite (double value ) {
927
+ return Double .isFinite (value );
928
+ }
929
+
930
+ @ Specialization (guards = "!isNumber(value)" )
931
+ public boolean isinf (Object value ,
932
+ @ Cached ("create(__FLOAT__)" ) LookupAndCallUnaryNode dispatchFloat ,
933
+ @ Cached ("create()" ) IsFiniteNode isFiniteNode ) {
934
+ Object result = dispatchFloat .executeObject (value );
935
+ if (result == PNone .NO_VALUE ) {
936
+ throw raise (TypeError , "must be real number, not %p" , value );
937
+ }
938
+ return isFiniteNode .execute (result );
939
+ }
940
+
941
+ protected IsFiniteNode create () {
942
+ return MathModuleBuiltinsFactory .IsFiniteNodeFactory .create (new PNode [0 ]);
943
+ }
944
+ }
945
+
946
+ @ Builtin (name = "isinf" , fixedNumOfArguments = 1 )
947
+ @ TypeSystemReference (PythonArithmeticTypes .class )
948
+ @ ImportStatic (MathGuards .class )
949
+ @ GenerateNodeFactory
950
+ public abstract static class IsInfNode extends PythonBuiltinNode {
951
+
952
+ public abstract boolean execute (Object value );
953
+
954
+ @ Specialization
955
+ public boolean isinf (@ SuppressWarnings ("unused" ) long value ) {
956
+ return false ;
957
+ }
958
+
959
+ @ Specialization
960
+ public boolean isfinite (@ SuppressWarnings ("unused" ) PInt value ) {
961
+ return false ;
962
+ }
963
+
964
+ @ Specialization
965
+ public boolean isinf (double value ) {
966
+ return Double .isInfinite (value );
967
+ }
968
+
969
+ @ Specialization (guards = "!isNumber(value)" )
970
+ public boolean isinf (Object value ,
971
+ @ Cached ("create(__FLOAT__)" ) LookupAndCallUnaryNode dispatchFloat ,
972
+ @ Cached ("create()" ) IsInfNode isInfNode ) {
973
+ Object result = dispatchFloat .executeObject (value );
974
+ if (result == PNone .NO_VALUE ) {
975
+ throw raise (TypeError , "must be real number, not %p" , value );
976
+ }
977
+ return isInfNode .execute (result );
978
+ }
979
+
980
+ protected IsInfNode create () {
981
+ return MathModuleBuiltinsFactory .IsInfNodeFactory .create (new PNode [0 ]);
982
+ }
983
+ }
984
+
909
985
@ Builtin (name = "log" , minNumOfArguments = 1 , maxNumOfArguments = 2 )
910
986
@ GenerateNodeFactory
911
987
public abstract static class LogNode extends PythonBuiltinNode {
0 commit comments