@@ -197,9 +197,18 @@ cdef extern from *:
197197    int  trailing_zeros_ullong " __Quicktions_trailing_zeros_ullong"   (unsigned  long  long  x)
198198
199199
200- cpdef  _gcd(a:  int , b:  int ):
200+ def  _gcd (a , b ):
201201    """ Calculate the Greatest Common Divisor of a and b as a non-negative number.
202202    """  
203+     if  not  isinstance (a, int ):
204+         raise  ValueError (f" Expected int, got {type(a).__name__}"  )
205+     if  not  isinstance (b, int ):
206+         raise  ValueError (f" Expected int, got {type(b).__name__}"  )
207+ 
208+     return  _igcd(int (a), int (b))
209+ 
210+ 
211+ cdef _igcd(a, b):
203212    if  HAS_ISLONGLONG:
204213        if  PyLong_IsLongLong(a) and  PyLong_IsLongLong(b):
205214            return  _c_gcd(< unsigned  long  long >  a, < unsigned  long  long >  b)
@@ -211,7 +220,7 @@ cpdef _gcd(a: int, b: int):
211220    if  HAS_OLD_PYLONG_GCD:
212221        return  _PyLong_GCD(a, b)
213222
214-     return  _gcd_fallback(a, b )
223+     return  _gcd_fallback(int (a),  int (b) )
215224
216225
217226ctypedef unsigned  long  long  ullong
@@ -760,7 +769,7 @@ cdef class Fraction:
760769                numerator =  int (numerator)
761770            if  not  isinstance (denominator, int ):
762771                denominator =  int (denominator)
763-             g =  _gcd (numerator, denominator)
772+             g =  _igcd (numerator, denominator)
764773            #  NOTE: 'is' tests on integers are generally a bad idea, but
765774            #  they are fast and if they fail here, it'll still be correct
766775            if  denominator <  0 :
0 commit comments