|
11 | 11 | import com.oracle.graal.python.builtins.objects.PNone;
|
12 | 12 | import com.oracle.graal.python.builtins.objects.complex.ComplexBuiltins;
|
13 | 13 | import com.oracle.graal.python.builtins.objects.complex.PComplex;
|
| 14 | +import com.oracle.graal.python.builtins.objects.object.PythonObjectLibrary; |
14 | 15 | import com.oracle.graal.python.builtins.objects.tuple.PTuple;
|
15 | 16 | import com.oracle.graal.python.nodes.ErrorMessages;
|
16 | 17 | import com.oracle.graal.python.nodes.function.PythonBuiltinBaseNode;
|
17 | 18 | import com.oracle.graal.python.nodes.function.builtins.PythonBinaryBuiltinNode;
|
18 | 19 | import com.oracle.graal.python.nodes.function.builtins.PythonUnaryBuiltinNode;
|
19 | 20 | import com.oracle.graal.python.nodes.truffle.PythonArithmeticTypes;
|
20 | 21 | import com.oracle.graal.python.nodes.util.CoerceToComplexNode;
|
21 |
| -import com.oracle.graal.python.nodes.util.CoerceToDoubleNode; |
22 | 22 | import com.oracle.graal.python.runtime.PythonCore;
|
23 | 23 | import com.oracle.graal.python.runtime.object.PythonObjectFactory;
|
24 | 24 | import com.oracle.truffle.api.CompilerDirectives;
|
|
29 | 29 | import com.oracle.truffle.api.dsl.Specialization;
|
30 | 30 | import com.oracle.truffle.api.dsl.TypeSystemReference;
|
31 | 31 | import com.oracle.truffle.api.frame.VirtualFrame;
|
| 32 | +import com.oracle.truffle.api.library.CachedLibrary; |
32 | 33 |
|
33 | 34 | import java.util.List;
|
34 | 35 |
|
@@ -327,19 +328,19 @@ PComplex doDD(double r, double phi) {
|
327 | 328 | return rect(r, phi);
|
328 | 329 | }
|
329 | 330 |
|
330 |
| - @Specialization |
331 |
| - PComplex doGeneral(VirtualFrame frame, Object r, Object phi, |
332 |
| - @Cached CoerceToDoubleNode coerceRToDouble, |
333 |
| - @Cached CoerceToDoubleNode coercePhiToDouble) { |
334 |
| - return rect(coerceRToDouble.execute(frame, r), coercePhiToDouble.execute(frame, phi)); |
| 331 | + @Specialization(limit = "2") |
| 332 | + PComplex doGeneral(Object r, Object phi, |
| 333 | + @CachedLibrary("r") PythonObjectLibrary rLib, |
| 334 | + @CachedLibrary("phi") PythonObjectLibrary phiLib) { |
| 335 | + return rect(rLib.asJavaDouble(r), phiLib.asJavaDouble(phi)); |
335 | 336 | }
|
336 | 337 |
|
337 | 338 | private PComplex rect(double r, double phi) {
|
338 | 339 | // deal with special values
|
339 | 340 | if (!Double.isFinite(r) || !Double.isFinite(phi)) {
|
340 | 341 | // need to raise an exception if r is a nonzero number and phi is infinite
|
341 | 342 | if (r != 0.0 && !Double.isNaN(r) && Double.isInfinite(phi)) {
|
342 |
| - throw raise(ValueError, "math domain error"); |
| 343 | + throw raise(ValueError, ErrorMessages.MATH_DOMAIN_ERROR); |
343 | 344 | }
|
344 | 345 |
|
345 | 346 | // if r is +/-infinity and phi is finite but nonzero then
|
@@ -434,7 +435,7 @@ private double computeRealPart(double real, double imag) {
|
434 | 435 | final double scaleUp = 0x1.0p53;
|
435 | 436 | return Math.log(Math.hypot(ax * scaleUp, ay * scaleUp)) - 53 * ln2;
|
436 | 437 | }
|
437 |
| - throw raise(ValueError, "math domain error"); |
| 438 | + throw raise(ValueError, ErrorMessages.MATH_DOMAIN_ERROR); |
438 | 439 | }
|
439 | 440 | double h = Math.hypot(ax, ay);
|
440 | 441 | if (0.71 <= h && h <= 1.73) {
|
|
0 commit comments