From 669f399f00f4d1546dc4cb62942986b65e3728de Mon Sep 17 00:00:00 2001 From: Shreyas Kalyan Date: Thu, 18 Jul 2024 16:21:00 -0400 Subject: [PATCH] fix some windows errors and lint --- .evergreen/init.sh | 1 + src/mc-range-encoding.c | 9 +++++++-- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/.evergreen/init.sh b/.evergreen/init.sh index 864237881..51ec07b85 100644 --- a/.evergreen/init.sh +++ b/.evergreen/init.sh @@ -222,6 +222,7 @@ run_ctest() { run_python() { pys=( + /Users/shreyaskal/dev/bin/python py python3.14 python3.13 diff --git a/src/mc-range-encoding.c b/src/mc-range-encoding.c index 5fe74fd9b..4b9a36130 100644 --- a/src/mc-range-encoding.c +++ b/src/mc-range-encoding.c @@ -166,12 +166,17 @@ bool mc_getTypeInfo64(mc_getTypeInfo64_args_t args, mc_OSTType_Int64 *out, mongo #define UINT_64_MAX 18446744073709551615ull uint64_t subtract_int64_t(int64_t max, int64_t min) { + // If the values have the same sign, then simple subtraction + // will work because we know max > min. if ((max > 0 && min > 0) || (max < 0 && min < 0)) { return (uint64_t)(max - min); } - uint64_t u_return = (uint64_t)labs(max); - u_return += (uint64_t)labs(min); + // If they are opposite signs, then we can just do a small + // abs_val addition trick to perform subtraction, since it + // is just the sum of differences between the values and 0. + uint64_t u_return = (uint64_t)llabs(max); + u_return += (uint64_t)llabs(min); return u_return; }