ladybird/Userland/Libraries/LibJS/Tests/math/integer-overflow-basic.js
Andreas Kling b2e6843055 LibJS+AK: Fix integer overflow UB on (any Int32 - -2147483648)
It wasn't safe to use addition_would_overflow(a, -b) to check if
subtraction (a - b) would overflow, since it doesn't cover this case.

I don't know why we didn't have subtraction_would_overflow(), so this
patch adds it. :^)
2024-05-18 18:11:50 +02:00

10 lines
423 B
JavaScript

test("basic integer overflow correctness", () => {
expect(2147483647 + 1).toBe(2147483648);
expect(2147483648 - 1).toBe(2147483647);
expect(0 - 2147483647).toBe(-2147483647);
expect(0 - 2147483648).toBe(-2147483648);
expect(0 - -2147483647).toBe(2147483647);
expect(0 - -2147483648).toBe(2147483648);
expect(0 + -2147483647).toBe(-2147483647);
expect(0 + -2147483648).toBe(-2147483648);
});