@@ -406,6 +406,9 @@ PComplex complexFromLong(LazyPythonClass cls, PInt real, @SuppressWarnings("unus
406
406
@ Specialization (guards = {"isNoValue(imag)" , "!isNoValue(number)" , "!isString(number)" })
407
407
PComplex complexFromObject (VirtualFrame frame , LazyPythonClass cls , Object number , @ SuppressWarnings ("unused" ) PNone imag ) {
408
408
PComplex value = getComplexNumberFromObject (frame , number );
409
+ if (value == null ) {
410
+ return createComplex (cls , getFirstArgCoerceToDouble ().execute (frame , number ), 0.0 );
411
+ }
409
412
return createComplex (cls , value );
410
413
}
411
414
@@ -427,31 +430,46 @@ PComplex complexFromDoubleComplex(LazyPythonClass cls, double one, PComplex two)
427
430
@ Specialization (guards = "!isString(one)" )
428
431
PComplex complexFromComplexLong (VirtualFrame frame , LazyPythonClass cls , Object one , long two ) {
429
432
PComplex value = getComplexNumberFromObject (frame , one );
433
+ if (value == null ) {
434
+ return createComplex (cls , getFirstArgCoerceToDouble ().execute (frame , one ), two );
435
+ }
430
436
return createComplex (cls , value .getReal (), value .getImag () + two );
431
437
}
432
438
433
439
@ Specialization (guards = "!isString(one)" )
434
440
PComplex complexFromComplexDouble (VirtualFrame frame , LazyPythonClass cls , Object one , double two ) {
435
441
PComplex value = getComplexNumberFromObject (frame , one );
442
+ if (value == null ) {
443
+ return createComplex (cls , getFirstArgCoerceToDouble ().execute (frame , one ), two );
444
+ }
436
445
return createComplex (cls , value .getReal (), value .getImag () + two );
437
446
}
438
447
439
448
@ Specialization (guards = "!isString(one)" )
440
449
PComplex complexFromComplexPInt (VirtualFrame frame , LazyPythonClass cls , Object one , PInt two ) {
441
450
PComplex value = getComplexNumberFromObject (frame , one );
451
+ if (value == null ) {
452
+ return createComplex (cls , getFirstArgCoerceToDouble ().execute (frame , one ), two .doubleValue ());
453
+ }
442
454
return createComplex (cls , value .getReal (), value .getImag () + two .doubleValue ());
443
455
}
444
456
445
457
@ Specialization (guards = "!isString(one)" )
446
458
PComplex complexFromComplexComplex (VirtualFrame frame , LazyPythonClass cls , Object one , PComplex two ) {
447
459
PComplex value = getComplexNumberFromObject (frame , one );
460
+ if (value == null ) {
461
+ return createComplex (cls , getFirstArgCoerceToDouble ().execute (frame , one ) - two .getImag (), two .getReal ());
462
+ }
448
463
return createComplex (cls , value .getReal () - two .getImag (), value .getImag () + two .getReal ());
449
464
}
450
465
451
466
@ Specialization (guards = {"!isString(one)" , "!isNoValue(two)" , "!isPComplex(two)" })
452
467
PComplex complexFromComplexObject (VirtualFrame frame , LazyPythonClass cls , Object one , Object two ) {
453
468
PComplex oneValue = getComplexNumberFromObject (frame , one );
454
469
double twoValue = getSecondArgCoerceToDouble ().execute (frame , two );
470
+ if (oneValue == null ) {
471
+ return createComplex (cls , getFirstArgCoerceToDouble ().execute (frame , one ), twoValue );
472
+ }
455
473
return createComplex (cls , oneValue .getReal (), oneValue .getImag () + twoValue );
456
474
}
457
475
@@ -528,7 +546,7 @@ private PComplex getComplexNumberFromObject(VirtualFrame frame, Object object) {
528
546
// the class extending PComplex but doesn't have __complex__ method
529
547
return (PComplex ) object ;
530
548
}
531
- return factory (). createComplex ( getFirstArgCoerceToDouble (). execute ( frame , object ), 0.0 ) ;
549
+ return null ;
532
550
}
533
551
}
534
552
@@ -1347,7 +1365,7 @@ Object createInt(LazyPythonClass cls, long arg, @SuppressWarnings("unused") PNon
1347
1365
}
1348
1366
1349
1367
@ Specialization (guards = "isNoValue(base)" )
1350
- Object createInt (VirtualFrame frame , LazyPythonClass cls , double arg , @ SuppressWarnings ("unused" ) PNone base ,
1368
+ Object createInt (LazyPythonClass cls , double arg , @ SuppressWarnings ("unused" ) PNone base ,
1351
1369
@ Cached ("createFloatInt()" ) FloatBuiltins .IntNode floatToIntNode ) {
1352
1370
Object result = floatToIntNode .executeWithDouble (arg );
1353
1371
return createInt (cls , result );
0 commit comments