aboutsummaryrefslogtreecommitdiffstats
path: root/libj2_j2u_sub_j2u.3
diff options
context:
space:
mode:
authorMattias Andrée <m@maandree.se>2026-02-12 13:45:48 +0100
committerMattias Andrée <m@maandree.se>2026-02-12 13:45:48 +0100
commit8b1e9c4dd1fd12e3b85750a5c0044b54ced216c7 (patch)
treefbf6b79555576e9005eeb84c0b605985a27fa714 /libj2_j2u_sub_j2u.3
parentlibj2_j2i_divmod_j2i_to_j2i: test overflow edge case (diff)
downloadlibj2-ac0dd6c546feaec1dec667f01616a2db709bedaf.tar.gz
libj2-ac0dd6c546feaec1dec667f01616a2db709bedaf.tar.bz2
libj2-ac0dd6c546feaec1dec667f01616a2db709bedaf.tar.xz
Add subtraction and addition with carry/borrow and add abs_diff1.2
Signed-off-by: Mattias Andrée <m@maandree.se>
Diffstat (limited to 'libj2_j2u_sub_j2u.3')
-rw-r--r--libj2_j2u_sub_j2u.326
1 files changed, 26 insertions, 0 deletions
diff --git a/libj2_j2u_sub_j2u.3 b/libj2_j2u_sub_j2u.3
index cbadfd2..4ed6863 100644
--- a/libj2_j2u_sub_j2u.3
+++ b/libj2_j2u_sub_j2u.3
@@ -25,6 +25,9 @@ int \fBlibj2_j2u_sub_ju_overflow_p\fP(const struct libj2_j2u *\fIa\fP, uintmax_t
int \fBlibj2_ju_sub_j2u_overflow_p\fP(uintmax_t \fIa\fP, const struct libj2_j2u *\fIb\fP);
int \fBlibj2_ju_sub_ju_overflow_p\fP(uintmax_t \fIa\fP, uintmax_t \fIb\fP);
+void \fBlibj2_j2u_sub_j2u_borrow\fP(struct libj2_j2u *\fIa\fP, const struct libj2_j2u *\fIb\fP, int *\fIc\fP);
+void \fBlibj2_j2u_sub_j2u_to_j2u_borrow\fP(const struct libj2_j2u *\fIa\fP, const struct libj2_j2u *\fIb\fP, struct libj2_j2u *\fIr\fP, int *\fIc\fP);
+
void \fBlibj2_j2u_rsub_j2u\fP(struct libj2_j2u *\fIb\fP, const struct libj2_j2u *\fIa\fP);
void \fBlibj2_j2u_rsub_ju\fP(struct libj2_j2u *\fIb\fP, uintmax_t \fIa\fP);
@@ -34,6 +37,8 @@ int \fBlibj2_j2u_rsub_ju_overflow\fP(struct libj2_j2u *\fIb\fP, uintmax_t \fIa\f
int \fBlibj2_j2u_rsub_j2u_overflow_p\fP(const struct libj2_j2u *\fIb\fP, const struct libj2_j2u *\fIa\fP);
int \fBlibj2_j2u_rsub_ju_overflow_p\fP(const struct libj2_j2u *\fIb\fP, uintmax_t \fIa\fP);
+void \fBlibj2_j2u_rsub_j2u_borrow\fP(struct libj2_j2u *\fIb\fP, const struct libj2_j2u *\fIa\fP, int *\fIc\fP);
+
void \fBlibj2_j2u_sat_sub_j2u\fP(struct libj2_j2u *\fIa\fP, const struct libj2_j2u *\fIb\fP);
void \fBlibj2_j2u_sat_sub_j2u_to_j2u\fP(const struct libj2_j2u *\fIa\fP, const struct libj2_j2u *\fIb\fP, struct libj2_j2u *\fIr\fP);
void \fBlibj2_j2u_sat_sub_ju\fP(struct libj2_j2u *\fIa\fP, uintmax_t \fIb\fP);
@@ -88,6 +93,18 @@ with word
.B overflow
in their name), detect arithmetic overflow.
.PP
+The
+.BR libj2_j2u_sub_j2u_borrow (),
+.BR libj2_j2u_sub_j2u_to_j2u_borrow (),
+and
+.BR libj2_j2u_rsub_j2u_borrow ()
+functions subtract
+.IR *c ,
+which must be 1 or 0,
+from the result, and sets
+.I *c
+to 1 on overflow, and 0 otherwise.
+.PP
The result is truncated to the least significant
bits, as many as can be stored, in case of overflow;
that is, modular arithmetics is used. However, the
@@ -149,6 +166,14 @@ and
.BR libj2_j2u_sat_rsub_ju ()
functions were added in version 1.1 of
.BR libj2 .
+.PP
+The
+.BR libj2_j2u_sub_j2u_borrow (),
+.BR libj2_j2u_sub_j2u_to_j2u_borrow (),
+and
+.BR libj2_j2u_rsub_j2u_borrow ()
+functions were added in version 1.2 of
+.BR libj2 .
.SH NOTES
The return value 1 represents negative
@@ -157,6 +182,7 @@ overflow. Positive overflow is impossible.
.SH SEE ALSO
.BR libj2 (7),
.BR libj2_j2i_sub_j2i (3),
+.BR libj2_j2u_abs_diff_j2u (3),
.BR libj2_j2i_add_j2i (3),
.BR libj2_j2i_mul_j2i (3),
.BR libj2_j2i_divmod_j2i (3)