Skip to content

Commit e6223ea

Browse files
committed
Use math.gcd() in Limited API on Python 3.13+.
1 parent d546edb commit e6223ea

1 file changed

Lines changed: 13 additions & 1 deletion

File tree

src/quicktions.pyx

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,18 @@ cdef extern from *:
174174
#define __Quicktions_HAS_FAST_CTZ_ullong (0)
175175
#define __Quicktions_trailing_zeros_ullong(x) (0)
176176
#endif
177+
178+
#if defined(Py_LIMITED_API)
179+
#if Py_LIMITED_API >= 0x030d0000
180+
#define __Quicktions_HAS_FAST_MATH_GCD (1)
181+
#elif Py_LIMITED_API >= 0x030b0000
182+
static const int __Quicktions_HAS_FAST_MATH_GCD = (Py_Version >= 0x030d0000);
183+
#else
184+
#define __Quicktions_HAS_FAST_MATH_GCD (0)
185+
#endif
186+
#else
187+
#define __Quicktions_HAS_FAST_MATH_GCD (PY_VERSION_HEX >= 0x030d0000)
188+
#endif
177189
"""
178190
bint PyLong_IsCompact "__Quicktions_PyLong_IsCompact" (x)
179191
unsigned long long PyLong_CompactValueUnsigned "__Quicktions_PyLong_CompactValueUnsigned" (x)
@@ -184,7 +196,7 @@ cdef extern from *:
184196

185197
# CPython 3.5-3.12 has a fast PyLong GCD implementation that we can use.
186198
# In CPython 3.13, math.gcd() is fast enough to call it directly.
187-
const bint HAS_FAST_MATH_GCD "(PY_VERSION_HEX >= 0x030d0000)"
199+
const bint HAS_FAST_MATH_GCD "__Quicktions_HAS_FAST_MATH_GCD"
188200
const bint HAS_OLD_PYLONG_GCD "(CYTHON_COMPILING_IN_CPYTHON && PY_VERSION_HEX < 0x030d0000)"
189201
object _PyLong_GCD(object a, object b)
190202

0 commit comments

Comments
 (0)