diff options
| author | Mattias Andrée <m@maandree.se> | 2025-12-06 10:21:36 +0100 |
|---|---|---|
| committer | Mattias Andrée <m@maandree.se> | 2025-12-06 10:21:36 +0100 |
| commit | c28859c3e10c84fd9f81ebf88336c9b693448eeb (patch) | |
| tree | 22f9804f4ba96474c23c93c021d293ba5959ccfa /libj2_j2u_sub_ju.c | |
| parent | Second commit (diff) | |
| download | libj2-c28859c3e10c84fd9f81ebf88336c9b693448eeb.tar.gz libj2-c28859c3e10c84fd9f81ebf88336c9b693448eeb.tar.bz2 libj2-c28859c3e10c84fd9f81ebf88336c9b693448eeb.tar.xz | |
Add overflow and underflow prediction functions
Signed-off-by: Mattias Andrée <m@maandree.se>
Diffstat (limited to 'libj2_j2u_sub_ju.c')
| -rw-r--r-- | libj2_j2u_sub_ju.c | 17 |
1 files changed, 16 insertions, 1 deletions
diff --git a/libj2_j2u_sub_ju.c b/libj2_j2u_sub_ju.c index b2a3f47..0cd0343 100644 --- a/libj2_j2u_sub_ju.c +++ b/libj2_j2u_sub_ju.c @@ -41,6 +41,11 @@ check(uintmax_t a_high, uintmax_t a_low, uintmax_t b) EXPECT(libj2_j2u_sub_ju_overflow(&a, b) == expected_overflow); EXPECT(libj2_j2u_eq_j2u(&a, &expected)); + a = (struct libj2_j2u){.high = a_high, .low = a_low}; + EXPECT(libj2_j2u_sub_ju_overflow_p((const struct libj2_j2u *)&a, b) == expected_overflow); + EXPECT(a.high == a_high); + EXPECT(a.low == a_low); + r = (struct libj2_j2u){111, 222}; a = (struct libj2_j2u){.high = a_high, .low = a_low}; libj2_j2u_sub_ju_to_j2u(&a, b, &r); @@ -86,6 +91,11 @@ check(uintmax_t a_high, uintmax_t a_low, uintmax_t b) libj2_minus_j2u(&a); EXPECT(libj2_j2u_eq_j2u(&a, &expected)); + a = (struct libj2_j2u){.high = a_high, .low = a_low}; + EXPECT(libj2_j2u_rsub_ju_overflow_p((const struct libj2_j2u *)&a, b) == expected_roverflow); + EXPECT(a.high == a_high); + EXPECT(a.low == a_low); + r = (struct libj2_j2u){111, 222}; a = (struct libj2_j2u){.high = a_high, .low = a_low}; EXPECT(libj2_ju_sub_j2u_to_j2u_overflow(b, &a, &r) == expected_roverflow); @@ -97,7 +107,12 @@ check(uintmax_t a_high, uintmax_t a_low, uintmax_t b) a = (struct libj2_j2u){.high = a_high, .low = a_low}; EXPECT(libj2_ju_sub_j2u_to_j2u_overflow(b, &a, &a) == expected_roverflow); libj2_minus_j2u(&a); - EXPECT(libj2_j2u_eq_j2u(&a, &expected)); + EXPECT(libj2_j2u_eq_j2u(&a, &expected));; + + a = (struct libj2_j2u){.high = a_high, .low = a_low}; + EXPECT(libj2_ju_sub_j2u_overflow_p(b, (const struct libj2_j2u *)&a) == expected_roverflow); + EXPECT(a.high == a_high); + EXPECT(a.low == a_low); } |
