|
40 | 40 | import com.oracle.graal.python.builtins.objects.floats.PFloat;
|
41 | 41 | import com.oracle.graal.python.builtins.objects.ints.PInt;
|
42 | 42 | import com.oracle.graal.python.builtins.objects.tuple.PTuple;
|
| 43 | +import com.oracle.graal.python.nodes.PNode; |
43 | 44 | import com.oracle.graal.python.nodes.call.special.LookupAndCallUnaryNode;
|
44 | 45 | import com.oracle.graal.python.nodes.function.PythonBuiltinNode;
|
45 | 46 | import com.oracle.graal.python.nodes.truffle.PythonArithmeticTypes;
|
@@ -827,19 +828,52 @@ public double ldexpOO(Object mantissa, Object exp) {
|
827 | 828 |
|
828 | 829 | }
|
829 | 830 |
|
830 |
| - @Builtin(name = "acos", fixedNumOfArguments = 1) |
| 831 | + @Builtin(name = "acos", fixedNumOfArguments = 1, doc = "Return the arc cosine (measured in radians) of x.") |
| 832 | + @TypeSystemReference(PythonArithmeticTypes.class) |
| 833 | + @ImportStatic(MathGuards.class) |
831 | 834 | @GenerateNodeFactory
|
832 | 835 | public abstract static class AcosNode extends PythonBuiltinNode {
|
833 | 836 |
|
| 837 | + public abstract double execute(Object value); |
| 838 | + |
834 | 839 | @Specialization
|
835 |
| - public double acos(int value) { |
| 840 | + public double acos(int value, |
| 841 | + @Cached("createBinaryProfile()") ConditionProfile doNotFit) { |
| 842 | + if (doNotFit.profile(value > 1 || value < -1)) { |
| 843 | + throw raise(ValueError, "math domain error"); |
| 844 | + } |
836 | 845 | return Math.acos(value);
|
837 | 846 | }
|
838 | 847 |
|
839 | 848 | @Specialization
|
840 |
| - public double acos(double value) { |
| 849 | + public double acos(PInt value, |
| 850 | + @Cached("createBinaryProfile()") ConditionProfile doNotFit) { |
| 851 | + return acos(value.intValue(), doNotFit); |
| 852 | + } |
| 853 | + |
| 854 | + @Specialization |
| 855 | + public double acos(double value, |
| 856 | + @Cached("createBinaryProfile()") ConditionProfile doNotFit) { |
| 857 | + if (doNotFit.profile(Double.isInfinite(value) || -1 > value || value > 1)) { |
| 858 | + throw raise(ValueError, "math domain error"); |
| 859 | + } |
841 | 860 | return Math.acos(value);
|
842 | 861 | }
|
| 862 | + |
| 863 | + @Specialization(guards = "!isNumber(value)") |
| 864 | + public double acos(Object value, |
| 865 | + @Cached("create(__FLOAT__)") LookupAndCallUnaryNode dispatchFloat, |
| 866 | + @Cached("create()") AcosNode acosNode) { |
| 867 | + Object result = dispatchFloat.executeObject(value); |
| 868 | + if (result == PNone.NO_VALUE) { |
| 869 | + throw raise(TypeError, "must be real number, not %p", value); |
| 870 | + } |
| 871 | + return acosNode.execute(result); |
| 872 | + } |
| 873 | + |
| 874 | + protected AcosNode create() { |
| 875 | + return MathModuleBuiltinsFactory.AcosNodeFactory.create(new PNode[0]); |
| 876 | + } |
843 | 877 | }
|
844 | 878 |
|
845 | 879 | @Builtin(name = "cos", fixedNumOfArguments = 1)
|
|
0 commit comments