Check if addition resulted in a carry When adding two unsigned numbers a + b = sum, carry occurs iff sum < a (or sum < b) This works because: - No carry: sum = a + b, so sum >= a and sum >= b - Carry: sum = a + b - 2^64, so sum < a and sum < b
(long a, long sum)
| 666 | * - Carry: sum = a + b - 2^64, so sum < a and sum < b |
| 667 | */ |
| 668 | public static boolean hasCarry(long a, long sum) { |
| 669 | // We can check against either a or b - both work |
| 670 | // Using a for consistency, b parameter kept for clarity |
| 671 | return (sum + Long.MIN_VALUE) < (a + Long.MIN_VALUE); |
| 672 | } |
| 673 | |
| 674 | /** |
| 675 | * Returns whether the Decimal256 is null or not. |
no outgoing calls
no test coverage detected