static uint32_t cc_calc_add_64(int64_t a1, int64_t a2, int64_t ar)
{
- if ((a1 > 0 && a2 > 0 && ar < 0) || (a1 < 0 && a2 < 0 && ar > 0)) {
+ if ((a1 > 0 && a2 > 0 && ar < 0) || (a1 < 0 && a2 < 0 && ar >= 0)) {
Intuitively, I'd have checked for any overflow/underflow by comparing
with one of the input variables:
a) Both numbers are positive
Adding to positive numbers has to result in something that's bigger than
the input parameters.
"a1 > 0 && a2 > 0 && ar < a1"
b) Both numbers are negative
Adding to negative numbers has to result in something that's smaller
than the input parameters.
"a1 < 0 && a2 < 0 && ar > a1"