Commit d0da3179 authored by Stefan Behnel's avatar Stefan Behnel

merge 0.18.x branch back into master

parents 81d3d105 0ed536d0
...@@ -19,16 +19,20 @@ proto = """ ...@@ -19,16 +19,20 @@ proto = """
abs_int_utility_code = UtilityCode( abs_int_utility_code = UtilityCode(
proto = ''' proto = '''
#if HAVE_LONG_LONG && defined (__STDC_VERSION__) && __STDC_VERSION__ >= 199901L static CYTHON_INLINE unsigned int __Pyx_abs_int(int x) {
#define __Pyx_abs_int(x) \ if (unlikely(x == -INT_MAX-1))
((sizeof(x) <= sizeof(int)) ? ((unsigned int)abs(x)) : \ return ((unsigned int)INT_MAX) + 1U;
((sizeof(x) <= sizeof(long)) ? ((unsigned long)labs(x)) : \ return (unsigned int) abs(x);
((unsigned PY_LONG_LONG)llabs(x)))) }
#else ''')
#define __Pyx_abs_int(x) \
((sizeof(x) <= sizeof(int)) ? ((unsigned int)abs(x)) : ((unsigned long)labs(x))) abs_long_utility_code = UtilityCode(
#endif proto = '''
#define __Pyx_abs_long(x) __Pyx_abs_int(x) static CYTHON_INLINE unsigned long __Pyx_abs_long(long x) {
if (unlikely(x == -LONG_MAX-1))
return ((unsigned long)LONG_MAX) + 1U;
return (unsigned long) labs(x);
}
''') ''')
iter_next_utility_code = UtilityCode.load_cached("IterNext", "ObjectHandling.c") iter_next_utility_code = UtilityCode.load_cached("IterNext", "ObjectHandling.c")
...@@ -201,7 +205,7 @@ builtin_function_table = [ ...@@ -201,7 +205,7 @@ builtin_function_table = [
], ],
is_strict_signature = True)), is_strict_signature = True)),
BuiltinFunction('abs', None, None, "__Pyx_abs_long", BuiltinFunction('abs', None, None, "__Pyx_abs_long",
utility_code = abs_int_utility_code, utility_code = abs_long_utility_code,
func_type = PyrexTypes.CFuncType( func_type = PyrexTypes.CFuncType(
PyrexTypes.c_ulong_type, [ PyrexTypes.c_ulong_type, [
PyrexTypes.CFuncTypeArg("arg", PyrexTypes.c_long_type, None) PyrexTypes.CFuncTypeArg("arg", PyrexTypes.c_long_type, None)
......
...@@ -8438,8 +8438,10 @@ class PowNode(NumBinopNode): ...@@ -8438,8 +8438,10 @@ class PowNode(NumBinopNode):
else: else:
self.pow_func = "__Pyx_pow_%s" % self.type.declaration_code('').replace(' ', '_') self.pow_func = "__Pyx_pow_%s" % self.type.declaration_code('').replace(' ', '_')
env.use_utility_code( env.use_utility_code(
int_pow_utility_code.specialize(func_name=self.pow_func, int_pow_utility_code.specialize(
type=self.type.declaration_code(''))) func_name=self.pow_func,
type=self.type.declaration_code(''),
signed=self.type.signed and 1 or 0))
def calculate_result_code(self): def calculate_result_code(self):
# Work around MSVC overloading ambiguity. # Work around MSVC overloading ambiguity.
...@@ -10055,7 +10057,9 @@ static CYTHON_INLINE %(type)s %(func_name)s(%(type)s b, %(type)s e) { ...@@ -10055,7 +10057,9 @@ static CYTHON_INLINE %(type)s %(func_name)s(%(type)s b, %(type)s e) {
case 0: case 0:
return 1; return 1;
} }
#if %(signed)s
if (unlikely(e<0)) return 0; if (unlikely(e<0)) return 0;
#endif
t = 1; t = 1;
while (likely(e)) { while (likely(e)) {
t *= (b * (e&1)) | ((~e)&1); /* 1 or b */ t *= (b * (e&1)) | ((~e)&1); /* 1 or b */
......
...@@ -38,11 +38,21 @@ def int_abs(int a): ...@@ -38,11 +38,21 @@ def int_abs(int a):
True True
>>> int_abs(-5.1) == 5 >>> int_abs(-5.1) == 5
True True
>>> long_abs(-max_int-1) > 0 >>> int_abs(-max_int-1) > 0
True True
>>> int_abs(-max_int-1) == abs(-max_int-1) >>> int_abs(-max_int-1) == abs(-max_int-1) or (max_int, int_abs(-max_int-1), abs(-max_int-1))
True True
>>> int_abs(max_int) == abs(max_int) >>> int_abs(max_int) == abs(max_int) or (max_int, int_abs(max_int), abs(max_int))
True
"""
return abs(a)
@cython.test_assert_path_exists("//ReturnStatNode//NameNode[@entry.name = 'abs']")
@cython.test_fail_if_path_exists("//ReturnStatNode//NameNode[@entry.cname = '__Pyx_abs_int']",
"//ReturnStatNode//NameNode[@entry.cname = '__Pyx_abs_long']")
def uint_abs(unsigned int a):
"""
>>> uint_abs(max_int) == abs(max_int) or (max_int, uint_abs(max_int), abs(max_int))
True True
""" """
return abs(a) return abs(a)
...@@ -57,9 +67,19 @@ def long_abs(long a): ...@@ -57,9 +67,19 @@ def long_abs(long a):
True True
>>> long_abs(-max_long-1) > 0 >>> long_abs(-max_long-1) > 0
True True
>>> long_abs(-max_long-1) == abs(-max_long-1) >>> long_abs(-max_long-1) == abs(-max_long-1) or (max_long, long_abs(-max_long-1), abs(-max_long-1))
True True
>>> long_abs(max_long) == abs(max_long) >>> long_abs(max_long) == abs(max_long) or (max_long, long_abs(max_long), abs(max_long))
True
"""
return abs(a)
@cython.test_assert_path_exists("//ReturnStatNode//NameNode[@entry.name = 'abs']")
@cython.test_fail_if_path_exists("//ReturnStatNode//NameNode[@entry.cname = '__Pyx_abs_int']",
"//ReturnStatNode//NameNode[@entry.cname = '__Pyx_abs_long']")
def ulong_abs(unsigned long a):
"""
>>> ulong_abs(max_long) == abs(max_long) or (max_int, ulong_abs(max_long), abs(max_long))
True True
""" """
return abs(a) return abs(a)
...@@ -70,9 +90,9 @@ def long_long_abs(long long a): ...@@ -70,9 +90,9 @@ def long_long_abs(long long a):
True True
>>> long_long_abs(-max_long_long-1) > 0 >>> long_long_abs(-max_long_long-1) > 0
True True
>>> long_long_abs(-max_long_long-1) == abs(-max_long_long-1) >>> long_long_abs(-max_long_long-1) == abs(-max_long_long-1) or (max_long_long, long_long_abs(-max_long_long-1), abs(-max_long_long-1))
True True
>>> long_long_abs(max_long_long) == abs(max_long_long) >>> long_long_abs(max_long_long) == abs(max_long_long) or (max_long_long, long_long_abs(max_long_long), abs(max_long_long))
True True
""" """
return abs(a) return abs(a)
......
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