@@ -897,35 +897,35 @@ cdef class Fraction:
897
897
898
898
def __floordiv__ (a , b ):
899
899
""" a // b"""
900
- return forward(a, b, _floordiv, _math_op_floordiv)
900
+ return forward(a, b, _floordiv, _math_op_floordiv, handle_complex = False )
901
901
902
902
def __rfloordiv__ (b , a ):
903
903
""" a // b"""
904
- return reverse(a, b, _floordiv, _math_op_floordiv)
904
+ return reverse(a, b, _floordiv, _math_op_floordiv, handle_complex = False )
905
905
906
906
def __mod__ (a , b ):
907
907
""" a % b """
908
- return forward(a, b, _mod, _math_op_mod)
908
+ return forward(a, b, _mod, _math_op_mod, handle_complex = False )
909
909
910
910
def __rmod__ (b , a ):
911
911
""" a % b """
912
- return reverse(a, b, _mod, _math_op_mod)
912
+ return reverse(a, b, _mod, _math_op_mod, handle_complex = False )
913
913
914
914
def __divmod__ (a , b ):
915
915
""" divmod(self, other): The pair (self // other, self % o ther).
916
916
917
917
Sometimes this can be computed faster than the pair of
918
918
operations.
919
919
"""
920
- return forward(a, b, _divmod, _math_op_divmod)
920
+ return forward(a, b, _divmod, _math_op_divmod, handle_complex = False )
921
921
922
922
def __rdivmod__ (b , a ):
923
923
""" divmod(self, other): The pair (self // other, self % o ther).
924
924
925
925
Sometimes this can be computed faster than the pair of
926
926
operations.
927
927
"""
928
- return reverse(a, b, _divmod, _math_op_divmod)
928
+ return reverse(a, b, _divmod, _math_op_divmod, handle_complex = False )
929
929
930
930
def __pow__ (a , b , x ):
931
931
""" a ** b
@@ -1516,7 +1516,7 @@ cdef:
1516
1516
ctypedef object (* math_func)(an, ad, bn, bd)
1517
1517
1518
1518
1519
- cdef forward(a, b, math_func monomorphic_operator, pyoperator):
1519
+ cdef forward(a, b, math_func monomorphic_operator, pyoperator, handle_complex = True ):
1520
1520
an, ad = (< Fraction> a)._numerator, (< Fraction> a)._denominator
1521
1521
if type (b) is Fraction:
1522
1522
return monomorphic_operator(an, ad, (< Fraction> b)._numerator, (< Fraction> b)._denominator)
@@ -1526,21 +1526,21 @@ cdef forward(a, b, math_func monomorphic_operator, pyoperator):
1526
1526
return monomorphic_operator(an, ad, b.numerator, b.denominator)
1527
1527
elif isinstance (b, float ):
1528
1528
return pyoperator(_as_float(an, ad), b)
1529
- elif isinstance (b, complex ):
1529
+ elif handle_complex and isinstance (b, complex ):
1530
1530
return pyoperator(complex (a), b)
1531
1531
else :
1532
1532
return NotImplemented
1533
1533
1534
1534
1535
- cdef reverse(a, b, math_func monomorphic_operator, pyoperator):
1535
+ cdef reverse(a, b, math_func monomorphic_operator, pyoperator, handle_complex = True ):
1536
1536
bn, bd = (< Fraction> b)._numerator, (< Fraction> b)._denominator
1537
1537
if isinstance (a, (int , long )):
1538
1538
return monomorphic_operator(a, 1 , bn, bd)
1539
1539
elif isinstance (a, Rational):
1540
1540
return monomorphic_operator(a.numerator, a.denominator, bn, bd)
1541
1541
elif isinstance (a, Real):
1542
1542
return pyoperator(float (a), _as_float(bn, bd))
1543
- elif isinstance (a, Complex):
1543
+ elif handle_complex and isinstance (a, Complex):
1544
1544
return pyoperator(complex (a), complex (b))
1545
1545
else :
1546
1546
return NotImplemented
0 commit comments