Bugfix: Off-by-one bug in subtracting UINT. Fixes #1557

This commit is contained in:
rjo12
2023-05-11 22:49:23 +09:30
committed by Dennis Guse
parent d6cf8ba90e
commit 5b0e7e5065
2 changed files with 36 additions and 6 deletions
@@ -14,6 +14,7 @@ public class UintUtils {
* @return diff
*/
public static long diff(long a, long b, final long UINT_MAX) {
if (a < 0 || b < 0) {
throw new RuntimeException("a or b cannot be less than zero.");
}
@@ -25,6 +26,6 @@ public class UintUtils {
return a - b;
}
return (UINT_MAX - b) + a;
return (UINT_MAX + 1 - b) + a;
}
}