Strange stimulation in arithmetic operation

Why is this cython function:

cimport numpy as np cimport cython def foo(np.uint32_t b): cdef np.int32_t a = 0 if ab <0: return 0 else: return 1 

returns 1, for foo (1)? I compiled similar code in C and did not observe that both operands (a, b) were translated into unsigned int.

+5
source share
1 answer

1 - the correct result; a signed operand must be converted to the corresponding unsigned type.

6.3.1.8 Normal arithmetic conversions

[...]
- Otherwise, if the operand with an unsigned integer type has a rank greater than or equal to the ranks of the type of another operand, then the operand with an integer type with a sign is converted to the type of an unsigned operand of an integer type.

+1
source

All Articles