aboutsummaryrefslogtreecommitdiffstats
path: root/libj2_j2u_sub_ju.c
diff options
context:
space:
mode:
authorMattias Andrée <m@maandree.se>2025-12-06 10:21:36 +0100
committerMattias Andrée <m@maandree.se>2025-12-06 10:21:36 +0100
commitc28859c3e10c84fd9f81ebf88336c9b693448eeb (patch)
tree22f9804f4ba96474c23c93c021d293ba5959ccfa /libj2_j2u_sub_ju.c
parentSecond commit (diff)
downloadlibj2-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.c17
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);
}