Commit 74435af4 authored by Stefan Behnel's avatar Stefan Behnel

align abs(long long) implementation with abs(ssize_t) macro

parent 7e803a0f
......@@ -222,19 +222,22 @@ static CYTHON_INLINE unsigned long __Pyx_abs_long(long x) {
//////////////////// abs_longlong.proto ////////////////////
static CYTHON_INLINE unsigned PY_LONG_LONG __Pyx_abs_longlong(PY_LONG_LONG x) {
#ifndef PY_LLONG_MAX
#ifdef LLONG_MAX
const PY_LONG_LONG PY_LLONG_MAX = LLONG_MAX;
#else
// copied from pyport.h in CPython 3.3, missing in 2.4
const PY_LONG_LONG PY_LLONG_MAX = (1 + 2 * ((1LL << (CHAR_BIT * sizeof(PY_LONG_LONG) - 2)) - 1));
#endif
#endif
if (unlikely(x == -PY_LLONG_MAX-1))
return ((unsigned PY_LONG_LONG)PY_LLONG_MAX) + 1U;
#if defined (__STDC_VERSION__) && __STDC_VERSION__ >= 199901L
#if defined (__cplusplus) && __cplusplus >= 201103L
return (unsigned PY_LONG_LONG) std::abs(x);
#elif defined (__STDC_VERSION__) && __STDC_VERSION__ >= 199901L
return (unsigned PY_LONG_LONG) llabs(x);
#elif defined (_MSC_VER) && defined (_M_X64)
// abs() is defined for long, but 64-bits type on MSVC is long long.
// Use MS-specific _abs64 instead.
return (unsigned PY_LONG_LONG) _abs64(x);
#elif defined (__GNUC__)
// gcc or clang on 64 bit windows.
return (unsigned PY_LONG_LONG) __builtin_llabs(x);
#else
if (sizeof(PY_LONG_LONG) <= sizeof(Py_ssize_t))
return __Pyx_sst_abs(x);
return (x<0) ? (unsigned PY_LONG_LONG)-x : (unsigned PY_LONG_LONG)x;
#endif
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment