@@ -458,9 +458,9 @@ private double doSpecialCases(double left, double right, BranchProfile negativeR
458
458
// v**(+/-)inf is 1.0 if abs(v) == 1, unlike on Java
459
459
return 1 ;
460
460
}
461
- if (left == 0 && right < 0 ) {
461
+ if (left == 0 && right < 0 && Double . isFinite ( right ) ) {
462
462
negativeRaise .enter ();
463
- // 0**w is an error if w is negative, unlike Java
463
+ // 0**w is an error if w is finite and negative, unlike Java
464
464
throw raise (PythonBuiltinClassType .ZeroDivisionError , ErrorMessages .POW_ZERO_CANNOT_RAISE_TO_NEGATIVE_POWER );
465
465
}
466
466
return 0 ;
@@ -480,7 +480,7 @@ private double doOperation(double left, double right, BranchProfile negativeRais
480
480
if (doSpecialCases (left , right , negativeRaise ) == 1 ) {
481
481
return 1.0 ;
482
482
}
483
- if (left < 0 && (right % 1 != 0 )) {
483
+ if (left < 0 && Double . isFinite ( left ) && Double . isFinite ( right ) && (right % 1 != 0 )) {
484
484
CompilerDirectives .transferToInterpreterAndInvalidate ();
485
485
// Negative numbers raised to fractional powers become complex.
486
486
throw new UnexpectedResultException (callPow .execute (frame , factory ().createComplex (left , 0 ), factory ().createComplex (right , 0 ), none ));
@@ -495,7 +495,7 @@ Object doDDToComplex(VirtualFrame frame, double left, double right, PNone none,
495
495
if (doSpecialCases (left , right , negativeRaise ) == 1 ) {
496
496
return 1.0 ;
497
497
}
498
- if (left < 0 && (right % 1 != 0 )) {
498
+ if (left < 0 && Double . isFinite ( left ) && Double . isFinite ( right ) && (right % 1 != 0 )) {
499
499
// Negative numbers raised to fractional powers become complex.
500
500
return callPow .execute (frame , factory ().createComplex (left , 0 ), factory ().createComplex (right , 0 ), none );
501
501
}
0 commit comments