From e0d1d5461e213fc7df0f33a57cf1571b11125bab Mon Sep 17 00:00:00 2001 From: Mattias Andrée Date: Sun, 28 Dec 2025 10:30:43 +0100 Subject: Fix typo MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Mattias Andrée --- Makefile | 6 +- README | 6 +- libj2.7 | 6 +- libj2.h | 6 +- libj2/mixed-comparison.h | 820 ++++++++++++++++++++++++++++++++++++++++++ libj2/mixed-comparsion.h | 820 ------------------------------------------ libj2/signed-comparison.h | 858 ++++++++++++++++++++++++++++++++++++++++++++ libj2/signed-comparsion.h | 858 -------------------------------------------- libj2/unsigned-comparison.h | 855 +++++++++++++++++++++++++++++++++++++++++++ libj2/unsigned-comparsion.h | 855 ------------------------------------------- 10 files changed, 2545 insertions(+), 2545 deletions(-) create mode 100644 libj2/mixed-comparison.h delete mode 100644 libj2/mixed-comparsion.h create mode 100644 libj2/signed-comparison.h delete mode 100644 libj2/signed-comparsion.h create mode 100644 libj2/unsigned-comparison.h delete mode 100644 libj2/unsigned-comparsion.h diff --git a/Makefile b/Makefile index 61ce8d9..9cef96d 100644 --- a/Makefile +++ b/Makefile @@ -512,9 +512,9 @@ SUBHDR =\ libj2/constants.h\ libj2/signum.h\ libj2/constructors.h\ - libj2/unsigned-comparsion.h\ - libj2/signed-comparsion.h\ - libj2/mixed-comparsion.h\ + libj2/unsigned-comparison.h\ + libj2/signed-comparison.h\ + libj2/mixed-comparison.h\ libj2/bitwise-logic.h\ libj2/sign-shifting.h\ libj2/bit-shifting.h\ diff --git a/README b/README index c55ef0a..7bb64e0 100644 --- a/README +++ b/README @@ -48,13 +48,13 @@ DESCRIPTION libj2_minus_abs_j2i(3), libj2_minus_abs_j2i_to_j2i(3) Calculate the additive inverse of the absolute value. - libj2 provides the following comparsion functions: + libj2 provides the following comparison functions: libj2_j2i_cmp_j2i(3), libj2_j2i_cmp_ji(3), libj2_ji_cmp_j2i(3), libj2_j2i_cmp_j2u(3), libj2_j2i_cmp_ju(3), libj2_ji_cmp_j2u(3), libj2_j2u_cmp_j2i(3), libj2_j2u_cmp_ji(3), libj2_ju_cmp_j2i(3), libj2_j2u_cmp_j2u(3), libj2_j2u_cmp_ju(3), libj2_ju_cmp_j2u(3) - Perform three-way comparision. + Perform three-way comparison. libj2_j2i_eq_j2i(3), libj2_j2i_eq_ji(3), libj2_ji_eq_j2i(3), libj2_j2i_eq_j2u(3), libj2_j2i_eq_ju(3), libj2_ji_eq_j2u(3), @@ -110,7 +110,7 @@ DESCRIPTION Check whether a value is negative. libj2_sgn_j2i(3), libj2_sgn_j2u(3) - Perform three-way comparision against the value zero (get the + Perform three-way comparison against the value zero (get the signum of a value). libj2_j2i_max_j2i(3), libj2_j2i_max_j2i_to_j2i(3), diff --git a/libj2.7 b/libj2.7 index eb793f7..8a7562f 100644 --- a/libj2.7 +++ b/libj2.7 @@ -91,7 +91,7 @@ Calculate the additive inverse. Calculate the additive inverse of the absolute value. .PP .B libj2 -provides the following comparsion functions: +provides the following comparison functions: .TP .BR libj2_j2i_cmp_j2i (3), .TQ @@ -116,7 +116,7 @@ provides the following comparsion functions: .BR libj2_j2u_cmp_ju (3), .TQ .BR libj2_ju_cmp_j2u (3) -Perform three-way comparision. +Perform three-way comparison. .TP .BR libj2_j2i_eq_j2i (3), .TQ @@ -296,7 +296,7 @@ Check whether a value is negative. .BR libj2_sgn_j2i (3), .TQ .BR libj2_sgn_j2u (3) -Perform three-way comparision against the value zero (get the +Perform three-way comparison against the value zero (get the signum of a value). .TP .BR libj2_j2i_max_j2i (3), diff --git a/libj2.h b/libj2.h index 7e389a6..7eb90d7 100644 --- a/libj2.h +++ b/libj2.h @@ -155,9 +155,9 @@ enum libj2_overflow { #include "libj2/constants.h" #include "libj2/signum.h" #include "libj2/constructors.h" -#include "libj2/unsigned-comparsion.h" -#include "libj2/signed-comparsion.h" -#include "libj2/mixed-comparsion.h" +#include "libj2/unsigned-comparison.h" +#include "libj2/signed-comparison.h" +#include "libj2/mixed-comparison.h" #include "libj2/bitwise-logic.h" #include "libj2/sign-shifting.h" #include "libj2/bit-shifting.h" diff --git a/libj2/mixed-comparison.h b/libj2/mixed-comparison.h new file mode 100644 index 0000000..dedf18d --- /dev/null +++ b/libj2/mixed-comparison.h @@ -0,0 +1,820 @@ +/* See LICENSE file for copyright and license details. */ +#ifndef LIBJ2_H +# error Do not include this header directly, include instead +#endif + + +/** + * Check whether a signed double-max precision integer + * is less than an unsigned double-max precision integer + * + * `libj2_j2i_lt_j2u(a, b)` implements `*a < *b` + * + * @param a The left-hand value + * @param b The right-hand value + * @return 1 if `*a` is less than `*b`, 0 otherwise + * + * @since 1.1 + */ +LIBJ2_PURE_ inline int +libj2_j2i_lt_j2u(const struct libj2_j2i *a, const struct libj2_j2u *b) +{ + return libj2_j2i_is_negative(a) ? 1 : libj2_j2u_lt_j2u((const void *)a, b); +} + + +/** + * Check whether a signed double-max precision integer is less + * than or equal to an unsigned double-max precision integer + * + * `libj2_j2i_le_j2u(a, b)` implements `*a <= *b` + * + * @param a The left-hand value + * @param b The right-hand value + * @return 1 if `*a` is less than or equal to `*b`, 0 otherwise + * + * @since 1.1 + */ +LIBJ2_PURE_ inline int +libj2_j2i_le_j2u(const struct libj2_j2i *a, const struct libj2_j2u *b) +{ + return libj2_j2i_is_negative(a) ? 1 : libj2_j2u_le_j2u((const void *)a, b); +} + + +/** + * Check whether a signed double-max precision integer + * is greater than an unsigned double-max precision integer + * + * `libj2_j2i_gt_j2u(a, b)` implements `*a > *b` + * + * @param a The left-hand value + * @param b The right-hand value + * @return 1 if `*a` is greater than `*b`, 0 otherwise + * + * @since 1.1 + */ +LIBJ2_PURE_ inline int +libj2_j2i_gt_j2u(const struct libj2_j2i *a, const struct libj2_j2u *b) +{ + return libj2_j2i_is_negative(a) ? 0 : libj2_j2u_gt_j2u((const void *)a, b); +} + + +/** + * Check whether a signed double-max precision integer is greater + * than or equal to an unsigned double-max precision integer + * + * `libj2_j2i_ge_j2u(a, b)` implements `*a >= *b` + * + * @param a The left-hand value + * @param b The right-hand value + * @return 1 if `*a` is greater than or equal to `*b`, 0 otherwise + * + * @since 1.1 + */ +LIBJ2_PURE_ inline int +libj2_j2i_ge_j2u(const struct libj2_j2i *a, const struct libj2_j2u *b) +{ + return libj2_j2i_is_negative(a) ? 0 : libj2_j2u_ge_j2u((const void *)a, b); +} + + +/** + * Check whether a signed double-max precision integer + * is equal to an unsigned double-max precision integer + * + * `libj2_j2i_eq_j2u(a, b)` implements `*a == *b` + * + * @param a The left-hand value + * @param b The right-hand value + * @return 1 if `*a` is equal to `*b`, 0 otherwise + * + * @since 1.1 + */ +LIBJ2_PURE_ inline int +libj2_j2i_eq_j2u(const struct libj2_j2i *a, const struct libj2_j2u *b) +{ + return libj2_j2i_is_negative(a) ? 0 : libj2_j2u_eq_j2u((const void *)a, b); +} + + +/** + * Check whether a signed double-max precision integer + * is not equal to an unsigned double-max precision integer + * + * `libj2_j2i_ne_j2u(a, b)` implements `*a != *b` + * + * @param a The left-hand value + * @param b The right-hand value + * @return 1 if `*a` is not equal to `*b`, 0 otherwise + * + * @since 1.1 + */ +LIBJ2_PURE_ inline int +libj2_j2i_ne_j2u(const struct libj2_j2i *a, const struct libj2_j2u *b) +{ + return libj2_j2i_is_negative(a) ? 1 : libj2_j2u_ne_j2u((const void *)a, b); +} + + +/** + * Compare a signed double-max precision integer + * against an unsigned double-max precision integer + * + * `libj2_j2i_cmp_j2u(a, b)` implements `*a < *b ? -1 : *a > *b ? +1 : 0`, + * or equivalently, the signum of `*a - *b` where the signum is 0 for 0 + * + * @param a The left-hand value + * @param b The right-hand value + * @return -1 if `*a` is less than `*b`, + * +1 if `*a` is greater than `*b`, + * 0 if `*a` is equal to `*b` + * + * @since 1.1 + */ +LIBJ2_PURE_ inline int +libj2_j2i_cmp_j2u(const struct libj2_j2i *a, const struct libj2_j2u *b) +{ + return libj2_j2i_is_negative(a) ? -1 : libj2_j2u_cmp_j2u((const void *)a, b); +} + + +/** + * Check whether an unsigned double-max precision integer + * is less than a signed double-max precision integer + * + * `libj2_j2u_lt_j2i(a, b)` implements `*a < *b` + * + * @param a The left-hand value + * @param b The right-hand value + * @return 1 if `*a` is less than `*b`, 0 otherwise + * + * @since 1.1 + */ +LIBJ2_PURE_ inline int +libj2_j2u_lt_j2i(const struct libj2_j2u *a, const struct libj2_j2i *b) +{ + return libj2_j2i_is_negative(b) ? 0 : libj2_j2u_lt_j2u(a, (const void *)b); +} + + +/** + * Check whether an unsigned double-max precision integer is less + * than or equal to a signed double-max precision integer + * + * `libj2_j2u_le_j2i(a, b)` implements `*a <= *b` + * + * @param a The left-hand value + * @param b The right-hand value + * @return 1 if `*a` is less than or equal to `*b`, 0 otherwise + * + * @since 1.1 + */ +LIBJ2_PURE_ inline int +libj2_j2u_le_j2i(const struct libj2_j2u *a, const struct libj2_j2i *b) +{ + return libj2_j2i_is_negative(b) ? 0 : libj2_j2u_le_j2u(a, (const void *)b); +} + + +/** + * Check whether an unsigned double-max precision integer + * is greater than a signed double-max precision integer + * + * `libj2_j2u_gt_j2i(a, b)` implements `*a > *b` + * + * @param a The left-hand value + * @param b The right-hand value + * @return 1 if `*a` is greater than `*b`, 0 otherwise + * + * @since 1.1 + */ +LIBJ2_PURE_ inline int +libj2_j2u_gt_j2i(const struct libj2_j2u *a, const struct libj2_j2i *b) +{ + return libj2_j2i_is_negative(b) ? 1 : libj2_j2u_gt_j2u(a, (const void *)b); +} + + +/** + * Check whether an unsigned double-max precision integer is + * greater than or equal to a signed double-max precision integer + * + * `libj2_j2u_ge_j2i(a, b)` implements `*a >= *b` + * + * @param a The left-hand value + * @param b The right-hand value + * @return 1 if `*a` is greater than or equal to `*b`, 0 otherwise + * + * @since 1.1 + */ +LIBJ2_PURE_ inline int +libj2_j2u_ge_j2i(const struct libj2_j2u *a, const struct libj2_j2i *b) +{ + return libj2_j2i_is_negative(b) ? 1 : libj2_j2u_ge_j2u(a, (const void *)b); +} + + +/** + * Check whether an unsigned double-max precision integer + * is equal to a signed double-max precision integer + * + * `libj2_j2u_eq_j2i(a, b)` implements `*a == *b` + * + * @param a The left-hand value + * @param b The right-hand value + * @return 1 if `*a` is equal to `*b`, 0 otherwise + * + * @since 1.1 + */ +LIBJ2_PURE_ inline int +libj2_j2u_eq_j2i(const struct libj2_j2u *a, const struct libj2_j2i *b) +{ + return libj2_j2i_is_negative(b) ? 0 : libj2_j2u_eq_j2u(a, (const void *)b); +} + + +/** + * Check whether an unsigned double-max precision integer + * is not equal to a signed double-max precision integer + * + * `libj2_j2u_ne_j2i(a, b)` implements `*a != *b` + * + * @param a The left-hand value + * @param b The right-hand value + * @return 1 if `*a` is not equal to `*b`, 0 otherwise + * + * @since 1.1 + */ +LIBJ2_PURE_ inline int +libj2_j2u_ne_j2i(const struct libj2_j2u *a, const struct libj2_j2i *b) +{ + return libj2_j2i_is_negative(b) ? 1 : libj2_j2u_ne_j2u(a, (const void *)b); +} + + +/** + * Compare an unsigned double-max precision integer + * against a signed double-max precision integer + * + * `libj2_j2u_cmp_j2i(a, b)` implements `*a < *b ? -1 : *a > *b ? +1 : 0`, + * or equivalently, the signum of `*a - *b` where the signum is 0 for 0 + * + * @param a The left-hand value + * @param b The right-hand value + * @return -1 if `*a` is less than `*b`, + * +1 if `*a` is greater than `*b`, + * 0 if `*a` is equal to `*b` + * + * @since 1.1 + */ +LIBJ2_PURE_ inline int +libj2_j2u_cmp_j2i(const struct libj2_j2u *a, const struct libj2_j2i *b) +{ + return libj2_j2i_is_negative(b) ? +1 : libj2_j2u_cmp_j2u(a, (const void *)b); +} + + +/** + * Check whether a signed max precision integer + * is less than an unsigned double-max precision integer + * + * `libj2_ji_lt_j2u(a, b)` implements `*a < *b` + * + * @param a The left-hand value + * @param b The right-hand value + * @return 1 if `*a` is less than `*b`, 0 otherwise + * + * @since 1.1 + */ +LIBJ2_PURE_ inline int +libj2_ji_lt_j2u(intmax_t a, const struct libj2_j2u *b) +{ + return a < 0 ? 1 : libj2_ju_lt_j2u((uintmax_t)a, b); +} + + +/** + * Check whether a signed max precision integer is less + * than or equal to an unsigned double-max precision integer + * + * `libj2_ji_le_j2u(a, b)` implements `*a <= *b` + * + * @param a The left-hand value + * @param b The right-hand value + * @return 1 if `*a` is less than or equal to `*b`, 0 otherwise + * + * @since 1.1 + */ +LIBJ2_PURE_ inline int +libj2_ji_le_j2u(intmax_t a, const struct libj2_j2u *b) +{ + return a < 0 ? 1 : libj2_ju_le_j2u((uintmax_t)a, b); +} + + +/** + * Check whether a signed max precision integer + * is greater than an unsigned double-max precision integer + * + * `libj2_ji_gt_j2u(a, b)` implements `*a > *b` + * + * @param a The left-hand value + * @param b The right-hand value + * @return 1 if `*a` is greater than `*b`, 0 otherwise + * + * @since 1.1 + */ +LIBJ2_PURE_ inline int +libj2_ji_gt_j2u(intmax_t a, const struct libj2_j2u *b) +{ + return a < 0 ? 0 : libj2_ju_gt_j2u((uintmax_t)a, b); +} + + +/** + * Check whether a signed max precision integer is greater + * than or equal to an unsigned double-max precision integer + * + * `libj2_ji_ge_j2u(a, b)` implements `*a >= *b` + * + * @param a The left-hand value + * @param b The right-hand value + * @return 1 if `*a` is greater than or equal to `*b`, 0 otherwise + * + * @since 1.1 + */ +LIBJ2_PURE_ inline int +libj2_ji_ge_j2u(intmax_t a, const struct libj2_j2u *b) +{ + return a < 0 ? 0 : libj2_ju_ge_j2u((uintmax_t)a, b); +} + + +/** + * Check whether a signed max precision integer + * is equal to an unsigned double-max precision integer + * + * `libj2_ji_eq_j2u(a, b)` implements `*a == *b` + * + * @param a The left-hand value + * @param b The right-hand value + * @return 1 if `*a` is equal to `*b`, 0 otherwise + * + * @since 1.1 + */ +LIBJ2_PURE_ inline int +libj2_ji_eq_j2u(intmax_t a, const struct libj2_j2u *b) +{ + return a < 0 ? 0 : libj2_ju_eq_j2u((uintmax_t)a, b); +} + + +/** + * Check whether a signed max precision integer + * is not equal to an unsigned double-max precision integer + * + * `libj2_ji_ne_j2u(a, b)` implements `*a != *b` + * + * @param a The left-hand value + * @param b The right-hand value + * @return 1 if `*a` is not equal to `*b`, 0 otherwise + * + * @since 1.1 + */ +LIBJ2_PURE_ inline int +libj2_ji_ne_j2u(intmax_t a, const struct libj2_j2u *b) +{ + return a < 0 ? 1 : libj2_ju_ne_j2u((uintmax_t)a, b); +} + + +/** + * Compare a signed max precision integer + * against an unsigned double-max precision integer + * + * `libj2_ji_cmp_j2u(a, b)` implements `*a < *b ? -1 : *a > *b ? +1 : 0`, + * or equivalently, the signum of `*a - *b` where the signum is 0 for 0 + * + * @param a The left-hand value + * @param b The right-hand value + * @return -1 if `*a` is less than `*b`, + * +1 if `*a` is greater than `*b`, + * 0 if `*a` is equal to `*b` + * + * @since 1.1 + */ +LIBJ2_PURE_ inline int +libj2_ji_cmp_j2u(intmax_t a, const struct libj2_j2u *b) +{ + return a < 0 ? -1 : libj2_ju_cmp_j2u((uintmax_t)a, b); +} + + +/** + * Check whether an unsigned double-max precision integer + * is less than a signed max precision integer + * + * `libj2_ju_lt_j2i(a, b)` implements `*a < *b` + * + * @param a The left-hand value + * @param b The right-hand value + * @return 1 if `*a` is less than `*b`, 0 otherwise + * + * @since 1.1 + */ +LIBJ2_PURE_ inline int +libj2_ju_lt_j2i(uintmax_t a, const struct libj2_j2i *b) +{ + return libj2_j2i_is_negative(b) ? 0 : libj2_ju_lt_j2u(a, (const void *)b); +} + + +/** + * Check whether an unsigned double-max precision integer + * is less than or equal to a signed max precision integer + * + * `libj2_ju_le_j2i(a, b)` implements `*a <= *b` + * + * @param a The left-hand value + * @param b The right-hand value + * @return 1 if `*a` is less than or equal to `*b`, 0 otherwise + * + * @since 1.1 + */ +LIBJ2_PURE_ inline int +libj2_ju_le_j2i(uintmax_t a, const struct libj2_j2i *b) +{ + return libj2_j2i_is_negative(b) ? 0 : libj2_ju_le_j2u(a, (const void *)b); +} + + +/** + * Check whether an unsigned double-max precision integer + * is greater than a signed max precision integer + * + * `libj2_ju_gt_j2i(a, b)` implements `*a > *b` + * + * @param a The left-hand value + * @param b The right-hand value + * @return 1 if `*a` is greater than `*b`, 0 otherwise + * + * @since 1.1 + */ +LIBJ2_PURE_ inline int +libj2_ju_gt_j2i(uintmax_t a, const struct libj2_j2i *b) +{ + return libj2_j2i_is_negative(b) ? 1 : libj2_ju_gt_j2u(a, (const void *)b); +} + + +/** + * Check whether an unsigned double-max precision integer is + * greater than or equal to a signed max precision integer + * + * `libj2_ju_ge_j2i(a, b)` implements `*a >= *b` + * + * @param a The left-hand value + * @param b The right-hand value + * @return 1 if `*a` is greater than or equal to `*b`, 0 otherwise + * + * @since 1.1 + */ +LIBJ2_PURE_ inline int +libj2_ju_ge_j2i(uintmax_t a, const struct libj2_j2i *b) +{ + return libj2_j2i_is_negative(b) ? 1 : libj2_ju_ge_j2u(a, (const void *)b); +} + + +/** + * Check whether an unsigned double-max precision integer + * is equal to a signed max precision integer + * + * `libj2_ju_eq_j2i(a, b)` implements `*a == *b` + * + * @param a The left-hand value + * @param b The right-hand value + * @return 1 if `*a` is equal to `*b`, 0 otherwise + * + * @since 1.1 + */ +LIBJ2_PURE_ inline int +libj2_ju_eq_j2i(uintmax_t a, const struct libj2_j2i *b) +{ + return libj2_j2i_is_negative(b) ? 0 : libj2_ju_eq_j2u(a, (const void *)b); +} + + +/** + * Check whether an unsigned double-max precision integer + * is not equal to a signed max precision integer + * + * `libj2_ju_ne_j2i(a, b)` implements `*a != *b` + * + * @param a The left-hand value + * @param b The right-hand value + * @return 1 if `*a` is not equal to `*b`, 0 otherwise + * + * @since 1.1 + */ +LIBJ2_PURE_ inline int +libj2_ju_ne_j2i(uintmax_t a, const struct libj2_j2i *b) +{ + return libj2_j2i_is_negative(b) ? 1 : libj2_ju_ne_j2u(a, (const void *)b); +} + + +/** + * Compare an unsigned double-max precision integer + * against a signed max precision integer + * + * `libj2_ju_cmp_j2i(a, b)` implements `*a < *b ? -1 : *a > *b ? +1 : 0`, + * or equivalently, the signum of `*a - *b` where the signum is 0 for 0 + * + * @param a The left-hand value + * @param b The right-hand value + * @return -1 if `*a` is less than `*b`, + * +1 if `*a` is greater than `*b`, + * 0 if `*a` is equal to `*b` + * + * @since 1.1 + */ +LIBJ2_PURE_ inline int +libj2_ju_cmp_j2i(uintmax_t a, const struct libj2_j2i *b) +{ + return libj2_j2i_is_negative(b) ? +1 : libj2_ju_cmp_j2u(a, (const void *)b); +} + + +/** + * Check whether a signed double-max precision integer + * is less than an unsigned max precision integer + * + * `libj2_j2i_lt_ju(a, b)` implements `*a < *b` + * + * @param a The left-hand value + * @param b The right-hand value + * @return 1 if `*a` is less than `*b`, 0 otherwise + * + * @since 1.1 + */ +LIBJ2_PURE_ inline int +libj2_j2i_lt_ju(const struct libj2_j2i *a, uintmax_t b) +{ + return libj2_j2i_is_negative(a) ? 1 : libj2_j2u_lt_ju((const void *)a, b); +} + + +/** + * Check whether a signed double-max precision integer is less + * than or equal to an unsigned max precision integer + * + * `libj2_j2i_le_ju(a, b)` implements `*a <= *b` + * + * @param a The left-hand value + * @param b The right-hand value + * @return 1 if `*a` is less than or equal to `*b`, 0 otherwise + * + * @since 1.1 + */ +LIBJ2_PURE_ inline int +libj2_j2i_le_ju(const struct libj2_j2i *a, uintmax_t b) +{ + return libj2_j2i_is_negative(a) ? 1 : libj2_j2u_le_ju((const void *)a, b); +} + + +/** + * Check whether a signed double-max precision integer + * is greater than an unsigned max precision integer + * + * `libj2_j2i_gt_ju(a, b)` implements `*a > *b` + * + * @param a The left-hand value + * @param b The right-hand value + * @return 1 if `*a` is greater than `*b`, 0 otherwise + * + * @since 1.1 + */ +LIBJ2_PURE_ inline int +libj2_j2i_gt_ju(const struct libj2_j2i *a, uintmax_t b) +{ + return libj2_j2i_is_negative(a) ? 0 : libj2_j2u_gt_ju((const void *)a, b); +} + + +/** + * Check whether a signed double-max precision integer is greater + * than or equal to an unsigned max precision integer + * + * `libj2_j2i_ge_ju(a, b)` implements `*a >= *b` + * + * @param a The left-hand value + * @param b The right-hand value + * @return 1 if `*a` is greater than or equal to `*b`, 0 otherwise + * + * @since 1.1 + */ +LIBJ2_PURE_ inline int +libj2_j2i_ge_ju(const struct libj2_j2i *a, uintmax_t b) +{ + return libj2_j2i_is_negative(a) ? 0 : libj2_j2u_ge_ju((const void *)a, b); +} + + +/** + * Check whether a signed double-max precision integer + * is equal to an unsigned max precision integer + * + * `libj2_j2i_eq_ju(a, b)` implements `*a == *b` + * + * @param a The left-hand value + * @param b The right-hand value + * @return 1 if `*a` is equal to `*b`, 0 otherwise + * + * @since 1.1 + */ +LIBJ2_PURE_ inline int +libj2_j2i_eq_ju(const struct libj2_j2i *a, uintmax_t b) +{ + return libj2_j2i_is_negative(a) ? 0 : libj2_j2u_eq_ju((const void *)a, b); +} + + +/** + * Check whether a signed double-max precision integer + * is not equal to an unsigned max precision integer + * + * `libj2_j2i_ne_ju(a, b)` implements `*a != *b` + * + * @param a The left-hand value + * @param b The right-hand value + * @return 1 if `*a` is not equal to `*b`, 0 otherwise + * + * @since 1.1 + */ +LIBJ2_PURE_ inline int +libj2_j2i_ne_ju(const struct libj2_j2i *a, uintmax_t b) +{ + return libj2_j2i_is_negative(a) ? 1 : libj2_j2u_ne_ju((const void *)a, b); +} + + +/** + * Compare a signed double-max precision integer + * against an unsigned max precision integer + * + * `libj2_j2i_cmp_ju(a, b)` implements `*a < *b ? -1 : *a > *b ? +1 : 0`, + * or equivalently, the signum of `*a - *b` where the signum is 0 for 0 + * + * @param a The left-hand value + * @param b The right-hand value + * @return -1 if `*a` is less than `*b`, + * +1 if `*a` is greater than `*b`, + * 0 if `*a` is equal to `*b` + * + * @since 1.1 + */ +LIBJ2_PURE_ inline int +libj2_j2i_cmp_ju(const struct libj2_j2i *a, uintmax_t b) +{ + return libj2_j2i_is_negative(a) ? -1 : libj2_j2u_cmp_ju((const void *)a, b); +} + + +/** + * Check whether an unsigned double-max precision integer + * is less than a signed max precision integer + * + * `libj2_j2u_lt_ji(a, b)` implements `*a < *b` + * + * @param a The left-hand value + * @param b The right-hand value + * @return 1 if `*a` is less than `*b`, 0 otherwise + * + * @since 1.1 + */ +LIBJ2_PURE_ inline int +libj2_j2u_lt_ji(const struct libj2_j2u *a, intmax_t b) +{ + return b < 0 ? 0 : libj2_j2u_lt_ju(a, (uintmax_t)b); +} + + +/** + * Check whether an unsigned double-max precision integer is + * less than or equal to a signed max precision integer + * + * `libj2_j2u_le_ji(a, b)` implements `*a <= *b` + * + * @param a The left-hand value + * @param b The right-hand value + * @return 1 if `*a` is less than or equal to `*b`, 0 otherwise + * + * @since 1.1 + */ +LIBJ2_PURE_ inline int +libj2_j2u_le_ji(const struct libj2_j2u *a, intmax_t b) +{ + return b < 0 ? 0 : libj2_j2u_le_ju(a, (uintmax_t)b); +} + + +/** + * Check whether an unsigned double-max precision integer + * is greater than a signed max precision integer + * + * `libj2_j2u_gt_ji(a, b)` implements `*a > *b` + * + * @param a The left-hand value + * @param b The right-hand value + * @return 1 if `*a` is greater than `*b`, 0 otherwise + * + * @since 1.1 + */ +LIBJ2_PURE_ inline int +libj2_j2u_gt_ji(const struct libj2_j2u *a, intmax_t b) +{ + return b < 0 ? 1 : libj2_j2u_gt_ju(a, (uintmax_t)b); +} + + +/** + * Check whether an unsigned double-max precision integer is + * greater than or equal to a signed max precision integer + * + * `libj2_j2u_ge_ji(a, b)` implements `*a >= *b` + * + * @param a The left-hand value + * @param b The right-hand value + * @return 1 if `*a` is greater than or equal to `*b`, 0 otherwise + * + * @since 1.1 + */ +LIBJ2_PURE_ inline int +libj2_j2u_ge_ji(const struct libj2_j2u *a, intmax_t b) +{ + return b < 0 ? 1 : libj2_j2u_ge_ju(a, (uintmax_t)b); +} + + +/** + * Check whether an unsigned double-max precision integer + * is equal to a signed max precision integer + * + * `libj2_j2u_eq_ji(a, b)` implements `*a == *b` + * + * @param a The left-hand value + * @param b The right-hand value + * @return 1 if `*a` is equal to `*b`, 0 otherwise + * + * @since 1.1 + */ +LIBJ2_PURE_ inline int +libj2_j2u_eq_ji(const struct libj2_j2u *a, intmax_t b) +{ + return b < 0 ? 0 : libj2_j2u_eq_ju(a, (uintmax_t)b); +} + + +/** + * Check whether an unsigned double-max precision integer + * is not equal to a signed max precision integer + * + * `libj2_j2u_ne_ji(a, b)` implements `*a != *b` + * + * @param a The left-hand value + * @param b The right-hand value + * @return 1 if `*a` is not equal to `*b`, 0 otherwise + * + * @since 1.1 + */ +LIBJ2_PURE_ inline int +libj2_j2u_ne_ji(const struct libj2_j2u *a, intmax_t b) +{ + return b < 0 ? 1 : libj2_j2u_ne_ju(a, (uintmax_t)b); +} + + +/** + * Compare an unsigned double-max precision integer + * against a signed max precision integer + * + * `libj2_j2u_cmp_ji(a, b)` implements `*a < *b ? -1 : *a > *b ? +1 : 0`, + * or equivalently, the signum of `*a - *b` where the signum is 0 for 0 + * + * @param a The left-hand value + * @param b The right-hand value + * @return -1 if `*a` is less than `*b`, + * +1 if `*a` is greater than `*b`, + * 0 if `*a` is equal to `*b` + * + * @since 1.1 + */ +LIBJ2_PURE_ inline int +libj2_j2u_cmp_ji(const struct libj2_j2u *a, intmax_t b) +{ + return b < 0 ? +1 : libj2_j2u_cmp_ju(a, (uintmax_t)b); +} diff --git a/libj2/mixed-comparsion.h b/libj2/mixed-comparsion.h deleted file mode 100644 index dedf18d..0000000 --- a/libj2/mixed-comparsion.h +++ /dev/null @@ -1,820 +0,0 @@ -/* See LICENSE file for copyright and license details. */ -#ifndef LIBJ2_H -# error Do not include this header directly, include instead -#endif - - -/** - * Check whether a signed double-max precision integer - * is less than an unsigned double-max precision integer - * - * `libj2_j2i_lt_j2u(a, b)` implements `*a < *b` - * - * @param a The left-hand value - * @param b The right-hand value - * @return 1 if `*a` is less than `*b`, 0 otherwise - * - * @since 1.1 - */ -LIBJ2_PURE_ inline int -libj2_j2i_lt_j2u(const struct libj2_j2i *a, const struct libj2_j2u *b) -{ - return libj2_j2i_is_negative(a) ? 1 : libj2_j2u_lt_j2u((const void *)a, b); -} - - -/** - * Check whether a signed double-max precision integer is less - * than or equal to an unsigned double-max precision integer - * - * `libj2_j2i_le_j2u(a, b)` implements `*a <= *b` - * - * @param a The left-hand value - * @param b The right-hand value - * @return 1 if `*a` is less than or equal to `*b`, 0 otherwise - * - * @since 1.1 - */ -LIBJ2_PURE_ inline int -libj2_j2i_le_j2u(const struct libj2_j2i *a, const struct libj2_j2u *b) -{ - return libj2_j2i_is_negative(a) ? 1 : libj2_j2u_le_j2u((const void *)a, b); -} - - -/** - * Check whether a signed double-max precision integer - * is greater than an unsigned double-max precision integer - * - * `libj2_j2i_gt_j2u(a, b)` implements `*a > *b` - * - * @param a The left-hand value - * @param b The right-hand value - * @return 1 if `*a` is greater than `*b`, 0 otherwise - * - * @since 1.1 - */ -LIBJ2_PURE_ inline int -libj2_j2i_gt_j2u(const struct libj2_j2i *a, const struct libj2_j2u *b) -{ - return libj2_j2i_is_negative(a) ? 0 : libj2_j2u_gt_j2u((const void *)a, b); -} - - -/** - * Check whether a signed double-max precision integer is greater - * than or equal to an unsigned double-max precision integer - * - * `libj2_j2i_ge_j2u(a, b)` implements `*a >= *b` - * - * @param a The left-hand value - * @param b The right-hand value - * @return 1 if `*a` is greater than or equal to `*b`, 0 otherwise - * - * @since 1.1 - */ -LIBJ2_PURE_ inline int -libj2_j2i_ge_j2u(const struct libj2_j2i *a, const struct libj2_j2u *b) -{ - return libj2_j2i_is_negative(a) ? 0 : libj2_j2u_ge_j2u((const void *)a, b); -} - - -/** - * Check whether a signed double-max precision integer - * is equal to an unsigned double-max precision integer - * - * `libj2_j2i_eq_j2u(a, b)` implements `*a == *b` - * - * @param a The left-hand value - * @param b The right-hand value - * @return 1 if `*a` is equal to `*b`, 0 otherwise - * - * @since 1.1 - */ -LIBJ2_PURE_ inline int -libj2_j2i_eq_j2u(const struct libj2_j2i *a, const struct libj2_j2u *b) -{ - return libj2_j2i_is_negative(a) ? 0 : libj2_j2u_eq_j2u((const void *)a, b); -} - - -/** - * Check whether a signed double-max precision integer - * is not equal to an unsigned double-max precision integer - * - * `libj2_j2i_ne_j2u(a, b)` implements `*a != *b` - * - * @param a The left-hand value - * @param b The right-hand value - * @return 1 if `*a` is not equal to `*b`, 0 otherwise - * - * @since 1.1 - */ -LIBJ2_PURE_ inline int -libj2_j2i_ne_j2u(const struct libj2_j2i *a, const struct libj2_j2u *b) -{ - return libj2_j2i_is_negative(a) ? 1 : libj2_j2u_ne_j2u((const void *)a, b); -} - - -/** - * Compare a signed double-max precision integer - * against an unsigned double-max precision integer - * - * `libj2_j2i_cmp_j2u(a, b)` implements `*a < *b ? -1 : *a > *b ? +1 : 0`, - * or equivalently, the signum of `*a - *b` where the signum is 0 for 0 - * - * @param a The left-hand value - * @param b The right-hand value - * @return -1 if `*a` is less than `*b`, - * +1 if `*a` is greater than `*b`, - * 0 if `*a` is equal to `*b` - * - * @since 1.1 - */ -LIBJ2_PURE_ inline int -libj2_j2i_cmp_j2u(const struct libj2_j2i *a, const struct libj2_j2u *b) -{ - return libj2_j2i_is_negative(a) ? -1 : libj2_j2u_cmp_j2u((const void *)a, b); -} - - -/** - * Check whether an unsigned double-max precision integer - * is less than a signed double-max precision integer - * - * `libj2_j2u_lt_j2i(a, b)` implements `*a < *b` - * - * @param a The left-hand value - * @param b The right-hand value - * @return 1 if `*a` is less than `*b`, 0 otherwise - * - * @since 1.1 - */ -LIBJ2_PURE_ inline int -libj2_j2u_lt_j2i(const struct libj2_j2u *a, const struct libj2_j2i *b) -{ - return libj2_j2i_is_negative(b) ? 0 : libj2_j2u_lt_j2u(a, (const void *)b); -} - - -/** - * Check whether an unsigned double-max precision integer is less - * than or equal to a signed double-max precision integer - * - * `libj2_j2u_le_j2i(a, b)` implements `*a <= *b` - * - * @param a The left-hand value - * @param b The right-hand value - * @return 1 if `*a` is less than or equal to `*b`, 0 otherwise - * - * @since 1.1 - */ -LIBJ2_PURE_ inline int -libj2_j2u_le_j2i(const struct libj2_j2u *a, const struct libj2_j2i *b) -{ - return libj2_j2i_is_negative(b) ? 0 : libj2_j2u_le_j2u(a, (const void *)b); -} - - -/** - * Check whether an unsigned double-max precision integer - * is greater than a signed double-max precision integer - * - * `libj2_j2u_gt_j2i(a, b)` implements `*a > *b` - * - * @param a The left-hand value - * @param b The right-hand value - * @return 1 if `*a` is greater than `*b`, 0 otherwise - * - * @since 1.1 - */ -LIBJ2_PURE_ inline int -libj2_j2u_gt_j2i(const struct libj2_j2u *a, const struct libj2_j2i *b) -{ - return libj2_j2i_is_negative(b) ? 1 : libj2_j2u_gt_j2u(a, (const void *)b); -} - - -/** - * Check whether an unsigned double-max precision integer is - * greater than or equal to a signed double-max precision integer - * - * `libj2_j2u_ge_j2i(a, b)` implements `*a >= *b` - * - * @param a The left-hand value - * @param b The right-hand value - * @return 1 if `*a` is greater than or equal to `*b`, 0 otherwise - * - * @since 1.1 - */ -LIBJ2_PURE_ inline int -libj2_j2u_ge_j2i(const struct libj2_j2u *a, const struct libj2_j2i *b) -{ - return libj2_j2i_is_negative(b) ? 1 : libj2_j2u_ge_j2u(a, (const void *)b); -} - - -/** - * Check whether an unsigned double-max precision integer - * is equal to a signed double-max precision integer - * - * `libj2_j2u_eq_j2i(a, b)` implements `*a == *b` - * - * @param a The left-hand value - * @param b The right-hand value - * @return 1 if `*a` is equal to `*b`, 0 otherwise - * - * @since 1.1 - */ -LIBJ2_PURE_ inline int -libj2_j2u_eq_j2i(const struct libj2_j2u *a, const struct libj2_j2i *b) -{ - return libj2_j2i_is_negative(b) ? 0 : libj2_j2u_eq_j2u(a, (const void *)b); -} - - -/** - * Check whether an unsigned double-max precision integer - * is not equal to a signed double-max precision integer - * - * `libj2_j2u_ne_j2i(a, b)` implements `*a != *b` - * - * @param a The left-hand value - * @param b The right-hand value - * @return 1 if `*a` is not equal to `*b`, 0 otherwise - * - * @since 1.1 - */ -LIBJ2_PURE_ inline int -libj2_j2u_ne_j2i(const struct libj2_j2u *a, const struct libj2_j2i *b) -{ - return libj2_j2i_is_negative(b) ? 1 : libj2_j2u_ne_j2u(a, (const void *)b); -} - - -/** - * Compare an unsigned double-max precision integer - * against a signed double-max precision integer - * - * `libj2_j2u_cmp_j2i(a, b)` implements `*a < *b ? -1 : *a > *b ? +1 : 0`, - * or equivalently, the signum of `*a - *b` where the signum is 0 for 0 - * - * @param a The left-hand value - * @param b The right-hand value - * @return -1 if `*a` is less than `*b`, - * +1 if `*a` is greater than `*b`, - * 0 if `*a` is equal to `*b` - * - * @since 1.1 - */ -LIBJ2_PURE_ inline int -libj2_j2u_cmp_j2i(const struct libj2_j2u *a, const struct libj2_j2i *b) -{ - return libj2_j2i_is_negative(b) ? +1 : libj2_j2u_cmp_j2u(a, (const void *)b); -} - - -/** - * Check whether a signed max precision integer - * is less than an unsigned double-max precision integer - * - * `libj2_ji_lt_j2u(a, b)` implements `*a < *b` - * - * @param a The left-hand value - * @param b The right-hand value - * @return 1 if `*a` is less than `*b`, 0 otherwise - * - * @since 1.1 - */ -LIBJ2_PURE_ inline int -libj2_ji_lt_j2u(intmax_t a, const struct libj2_j2u *b) -{ - return a < 0 ? 1 : libj2_ju_lt_j2u((uintmax_t)a, b); -} - - -/** - * Check whether a signed max precision integer is less - * than or equal to an unsigned double-max precision integer - * - * `libj2_ji_le_j2u(a, b)` implements `*a <= *b` - * - * @param a The left-hand value - * @param b The right-hand value - * @return 1 if `*a` is less than or equal to `*b`, 0 otherwise - * - * @since 1.1 - */ -LIBJ2_PURE_ inline int -libj2_ji_le_j2u(intmax_t a, const struct libj2_j2u *b) -{ - return a < 0 ? 1 : libj2_ju_le_j2u((uintmax_t)a, b); -} - - -/** - * Check whether a signed max precision integer - * is greater than an unsigned double-max precision integer - * - * `libj2_ji_gt_j2u(a, b)` implements `*a > *b` - * - * @param a The left-hand value - * @param b The right-hand value - * @return 1 if `*a` is greater than `*b`, 0 otherwise - * - * @since 1.1 - */ -LIBJ2_PURE_ inline int -libj2_ji_gt_j2u(intmax_t a, const struct libj2_j2u *b) -{ - return a < 0 ? 0 : libj2_ju_gt_j2u((uintmax_t)a, b); -} - - -/** - * Check whether a signed max precision integer is greater - * than or equal to an unsigned double-max precision integer - * - * `libj2_ji_ge_j2u(a, b)` implements `*a >= *b` - * - * @param a The left-hand value - * @param b The right-hand value - * @return 1 if `*a` is greater than or equal to `*b`, 0 otherwise - * - * @since 1.1 - */ -LIBJ2_PURE_ inline int -libj2_ji_ge_j2u(intmax_t a, const struct libj2_j2u *b) -{ - return a < 0 ? 0 : libj2_ju_ge_j2u((uintmax_t)a, b); -} - - -/** - * Check whether a signed max precision integer - * is equal to an unsigned double-max precision integer - * - * `libj2_ji_eq_j2u(a, b)` implements `*a == *b` - * - * @param a The left-hand value - * @param b The right-hand value - * @return 1 if `*a` is equal to `*b`, 0 otherwise - * - * @since 1.1 - */ -LIBJ2_PURE_ inline int -libj2_ji_eq_j2u(intmax_t a, const struct libj2_j2u *b) -{ - return a < 0 ? 0 : libj2_ju_eq_j2u((uintmax_t)a, b); -} - - -/** - * Check whether a signed max precision integer - * is not equal to an unsigned double-max precision integer - * - * `libj2_ji_ne_j2u(a, b)` implements `*a != *b` - * - * @param a The left-hand value - * @param b The right-hand value - * @return 1 if `*a` is not equal to `*b`, 0 otherwise - * - * @since 1.1 - */ -LIBJ2_PURE_ inline int -libj2_ji_ne_j2u(intmax_t a, const struct libj2_j2u *b) -{ - return a < 0 ? 1 : libj2_ju_ne_j2u((uintmax_t)a, b); -} - - -/** - * Compare a signed max precision integer - * against an unsigned double-max precision integer - * - * `libj2_ji_cmp_j2u(a, b)` implements `*a < *b ? -1 : *a > *b ? +1 : 0`, - * or equivalently, the signum of `*a - *b` where the signum is 0 for 0 - * - * @param a The left-hand value - * @param b The right-hand value - * @return -1 if `*a` is less than `*b`, - * +1 if `*a` is greater than `*b`, - * 0 if `*a` is equal to `*b` - * - * @since 1.1 - */ -LIBJ2_PURE_ inline int -libj2_ji_cmp_j2u(intmax_t a, const struct libj2_j2u *b) -{ - return a < 0 ? -1 : libj2_ju_cmp_j2u((uintmax_t)a, b); -} - - -/** - * Check whether an unsigned double-max precision integer - * is less than a signed max precision integer - * - * `libj2_ju_lt_j2i(a, b)` implements `*a < *b` - * - * @param a The left-hand value - * @param b The right-hand value - * @return 1 if `*a` is less than `*b`, 0 otherwise - * - * @since 1.1 - */ -LIBJ2_PURE_ inline int -libj2_ju_lt_j2i(uintmax_t a, const struct libj2_j2i *b) -{ - return libj2_j2i_is_negative(b) ? 0 : libj2_ju_lt_j2u(a, (const void *)b); -} - - -/** - * Check whether an unsigned double-max precision integer - * is less than or equal to a signed max precision integer - * - * `libj2_ju_le_j2i(a, b)` implements `*a <= *b` - * - * @param a The left-hand value - * @param b The right-hand value - * @return 1 if `*a` is less than or equal to `*b`, 0 otherwise - * - * @since 1.1 - */ -LIBJ2_PURE_ inline int -libj2_ju_le_j2i(uintmax_t a, const struct libj2_j2i *b) -{ - return libj2_j2i_is_negative(b) ? 0 : libj2_ju_le_j2u(a, (const void *)b); -} - - -/** - * Check whether an unsigned double-max precision integer - * is greater than a signed max precision integer - * - * `libj2_ju_gt_j2i(a, b)` implements `*a > *b` - * - * @param a The left-hand value - * @param b The right-hand value - * @return 1 if `*a` is greater than `*b`, 0 otherwise - * - * @since 1.1 - */ -LIBJ2_PURE_ inline int -libj2_ju_gt_j2i(uintmax_t a, const struct libj2_j2i *b) -{ - return libj2_j2i_is_negative(b) ? 1 : libj2_ju_gt_j2u(a, (const void *)b); -} - - -/** - * Check whether an unsigned double-max precision integer is - * greater than or equal to a signed max precision integer - * - * `libj2_ju_ge_j2i(a, b)` implements `*a >= *b` - * - * @param a The left-hand value - * @param b The right-hand value - * @return 1 if `*a` is greater than or equal to `*b`, 0 otherwise - * - * @since 1.1 - */ -LIBJ2_PURE_ inline int -libj2_ju_ge_j2i(uintmax_t a, const struct libj2_j2i *b) -{ - return libj2_j2i_is_negative(b) ? 1 : libj2_ju_ge_j2u(a, (const void *)b); -} - - -/** - * Check whether an unsigned double-max precision integer - * is equal to a signed max precision integer - * - * `libj2_ju_eq_j2i(a, b)` implements `*a == *b` - * - * @param a The left-hand value - * @param b The right-hand value - * @return 1 if `*a` is equal to `*b`, 0 otherwise - * - * @since 1.1 - */ -LIBJ2_PURE_ inline int -libj2_ju_eq_j2i(uintmax_t a, const struct libj2_j2i *b) -{ - return libj2_j2i_is_negative(b) ? 0 : libj2_ju_eq_j2u(a, (const void *)b); -} - - -/** - * Check whether an unsigned double-max precision integer - * is not equal to a signed max precision integer - * - * `libj2_ju_ne_j2i(a, b)` implements `*a != *b` - * - * @param a The left-hand value - * @param b The right-hand value - * @return 1 if `*a` is not equal to `*b`, 0 otherwise - * - * @since 1.1 - */ -LIBJ2_PURE_ inline int -libj2_ju_ne_j2i(uintmax_t a, const struct libj2_j2i *b) -{ - return libj2_j2i_is_negative(b) ? 1 : libj2_ju_ne_j2u(a, (const void *)b); -} - - -/** - * Compare an unsigned double-max precision integer - * against a signed max precision integer - * - * `libj2_ju_cmp_j2i(a, b)` implements `*a < *b ? -1 : *a > *b ? +1 : 0`, - * or equivalently, the signum of `*a - *b` where the signum is 0 for 0 - * - * @param a The left-hand value - * @param b The right-hand value - * @return -1 if `*a` is less than `*b`, - * +1 if `*a` is greater than `*b`, - * 0 if `*a` is equal to `*b` - * - * @since 1.1 - */ -LIBJ2_PURE_ inline int -libj2_ju_cmp_j2i(uintmax_t a, const struct libj2_j2i *b) -{ - return libj2_j2i_is_negative(b) ? +1 : libj2_ju_cmp_j2u(a, (const void *)b); -} - - -/** - * Check whether a signed double-max precision integer - * is less than an unsigned max precision integer - * - * `libj2_j2i_lt_ju(a, b)` implements `*a < *b` - * - * @param a The left-hand value - * @param b The right-hand value - * @return 1 if `*a` is less than `*b`, 0 otherwise - * - * @since 1.1 - */ -LIBJ2_PURE_ inline int -libj2_j2i_lt_ju(const struct libj2_j2i *a, uintmax_t b) -{ - return libj2_j2i_is_negative(a) ? 1 : libj2_j2u_lt_ju((const void *)a, b); -} - - -/** - * Check whether a signed double-max precision integer is less - * than or equal to an unsigned max precision integer - * - * `libj2_j2i_le_ju(a, b)` implements `*a <= *b` - * - * @param a The left-hand value - * @param b The right-hand value - * @return 1 if `*a` is less than or equal to `*b`, 0 otherwise - * - * @since 1.1 - */ -LIBJ2_PURE_ inline int -libj2_j2i_le_ju(const struct libj2_j2i *a, uintmax_t b) -{ - return libj2_j2i_is_negative(a) ? 1 : libj2_j2u_le_ju((const void *)a, b); -} - - -/** - * Check whether a signed double-max precision integer - * is greater than an unsigned max precision integer - * - * `libj2_j2i_gt_ju(a, b)` implements `*a > *b` - * - * @param a The left-hand value - * @param b The right-hand value - * @return 1 if `*a` is greater than `*b`, 0 otherwise - * - * @since 1.1 - */ -LIBJ2_PURE_ inline int -libj2_j2i_gt_ju(const struct libj2_j2i *a, uintmax_t b) -{ - return libj2_j2i_is_negative(a) ? 0 : libj2_j2u_gt_ju((const void *)a, b); -} - - -/** - * Check whether a signed double-max precision integer is greater - * than or equal to an unsigned max precision integer - * - * `libj2_j2i_ge_ju(a, b)` implements `*a >= *b` - * - * @param a The left-hand value - * @param b The right-hand value - * @return 1 if `*a` is greater than or equal to `*b`, 0 otherwise - * - * @since 1.1 - */ -LIBJ2_PURE_ inline int -libj2_j2i_ge_ju(const struct libj2_j2i *a, uintmax_t b) -{ - return libj2_j2i_is_negative(a) ? 0 : libj2_j2u_ge_ju((const void *)a, b); -} - - -/** - * Check whether a signed double-max precision integer - * is equal to an unsigned max precision integer - * - * `libj2_j2i_eq_ju(a, b)` implements `*a == *b` - * - * @param a The left-hand value - * @param b The right-hand value - * @return 1 if `*a` is equal to `*b`, 0 otherwise - * - * @since 1.1 - */ -LIBJ2_PURE_ inline int -libj2_j2i_eq_ju(const struct libj2_j2i *a, uintmax_t b) -{ - return libj2_j2i_is_negative(a) ? 0 : libj2_j2u_eq_ju((const void *)a, b); -} - - -/** - * Check whether a signed double-max precision integer - * is not equal to an unsigned max precision integer - * - * `libj2_j2i_ne_ju(a, b)` implements `*a != *b` - * - * @param a The left-hand value - * @param b The right-hand value - * @return 1 if `*a` is not equal to `*b`, 0 otherwise - * - * @since 1.1 - */ -LIBJ2_PURE_ inline int -libj2_j2i_ne_ju(const struct libj2_j2i *a, uintmax_t b) -{ - return libj2_j2i_is_negative(a) ? 1 : libj2_j2u_ne_ju((const void *)a, b); -} - - -/** - * Compare a signed double-max precision integer - * against an unsigned max precision integer - * - * `libj2_j2i_cmp_ju(a, b)` implements `*a < *b ? -1 : *a > *b ? +1 : 0`, - * or equivalently, the signum of `*a - *b` where the signum is 0 for 0 - * - * @param a The left-hand value - * @param b The right-hand value - * @return -1 if `*a` is less than `*b`, - * +1 if `*a` is greater than `*b`, - * 0 if `*a` is equal to `*b` - * - * @since 1.1 - */ -LIBJ2_PURE_ inline int -libj2_j2i_cmp_ju(const struct libj2_j2i *a, uintmax_t b) -{ - return libj2_j2i_is_negative(a) ? -1 : libj2_j2u_cmp_ju((const void *)a, b); -} - - -/** - * Check whether an unsigned double-max precision integer - * is less than a signed max precision integer - * - * `libj2_j2u_lt_ji(a, b)` implements `*a < *b` - * - * @param a The left-hand value - * @param b The right-hand value - * @return 1 if `*a` is less than `*b`, 0 otherwise - * - * @since 1.1 - */ -LIBJ2_PURE_ inline int -libj2_j2u_lt_ji(const struct libj2_j2u *a, intmax_t b) -{ - return b < 0 ? 0 : libj2_j2u_lt_ju(a, (uintmax_t)b); -} - - -/** - * Check whether an unsigned double-max precision integer is - * less than or equal to a signed max precision integer - * - * `libj2_j2u_le_ji(a, b)` implements `*a <= *b` - * - * @param a The left-hand value - * @param b The right-hand value - * @return 1 if `*a` is less than or equal to `*b`, 0 otherwise - * - * @since 1.1 - */ -LIBJ2_PURE_ inline int -libj2_j2u_le_ji(const struct libj2_j2u *a, intmax_t b) -{ - return b < 0 ? 0 : libj2_j2u_le_ju(a, (uintmax_t)b); -} - - -/** - * Check whether an unsigned double-max precision integer - * is greater than a signed max precision integer - * - * `libj2_j2u_gt_ji(a, b)` implements `*a > *b` - * - * @param a The left-hand value - * @param b The right-hand value - * @return 1 if `*a` is greater than `*b`, 0 otherwise - * - * @since 1.1 - */ -LIBJ2_PURE_ inline int -libj2_j2u_gt_ji(const struct libj2_j2u *a, intmax_t b) -{ - return b < 0 ? 1 : libj2_j2u_gt_ju(a, (uintmax_t)b); -} - - -/** - * Check whether an unsigned double-max precision integer is - * greater than or equal to a signed max precision integer - * - * `libj2_j2u_ge_ji(a, b)` implements `*a >= *b` - * - * @param a The left-hand value - * @param b The right-hand value - * @return 1 if `*a` is greater than or equal to `*b`, 0 otherwise - * - * @since 1.1 - */ -LIBJ2_PURE_ inline int -libj2_j2u_ge_ji(const struct libj2_j2u *a, intmax_t b) -{ - return b < 0 ? 1 : libj2_j2u_ge_ju(a, (uintmax_t)b); -} - - -/** - * Check whether an unsigned double-max precision integer - * is equal to a signed max precision integer - * - * `libj2_j2u_eq_ji(a, b)` implements `*a == *b` - * - * @param a The left-hand value - * @param b The right-hand value - * @return 1 if `*a` is equal to `*b`, 0 otherwise - * - * @since 1.1 - */ -LIBJ2_PURE_ inline int -libj2_j2u_eq_ji(const struct libj2_j2u *a, intmax_t b) -{ - return b < 0 ? 0 : libj2_j2u_eq_ju(a, (uintmax_t)b); -} - - -/** - * Check whether an unsigned double-max precision integer - * is not equal to a signed max precision integer - * - * `libj2_j2u_ne_ji(a, b)` implements `*a != *b` - * - * @param a The left-hand value - * @param b The right-hand value - * @return 1 if `*a` is not equal to `*b`, 0 otherwise - * - * @since 1.1 - */ -LIBJ2_PURE_ inline int -libj2_j2u_ne_ji(const struct libj2_j2u *a, intmax_t b) -{ - return b < 0 ? 1 : libj2_j2u_ne_ju(a, (uintmax_t)b); -} - - -/** - * Compare an unsigned double-max precision integer - * against a signed max precision integer - * - * `libj2_j2u_cmp_ji(a, b)` implements `*a < *b ? -1 : *a > *b ? +1 : 0`, - * or equivalently, the signum of `*a - *b` where the signum is 0 for 0 - * - * @param a The left-hand value - * @param b The right-hand value - * @return -1 if `*a` is less than `*b`, - * +1 if `*a` is greater than `*b`, - * 0 if `*a` is equal to `*b` - * - * @since 1.1 - */ -LIBJ2_PURE_ inline int -libj2_j2u_cmp_ji(const struct libj2_j2u *a, intmax_t b) -{ - return b < 0 ? +1 : libj2_j2u_cmp_ju(a, (uintmax_t)b); -} diff --git a/libj2/signed-comparison.h b/libj2/signed-comparison.h new file mode 100644 index 0000000..1bed2f1 --- /dev/null +++ b/libj2/signed-comparison.h @@ -0,0 +1,858 @@ +/* See LICENSE file for copyright and license details. */ +#ifndef LIBJ2_H +# error Do not include this header directly, include instead +#endif + + +/** + * Compare a signed double-max precision integer + * against another signed double-max precision integer + * + * `libj2_j2i_cmp_j2i(a, b)` implements `*a < *b ? -1 : *a > *b ? +1 : 0`, + * or equivalently, the signum of `*a - *b` where the signum is 0 for 0 + * + * @param a The left-hand value + * @param b The right-hand value + * @return -1 if `*a` is less than `*b`, + * +1 if `*a` is greater than `*b`, + * 0 if `*a` is equal to `*b` + * + * @since 1.1 + */ +LIBJ2_PURE_ inline int +libj2_j2i_cmp_j2i(const struct libj2_j2i *a, const struct libj2_j2i *b) +{ + int cmp = libj2_sgn_j2i(a) - libj2_sgn_j2i(b); + if (cmp) + return cmp < 0 ? -1 : +1; + return libj2_j2u_cmp_j2u((const void *)a, (const void *)b); +} + + +/** + * Check whether a signed double-max precision integer is + * less than another signed double-max precision integer + * + * `libj2_j2i_lt_j2i(a, b)` implements `*a < *b` + * + * @param a The left-hand value + * @param b The right-hand value + * @return 1 if `*a` is less than `*b`, 0 otherwise + * + * @since 1.1 + */ +LIBJ2_PURE_ inline int +libj2_j2i_lt_j2i(const struct libj2_j2i *a, const struct libj2_j2i *b) +{ + return libj2_j2i_cmp_j2i(a, b) < 0; +} + + +/** + * Check whether a signed double-max precision integer is less + * than or equal to another signed double-max precision integer + * + * `libj2_j2i_le_j2i(a, b)` implements `*a <= *b` + * + * @param a The left-hand value + * @param b The right-hand value + * @return 1 if `*a` is less than or equal to `*b`, 0 otherwise + * + * @since 1.1 + */ +LIBJ2_PURE_ inline int +libj2_j2i_le_j2i(const struct libj2_j2i *a, const struct libj2_j2i *b) +{ + return libj2_j2i_cmp_j2i(a, b) <= 0; +} + + +/** + * Check whether a signed double-max precision integer is + * greater than another signed double-max precision integer + * + * `libj2_j2i_gt_j2i(a, b)` implements `*a > *b` + * + * @param a The left-hand value + * @param b The right-hand value + * @return 1 if `*a` is greater than `*b`, 0 otherwise + * + * @since 1.1 + */ +LIBJ2_PURE_ inline int +libj2_j2i_gt_j2i(const struct libj2_j2i *a, const struct libj2_j2i *b) +{ + return libj2_j2i_cmp_j2i(a, b) > 0; +} + + +/** + * Check whether a signed double-max precision integer is greater + * than or equal to another signed double-max precision integer + * + * `libj2_j2i_ge_j2i(a, b)` implements `*a >= *b` + * + * @param a The left-hand value + * @param b The right-hand value + * @return 1 if `*a` is greater than or equal to `*b`, 0 otherwise + * + * @since 1.1 + */ +LIBJ2_PURE_ inline int +libj2_j2i_ge_j2i(const struct libj2_j2i *a, const struct libj2_j2i *b) +{ + return libj2_j2i_cmp_j2i(a, b) >= 0; +} + + +/** + * Check whether a signed double-max precision integer is + * equal to another signed double-max precision integer + * + * `libj2_j2i_eq_j2i(a, b)` implements `*a == *b` + * + * @param a The left-hand value + * @param b The right-hand value + * @return 1 if `*a` is equal to `*b`, 0 otherwise + * + * @since 1.1 + */ +LIBJ2_PURE_ inline int +libj2_j2i_eq_j2i(const struct libj2_j2i *a, const struct libj2_j2i *b) +{ + return libj2_j2u_eq_j2u((const void *)a, (const void *)b); +} + + +/** + * Check whether a signed double-max precision integer is + * not equal to another signed double-max precision integer + * + * `libj2_j2i_ne_j2i(a, b)` implements `*a != *b` + * + * @param a The left-hand value + * @param b The right-hand value + * @return 1 if `*a` is not equal to `*b`, 0 otherwise + * + * @since 1.1 + */ +LIBJ2_PURE_ inline int +libj2_j2i_ne_j2i(const struct libj2_j2i *a, const struct libj2_j2i *b) +{ + return libj2_j2u_ne_j2u((const void *)a, (const void *)b); +} + + +/** + * Compare a signed double-max precision integer + * against a signed max precision integer + * + * `libj2_j2i_cmp_ji(a, b)` implements `*a < b ? -1 : *a > b ? +1 : 0`, + * or equivalently, the signum of `*a - b` where the signum is 0 for 0 + * + * @param a The left-hand value + * @param b The right-hand value + * @return -1 if `*a` is less than `b`, + * +1 if `*a` is greater than `b`, + * 0 if `*a` is equal to `b` + * + * @since 1.1 + */ +LIBJ2_PURE_ inline int +libj2_j2i_cmp_ji(const struct libj2_j2i *a, intmax_t b) +{ + struct libj2_j2i t; + libj2_ji_to_j2i(b, &t); + return libj2_j2i_cmp_j2i(a, &t); +} + + +/** + * Check whether a signed double-max precision integer + * is less than a signed max precision integer + * + * `libj2_j2i_lt_ji(a, b)` implements `*a < b` + * + * @param a The left-hand value + * @param b The right-hand value + * @return 1 if `*a` is less than `b`, 0 otherwise + * + * @since 1.1 + */ +LIBJ2_PURE_ inline int +libj2_j2i_lt_ji(const struct libj2_j2i *a, intmax_t b) +{ + return libj2_j2i_cmp_ji(a, b) < 0; +} + + +/** + * Check whether a signed double-max precision integer is + * less than or equal to a signed max precision integer + * + * `libj2_j2i_le_ji(a, b)` implements `*a <= b` + * + * @param a The left-hand value + * @param b The right-hand value + * @return 1 if `*a` is less than or equal to `b`, 0 otherwise + * + * @since 1.1 + */ +LIBJ2_PURE_ inline int +libj2_j2i_le_ji(const struct libj2_j2i *a, intmax_t b) +{ + return libj2_j2i_cmp_ji(a, b) <= 0; +} + + +/** + * Check whether a signed double-max precision integer + * is greater than a signed max precision integer + * + * `libj2_j2i_gt_ji(a, b)` implements `*a > b` + * + * @param a The left-hand value + * @param b The right-hand value + * @return 1 if `*a` is less than `b`, 0 otherwise + * + * @since 1.1 + */ +LIBJ2_PURE_ inline int +libj2_j2i_gt_ji(const struct libj2_j2i *a, intmax_t b) +{ + return libj2_j2i_cmp_ji(a, b) > 0; +} + + +/** + * Check whether a signed double-max precision integer is + * greater than or equal to a signed max precision integer + * + * `libj2_j2i_ge_ji(a, b)` implements `*a >= b` + * + * @param a The left-hand value + * @param b The right-hand value + * @return 1 if `*a` is greater than or equal to `b`, 0 otherwise + * + * @since 1.1 + */ +LIBJ2_PURE_ inline int +libj2_j2i_ge_ji(const struct libj2_j2i *a, intmax_t b) +{ + return libj2_j2i_cmp_ji(a, b) >= 0; +} + + +/** + * Check whether a signed double-max precision integer + * is equal to a signed max precision integer + * + * `libj2_j2i_eq_ji(a, b)` implements `*a == b` + * + * @param a The left-hand value + * @param b The right-hand value + * @return 1 if `*a` is equal to `b`, 0 otherwise + * + * @since 1.1 + */ +LIBJ2_PURE_ inline int +libj2_j2i_eq_ji(const struct libj2_j2i *a, intmax_t b) +{ + if (b >= 0) + return !a->high && a->low == (uintmax_t)b; + return a->high == UINTMAX_MAX && a->low == ~(uintmax_t)-(b + 1); +} + + +/** + * Check whether a signed double-max precision integer + * is not equal to a signed max precision integer + * + * `libj2_j2i_ne_ji(a, b)` implements `*a != b` + * + * @param a The left-hand value + * @param b The right-hand value + * @return 1 if `*a` is not equal to `b`, 0 otherwise + * + * @since 1.1 + */ +LIBJ2_PURE_ inline int +libj2_j2i_ne_ji(const struct libj2_j2i *a, intmax_t b) +{ + return !libj2_j2i_eq_ji(a, b); +} + + +/** + * Compare a signed max precision integer + * against a signed double-max precision integer + * + * `libj2_ji_cmp_j2i(a, b)` implements `a < *b ? -1 : a > *b ? +1 : 0`, + * or equivalently, the signum of `a - *b` where the signum is 0 for 0 + * + * @param a The left-hand value + * @param b The right-hand value + * @return -1 if `a` is less than `*b`, + * +1 if `a` is greater than `*b`, + * 0 if `a` is equal to `*b` + * + * @since 1.1 + */ +LIBJ2_PURE_ inline int +libj2_ji_cmp_j2i(intmax_t a, const struct libj2_j2i *b) +{ + struct libj2_j2i t; + libj2_ji_to_j2i(a, &t); + return libj2_j2i_cmp_j2i(&t, b); +} + + +/** + * Check whether a signed max precision integer is + * less than a signed double-max precision integer + * + * `libj2_ji_lt_j2i(a, b)` implements `a < *b` + * + * @param a The left-hand value + * @param b The right-hand value + * @return 1 if `a` is less than `*b`, 0 otherwise + * + * @since 1.1 + */ +LIBJ2_PURE_ inline int +libj2_ji_lt_j2i(intmax_t a, const struct libj2_j2i *b) +{ + return libj2_j2i_gt_ji(b, a); +} + + +/** + * Check whether a signed max precision integer is less + * than or equal to a signed double-max precision integer + * + * `libj2_ji_le_j2i(a, b)` implements `a <= *b` + * + * @param a The left-hand value + * @param b The right-hand value + * @return 1 if `a` is less than or equal to `*b`, 0 otherwise + * + * @since 1.1 + */ +LIBJ2_PURE_ inline int +libj2_ji_le_j2i(intmax_t a, const struct libj2_j2i *b) +{ + return libj2_j2i_ge_ji(b, a); +} + + +/** + * Check whether a signed max precision integer is + * greater than a signed double-max precision integer + * + * `libj2_ji_gt_j2i(a, b)` implements `a > *b` + * + * @param a The left-hand value + * @param b The right-hand value + * @return 1 if `a` is less than `*b`, 0 otherwise + * + * @since 1.1 + */ +LIBJ2_PURE_ inline int +libj2_ji_gt_j2i(intmax_t a, const struct libj2_j2i *b) +{ + return libj2_j2i_lt_ji(b, a); +} + + +/** + * Check whether a signed max precision integer is greater + * than or equal to a signed double-max precision integer + * + * `libj2_ji_ge_j2i(a, b)` implements `a >= *b` + * + * @param a The left-hand value + * @param b The right-hand value + * @return 1 if `a` is greater than or equal to `*b`, 0 otherwise + * + * @since 1.1 + */ +LIBJ2_PURE_ inline int +libj2_ji_ge_j2i(intmax_t a, const struct libj2_j2i *b) +{ + return libj2_j2i_le_ji(b, a); +} + + +/** + * Check whether a signed max precision integer is + * equal to a signed double-max precision integer + * + * `libj2_ji_eq_j2i(a, b)` implements `a == *b` + * + * @param a The left-hand value + * @param b The right-hand value + * @return 1 if `a` is equal to `*b`, 0 otherwise + * + * @since 1.1 + */ +LIBJ2_PURE_ inline int +libj2_ji_eq_j2i(intmax_t a, const struct libj2_j2i *b) +{ + return libj2_j2i_eq_ji(b, a); +} + + +/** + * Check whether a signed max precision integer is + * not equal to a signed double-max precision integer + * + * `libj2_ji_ne_j2i(a, b)` implements `a != *b` + * + * @param a The left-hand value + * @param b The right-hand value + * @return 1 if `a` is not equal to `*b`, 0 otherwise + * + * @since 1.1 + */ +LIBJ2_PURE_ inline int +libj2_ji_ne_j2i(intmax_t a, const struct libj2_j2i *b) +{ + return libj2_j2i_ne_ji(b, a); +} + + + + + +/** + * Get the maximum of two signed double-max + * precision integers + * + * `libj2_j2i_max_j2i_to_ji2(a, b, res)` implements + * `*res = *a > *b ? *a : *b` + * + * @param a One of the values + * @param b The other value + * @param res Output parameter for the maximum of `*a` and `*b` + * + * @since 1.1 + */ +inline void +libj2_j2i_max_j2i_to_j2i(const struct libj2_j2i *a, const struct libj2_j2i *b, struct libj2_j2i *res) +{ + *res = libj2_j2i_gt_j2i(a, b) ? *a : *b; +} + + +/** + * Get the maximum of two signed double-max + * precision integers + * + * `libj2_j2i_max_j2i(a, b)` implements + * `*a = *a > *b ? *a : *b` + * + * @param a One of the values, and output parameter + * for the maximum of `*a` and `*b` + * @param b The other value + * + * @since 1.1 + */ +inline void +libj2_j2i_max_j2i(struct libj2_j2i *a, const struct libj2_j2i *b) +{ + if (libj2_j2i_gt_j2i(b, a)) + *a = *b; +} + + +/** + * Get the maximum of a signed double-max + * precision integer and a signed precision + * integer + * + * `libj2_j2i_max_ji(a, b)` implements + * `*a = *a > b ? *a : b` + * + * @param a One of the values, and output parameter + * for the maximum of `*a` and `b` + * @param b The other value + * + * @since 1.1 + */ +inline void +libj2_j2i_max_ji(struct libj2_j2i *a, intmax_t b) +{ + if (libj2_j2i_lt_ji(a, b)) + libj2_ji_to_j2i(b, a); +} + + +/** + * Get the maximum of a signed double-max + * precision integer and a signed precision + * integer + * + * `libj2_j2i_max_ji_to_j2i(a, b, res)` implements + * `*res = *a > b ? *a : b` + * + * @param a One of the values + * @param b The other value + * @param res Output parameter for the maximum of `*a` and `b` + * + * @since 1.1 + */ +inline void +libj2_j2i_max_ji_to_j2i(const struct libj2_j2i *a, intmax_t b, struct libj2_j2i *res) +{ + if (libj2_j2i_lt_ji(a, b)) + libj2_ji_to_j2i(b, res); + else + *res = *a; +} + + +/** + * Get the minimum of two signed double-max + * precision integers + * + * `libj2_j2i_min_j2i_to_ji2(a, b, res)` implements + * `*res = *a < *b ? *a : *b` + * + * @param a One of the values + * @param b The other value + * @param res Output parameter for the minimum of `*a` and `*b` + * + * @since 1.1 + */ +inline void +libj2_j2i_min_j2i_to_j2i(const struct libj2_j2i *a, const struct libj2_j2i *b, struct libj2_j2i *res) +{ + *res = libj2_j2i_lt_j2i(a, b) ? *a : *b; +} + + +/** + * Get the minimum of two signed double-max + * precision integers + * + * `libj2_j2i_min_j2i(a, b)` implements + * `*a = *a < *b ? *a : *b` + * + * @param a One of the values, and output parameter + * for the minimum of `*a` and `*b` + * @param b The other value + * + * @since 1.1 + */ +inline void +libj2_j2i_min_j2i(struct libj2_j2i *a, const struct libj2_j2i *b) +{ + if (libj2_j2i_lt_j2i(b, a)) + *a = *b; +} + + +/** + * Get the minimum of a signed double-max + * precision integer and a signed precision + * integer + * + * `libj2_j2i_min_ji(a, b)` implements + * `*a = *a < b ? *a : b` + * + * @param a One of the values, and output parameter + * for the minimum of `*a` and `b` + * @param b The other value + * + * @since 1.1 + */ +inline void +libj2_j2i_min_ji(struct libj2_j2i *a, intmax_t b) +{ + if (libj2_j2i_gt_ji(a, b)) + libj2_ji_to_j2i(b, a); +} + + +/** + * Get the minimum of a signed double-max + * precision integer and a signed precision + * integer + * + * `libj2_j2i_min_ji_to_j2i(a, b, res)` implements + * `*res = *a < b ? *a : b` + * + * @param a One of the values + * @param b The other value + * @param res Output parameter for the minimum of `*a` and `b` + * + * @since 1.1 + */ +inline void +libj2_j2i_min_ji_to_j2i(const struct libj2_j2i *a, intmax_t b, struct libj2_j2i *res) +{ + if (libj2_j2i_gt_ji(a, b)) + libj2_ji_to_j2i(b, res); + else + *res = *a; +} + + +/** + * Get the maximum of a set of signed double-max + * precision integers + * + * @param a One of the values, and output parameter for + * the maximum of the values + * @param args `NULL` terminated list of additional values; each + * argument shall have the type `const struct libj2_j2i *` + * + * @since 1.1 + */ +inline void +libj2_vmax_j2i(struct libj2_j2i *a, va_list args) +{ + const struct libj2_j2i *b; + while ((b = va_arg(args, const struct libj2_j2i *))) + libj2_j2i_max_j2i(a, b); +} + + +/** + * Get the maximum of a set of signed double-max + * precision integers + * + * @param a One of the values, and output parameter for + * the maximum of the values + * @param ... `NULL` terminated list of additional values; each + * argument shall have the type `const struct libj2_j2i *` + * + * @since 1.1 + */ +inline void +libj2_max_j2i(struct libj2_j2i *a, ... /*, NULL */) +{ + va_list args; + va_start(args, a); + libj2_vmax_j2i(a, args); + va_end(args); +} + + +/** + * Get the maximum of a set of signed double-max + * precision integers + * + * @param a One of the values + * @param args `NULL` terminated list of additional values; each + * argument shall have the type `const struct libj2_j2i *` + * @return One of the `const struct libj2_j2i *` that as the + * maximum of the values of each argument + * + * @since 1.1 + */ +inline const struct libj2_j2i * +libj2_vmax_j2i_return(const struct libj2_j2i *a, va_list args) +{ + const struct libj2_j2i *b; + while ((b = va_arg(args, const struct libj2_j2i *))) + if (libj2_j2i_gt_j2i(b, a)) + a = b; + return a; +} + + +/** + * Get the maximum of a set of signed double-max + * precision integers + * + * @param a One of the values + * @param ... `NULL` terminated list of additional values; each + * argument shall have the type `const struct libj2_j2i *` + * @return One of the `const struct libj2_j2i *` that as the + * maximum of the values of each argument + * + * @since 1.1 + */ +LIBJ2_PURE_ inline const struct libj2_j2i * +libj2_max_j2i_return(const struct libj2_j2i *a, ... /*, NULL */) +{ + va_list args; + va_start(args, a); + return libj2_vmax_j2i_return(a, args); + va_end(args); +} + + +/** + * Get the maximum of a set of signed double-max + * precision integers + * + * @param a One of the values + * @param args `NULL` terminated list of additional values, each + * argument shall have the type `const struct libj2_j2i *`, + * followed by a `struct libj2_j2i *` is used as the + * output parameter for the maximum of the values + * + * @since 1.1 + */ +inline void +libj2_vmax_j2i_to_j2i(const struct libj2_j2i *a, va_list args) +{ + struct libj2_j2i *res; + a = libj2_vmax_j2i_return(a, args); + res = va_arg(args, struct libj2_j2i *); + *res = *a; +} + + +/** + * Get the maximum of a set of signed double-max + * precision integers + * + * @param a One of the values + * @param ... `NULL` terminated list of additional values, each + * argument shall have the type `const struct libj2_j2i *`, + * followed by a `struct libj2_j2i *` is used as the + * output parameter for the maximum of the values + * + * @since 1.1 + */ +inline void +libj2_max_j2i_to_j2i(const struct libj2_j2i *a, ... /*, NULL, struct libj2_j2i *res */) +{ + va_list args; + va_start(args, a); + libj2_vmax_j2i_to_j2i(a, args); + va_end(args); +} + + +/** + * Get the minimum of a set of signed double-max + * precision integers + * + * @param a One of the values, and output parameter for + * the minimum of the values + * @param args `NULL` terminated list of additional values; each + * argument shall have the type `const struct libj2_j2i *` + * + * @since 1.1 + */ +inline void +libj2_vmin_j2i(struct libj2_j2i *a, va_list args) +{ + const struct libj2_j2i *b; + while ((b = va_arg(args, const struct libj2_j2i *))) + libj2_j2i_min_j2i(a, b); +} + + +/** + * Get the minimum of a set of signed double-max + * precision integers + * + * @param a One of the values, and output parameter for + * the minimum of the values + * @param ... `NULL` terminated list of additional values; each + * argument shall have the type `const struct libj2_j2i *` + * + * @since 1.1 + */ +inline void +libj2_min_j2i(struct libj2_j2i *a, ... /*, NULL */) +{ + va_list args; + va_start(args, a); + libj2_vmin_j2i(a, args); + va_end(args); +} + + +/** + * Get the minimum of a set of signed double-max + * precision integers + * + * @param a One of the values + * @param args `NULL` terminated list of additional values; each + * argument shall have the type `const struct libj2_j2i *` + * @return One of the `const struct libj2_j2i *` that as the + * minimum of the values of each argument + * + * @since 1.1 + */ +inline const struct libj2_j2i * +libj2_vmin_j2i_return(const struct libj2_j2i *a, va_list args) +{ + const struct libj2_j2i *b; + while ((b = va_arg(args, const struct libj2_j2i *))) + if (libj2_j2i_lt_j2i(b, a)) + a = b; + return a; +} + + +/** + * Get the minimum of a set of signed double-max + * precision integers + * + * @param a One of the values + * @param ... `NULL` terminated list of additional values; each + * argument shall have the type `const struct libj2_j2i *` + * @return One of the `const struct libj2_j2i *` that as the + * minimum of the values of each argument + * + * @since 1.1 + */ +LIBJ2_PURE_ inline const struct libj2_j2i * +libj2_min_j2i_return(const struct libj2_j2i *a, ... /*, NULL */) +{ + va_list args; + va_start(args, a); + return libj2_vmin_j2i_return(a, args); + va_end(args); +} + + +/** + * Get the minimum of a set of signed double-max + * precision integers + * + * @param a One of the values + * @param args `NULL` terminated list of additional values, each + * argument shall have the type `const struct libj2_j2i *`, + * followed by a `struct libj2_j2i *` is used as the + * output parameter for the minimum of the values + * + * @since 1.1 + */ +inline void +libj2_vmin_j2i_to_j2i(const struct libj2_j2i *a, va_list args) +{ + struct libj2_j2i *res; + a = libj2_vmin_j2i_return(a, args); + res = va_arg(args, struct libj2_j2i *); + *res = *a; +} + + +/** + * Get the minimum of a set of signed double-max + * precision integers + * + * @param a One of the values + * @param ... `NULL` terminated list of additional values, each + * argument shall have the type `const struct libj2_j2i *`, + * followed by a `struct libj2_j2i *` is used as the + * output parameter for the minimum of the values + * + * @since 1.1 + */ +inline void +libj2_min_j2i_to_j2i(const struct libj2_j2i *a, ... /*, NULL, struct libj2_j2i *res */) +{ + va_list args; + va_start(args, a); + libj2_vmin_j2i_to_j2i(a, args); + va_end(args); +} diff --git a/libj2/signed-comparsion.h b/libj2/signed-comparsion.h deleted file mode 100644 index 1bed2f1..0000000 --- a/libj2/signed-comparsion.h +++ /dev/null @@ -1,858 +0,0 @@ -/* See LICENSE file for copyright and license details. */ -#ifndef LIBJ2_H -# error Do not include this header directly, include instead -#endif - - -/** - * Compare a signed double-max precision integer - * against another signed double-max precision integer - * - * `libj2_j2i_cmp_j2i(a, b)` implements `*a < *b ? -1 : *a > *b ? +1 : 0`, - * or equivalently, the signum of `*a - *b` where the signum is 0 for 0 - * - * @param a The left-hand value - * @param b The right-hand value - * @return -1 if `*a` is less than `*b`, - * +1 if `*a` is greater than `*b`, - * 0 if `*a` is equal to `*b` - * - * @since 1.1 - */ -LIBJ2_PURE_ inline int -libj2_j2i_cmp_j2i(const struct libj2_j2i *a, const struct libj2_j2i *b) -{ - int cmp = libj2_sgn_j2i(a) - libj2_sgn_j2i(b); - if (cmp) - return cmp < 0 ? -1 : +1; - return libj2_j2u_cmp_j2u((const void *)a, (const void *)b); -} - - -/** - * Check whether a signed double-max precision integer is - * less than another signed double-max precision integer - * - * `libj2_j2i_lt_j2i(a, b)` implements `*a < *b` - * - * @param a The left-hand value - * @param b The right-hand value - * @return 1 if `*a` is less than `*b`, 0 otherwise - * - * @since 1.1 - */ -LIBJ2_PURE_ inline int -libj2_j2i_lt_j2i(const struct libj2_j2i *a, const struct libj2_j2i *b) -{ - return libj2_j2i_cmp_j2i(a, b) < 0; -} - - -/** - * Check whether a signed double-max precision integer is less - * than or equal to another signed double-max precision integer - * - * `libj2_j2i_le_j2i(a, b)` implements `*a <= *b` - * - * @param a The left-hand value - * @param b The right-hand value - * @return 1 if `*a` is less than or equal to `*b`, 0 otherwise - * - * @since 1.1 - */ -LIBJ2_PURE_ inline int -libj2_j2i_le_j2i(const struct libj2_j2i *a, const struct libj2_j2i *b) -{ - return libj2_j2i_cmp_j2i(a, b) <= 0; -} - - -/** - * Check whether a signed double-max precision integer is - * greater than another signed double-max precision integer - * - * `libj2_j2i_gt_j2i(a, b)` implements `*a > *b` - * - * @param a The left-hand value - * @param b The right-hand value - * @return 1 if `*a` is greater than `*b`, 0 otherwise - * - * @since 1.1 - */ -LIBJ2_PURE_ inline int -libj2_j2i_gt_j2i(const struct libj2_j2i *a, const struct libj2_j2i *b) -{ - return libj2_j2i_cmp_j2i(a, b) > 0; -} - - -/** - * Check whether a signed double-max precision integer is greater - * than or equal to another signed double-max precision integer - * - * `libj2_j2i_ge_j2i(a, b)` implements `*a >= *b` - * - * @param a The left-hand value - * @param b The right-hand value - * @return 1 if `*a` is greater than or equal to `*b`, 0 otherwise - * - * @since 1.1 - */ -LIBJ2_PURE_ inline int -libj2_j2i_ge_j2i(const struct libj2_j2i *a, const struct libj2_j2i *b) -{ - return libj2_j2i_cmp_j2i(a, b) >= 0; -} - - -/** - * Check whether a signed double-max precision integer is - * equal to another signed double-max precision integer - * - * `libj2_j2i_eq_j2i(a, b)` implements `*a == *b` - * - * @param a The left-hand value - * @param b The right-hand value - * @return 1 if `*a` is equal to `*b`, 0 otherwise - * - * @since 1.1 - */ -LIBJ2_PURE_ inline int -libj2_j2i_eq_j2i(const struct libj2_j2i *a, const struct libj2_j2i *b) -{ - return libj2_j2u_eq_j2u((const void *)a, (const void *)b); -} - - -/** - * Check whether a signed double-max precision integer is - * not equal to another signed double-max precision integer - * - * `libj2_j2i_ne_j2i(a, b)` implements `*a != *b` - * - * @param a The left-hand value - * @param b The right-hand value - * @return 1 if `*a` is not equal to `*b`, 0 otherwise - * - * @since 1.1 - */ -LIBJ2_PURE_ inline int -libj2_j2i_ne_j2i(const struct libj2_j2i *a, const struct libj2_j2i *b) -{ - return libj2_j2u_ne_j2u((const void *)a, (const void *)b); -} - - -/** - * Compare a signed double-max precision integer - * against a signed max precision integer - * - * `libj2_j2i_cmp_ji(a, b)` implements `*a < b ? -1 : *a > b ? +1 : 0`, - * or equivalently, the signum of `*a - b` where the signum is 0 for 0 - * - * @param a The left-hand value - * @param b The right-hand value - * @return -1 if `*a` is less than `b`, - * +1 if `*a` is greater than `b`, - * 0 if `*a` is equal to `b` - * - * @since 1.1 - */ -LIBJ2_PURE_ inline int -libj2_j2i_cmp_ji(const struct libj2_j2i *a, intmax_t b) -{ - struct libj2_j2i t; - libj2_ji_to_j2i(b, &t); - return libj2_j2i_cmp_j2i(a, &t); -} - - -/** - * Check whether a signed double-max precision integer - * is less than a signed max precision integer - * - * `libj2_j2i_lt_ji(a, b)` implements `*a < b` - * - * @param a The left-hand value - * @param b The right-hand value - * @return 1 if `*a` is less than `b`, 0 otherwise - * - * @since 1.1 - */ -LIBJ2_PURE_ inline int -libj2_j2i_lt_ji(const struct libj2_j2i *a, intmax_t b) -{ - return libj2_j2i_cmp_ji(a, b) < 0; -} - - -/** - * Check whether a signed double-max precision integer is - * less than or equal to a signed max precision integer - * - * `libj2_j2i_le_ji(a, b)` implements `*a <= b` - * - * @param a The left-hand value - * @param b The right-hand value - * @return 1 if `*a` is less than or equal to `b`, 0 otherwise - * - * @since 1.1 - */ -LIBJ2_PURE_ inline int -libj2_j2i_le_ji(const struct libj2_j2i *a, intmax_t b) -{ - return libj2_j2i_cmp_ji(a, b) <= 0; -} - - -/** - * Check whether a signed double-max precision integer - * is greater than a signed max precision integer - * - * `libj2_j2i_gt_ji(a, b)` implements `*a > b` - * - * @param a The left-hand value - * @param b The right-hand value - * @return 1 if `*a` is less than `b`, 0 otherwise - * - * @since 1.1 - */ -LIBJ2_PURE_ inline int -libj2_j2i_gt_ji(const struct libj2_j2i *a, intmax_t b) -{ - return libj2_j2i_cmp_ji(a, b) > 0; -} - - -/** - * Check whether a signed double-max precision integer is - * greater than or equal to a signed max precision integer - * - * `libj2_j2i_ge_ji(a, b)` implements `*a >= b` - * - * @param a The left-hand value - * @param b The right-hand value - * @return 1 if `*a` is greater than or equal to `b`, 0 otherwise - * - * @since 1.1 - */ -LIBJ2_PURE_ inline int -libj2_j2i_ge_ji(const struct libj2_j2i *a, intmax_t b) -{ - return libj2_j2i_cmp_ji(a, b) >= 0; -} - - -/** - * Check whether a signed double-max precision integer - * is equal to a signed max precision integer - * - * `libj2_j2i_eq_ji(a, b)` implements `*a == b` - * - * @param a The left-hand value - * @param b The right-hand value - * @return 1 if `*a` is equal to `b`, 0 otherwise - * - * @since 1.1 - */ -LIBJ2_PURE_ inline int -libj2_j2i_eq_ji(const struct libj2_j2i *a, intmax_t b) -{ - if (b >= 0) - return !a->high && a->low == (uintmax_t)b; - return a->high == UINTMAX_MAX && a->low == ~(uintmax_t)-(b + 1); -} - - -/** - * Check whether a signed double-max precision integer - * is not equal to a signed max precision integer - * - * `libj2_j2i_ne_ji(a, b)` implements `*a != b` - * - * @param a The left-hand value - * @param b The right-hand value - * @return 1 if `*a` is not equal to `b`, 0 otherwise - * - * @since 1.1 - */ -LIBJ2_PURE_ inline int -libj2_j2i_ne_ji(const struct libj2_j2i *a, intmax_t b) -{ - return !libj2_j2i_eq_ji(a, b); -} - - -/** - * Compare a signed max precision integer - * against a signed double-max precision integer - * - * `libj2_ji_cmp_j2i(a, b)` implements `a < *b ? -1 : a > *b ? +1 : 0`, - * or equivalently, the signum of `a - *b` where the signum is 0 for 0 - * - * @param a The left-hand value - * @param b The right-hand value - * @return -1 if `a` is less than `*b`, - * +1 if `a` is greater than `*b`, - * 0 if `a` is equal to `*b` - * - * @since 1.1 - */ -LIBJ2_PURE_ inline int -libj2_ji_cmp_j2i(intmax_t a, const struct libj2_j2i *b) -{ - struct libj2_j2i t; - libj2_ji_to_j2i(a, &t); - return libj2_j2i_cmp_j2i(&t, b); -} - - -/** - * Check whether a signed max precision integer is - * less than a signed double-max precision integer - * - * `libj2_ji_lt_j2i(a, b)` implements `a < *b` - * - * @param a The left-hand value - * @param b The right-hand value - * @return 1 if `a` is less than `*b`, 0 otherwise - * - * @since 1.1 - */ -LIBJ2_PURE_ inline int -libj2_ji_lt_j2i(intmax_t a, const struct libj2_j2i *b) -{ - return libj2_j2i_gt_ji(b, a); -} - - -/** - * Check whether a signed max precision integer is less - * than or equal to a signed double-max precision integer - * - * `libj2_ji_le_j2i(a, b)` implements `a <= *b` - * - * @param a The left-hand value - * @param b The right-hand value - * @return 1 if `a` is less than or equal to `*b`, 0 otherwise - * - * @since 1.1 - */ -LIBJ2_PURE_ inline int -libj2_ji_le_j2i(intmax_t a, const struct libj2_j2i *b) -{ - return libj2_j2i_ge_ji(b, a); -} - - -/** - * Check whether a signed max precision integer is - * greater than a signed double-max precision integer - * - * `libj2_ji_gt_j2i(a, b)` implements `a > *b` - * - * @param a The left-hand value - * @param b The right-hand value - * @return 1 if `a` is less than `*b`, 0 otherwise - * - * @since 1.1 - */ -LIBJ2_PURE_ inline int -libj2_ji_gt_j2i(intmax_t a, const struct libj2_j2i *b) -{ - return libj2_j2i_lt_ji(b, a); -} - - -/** - * Check whether a signed max precision integer is greater - * than or equal to a signed double-max precision integer - * - * `libj2_ji_ge_j2i(a, b)` implements `a >= *b` - * - * @param a The left-hand value - * @param b The right-hand value - * @return 1 if `a` is greater than or equal to `*b`, 0 otherwise - * - * @since 1.1 - */ -LIBJ2_PURE_ inline int -libj2_ji_ge_j2i(intmax_t a, const struct libj2_j2i *b) -{ - return libj2_j2i_le_ji(b, a); -} - - -/** - * Check whether a signed max precision integer is - * equal to a signed double-max precision integer - * - * `libj2_ji_eq_j2i(a, b)` implements `a == *b` - * - * @param a The left-hand value - * @param b The right-hand value - * @return 1 if `a` is equal to `*b`, 0 otherwise - * - * @since 1.1 - */ -LIBJ2_PURE_ inline int -libj2_ji_eq_j2i(intmax_t a, const struct libj2_j2i *b) -{ - return libj2_j2i_eq_ji(b, a); -} - - -/** - * Check whether a signed max precision integer is - * not equal to a signed double-max precision integer - * - * `libj2_ji_ne_j2i(a, b)` implements `a != *b` - * - * @param a The left-hand value - * @param b The right-hand value - * @return 1 if `a` is not equal to `*b`, 0 otherwise - * - * @since 1.1 - */ -LIBJ2_PURE_ inline int -libj2_ji_ne_j2i(intmax_t a, const struct libj2_j2i *b) -{ - return libj2_j2i_ne_ji(b, a); -} - - - - - -/** - * Get the maximum of two signed double-max - * precision integers - * - * `libj2_j2i_max_j2i_to_ji2(a, b, res)` implements - * `*res = *a > *b ? *a : *b` - * - * @param a One of the values - * @param b The other value - * @param res Output parameter for the maximum of `*a` and `*b` - * - * @since 1.1 - */ -inline void -libj2_j2i_max_j2i_to_j2i(const struct libj2_j2i *a, const struct libj2_j2i *b, struct libj2_j2i *res) -{ - *res = libj2_j2i_gt_j2i(a, b) ? *a : *b; -} - - -/** - * Get the maximum of two signed double-max - * precision integers - * - * `libj2_j2i_max_j2i(a, b)` implements - * `*a = *a > *b ? *a : *b` - * - * @param a One of the values, and output parameter - * for the maximum of `*a` and `*b` - * @param b The other value - * - * @since 1.1 - */ -inline void -libj2_j2i_max_j2i(struct libj2_j2i *a, const struct libj2_j2i *b) -{ - if (libj2_j2i_gt_j2i(b, a)) - *a = *b; -} - - -/** - * Get the maximum of a signed double-max - * precision integer and a signed precision - * integer - * - * `libj2_j2i_max_ji(a, b)` implements - * `*a = *a > b ? *a : b` - * - * @param a One of the values, and output parameter - * for the maximum of `*a` and `b` - * @param b The other value - * - * @since 1.1 - */ -inline void -libj2_j2i_max_ji(struct libj2_j2i *a, intmax_t b) -{ - if (libj2_j2i_lt_ji(a, b)) - libj2_ji_to_j2i(b, a); -} - - -/** - * Get the maximum of a signed double-max - * precision integer and a signed precision - * integer - * - * `libj2_j2i_max_ji_to_j2i(a, b, res)` implements - * `*res = *a > b ? *a : b` - * - * @param a One of the values - * @param b The other value - * @param res Output parameter for the maximum of `*a` and `b` - * - * @since 1.1 - */ -inline void -libj2_j2i_max_ji_to_j2i(const struct libj2_j2i *a, intmax_t b, struct libj2_j2i *res) -{ - if (libj2_j2i_lt_ji(a, b)) - libj2_ji_to_j2i(b, res); - else - *res = *a; -} - - -/** - * Get the minimum of two signed double-max - * precision integers - * - * `libj2_j2i_min_j2i_to_ji2(a, b, res)` implements - * `*res = *a < *b ? *a : *b` - * - * @param a One of the values - * @param b The other value - * @param res Output parameter for the minimum of `*a` and `*b` - * - * @since 1.1 - */ -inline void -libj2_j2i_min_j2i_to_j2i(const struct libj2_j2i *a, const struct libj2_j2i *b, struct libj2_j2i *res) -{ - *res = libj2_j2i_lt_j2i(a, b) ? *a : *b; -} - - -/** - * Get the minimum of two signed double-max - * precision integers - * - * `libj2_j2i_min_j2i(a, b)` implements - * `*a = *a < *b ? *a : *b` - * - * @param a One of the values, and output parameter - * for the minimum of `*a` and `*b` - * @param b The other value - * - * @since 1.1 - */ -inline void -libj2_j2i_min_j2i(struct libj2_j2i *a, const struct libj2_j2i *b) -{ - if (libj2_j2i_lt_j2i(b, a)) - *a = *b; -} - - -/** - * Get the minimum of a signed double-max - * precision integer and a signed precision - * integer - * - * `libj2_j2i_min_ji(a, b)` implements - * `*a = *a < b ? *a : b` - * - * @param a One of the values, and output parameter - * for the minimum of `*a` and `b` - * @param b The other value - * - * @since 1.1 - */ -inline void -libj2_j2i_min_ji(struct libj2_j2i *a, intmax_t b) -{ - if (libj2_j2i_gt_ji(a, b)) - libj2_ji_to_j2i(b, a); -} - - -/** - * Get the minimum of a signed double-max - * precision integer and a signed precision - * integer - * - * `libj2_j2i_min_ji_to_j2i(a, b, res)` implements - * `*res = *a < b ? *a : b` - * - * @param a One of the values - * @param b The other value - * @param res Output parameter for the minimum of `*a` and `b` - * - * @since 1.1 - */ -inline void -libj2_j2i_min_ji_to_j2i(const struct libj2_j2i *a, intmax_t b, struct libj2_j2i *res) -{ - if (libj2_j2i_gt_ji(a, b)) - libj2_ji_to_j2i(b, res); - else - *res = *a; -} - - -/** - * Get the maximum of a set of signed double-max - * precision integers - * - * @param a One of the values, and output parameter for - * the maximum of the values - * @param args `NULL` terminated list of additional values; each - * argument shall have the type `const struct libj2_j2i *` - * - * @since 1.1 - */ -inline void -libj2_vmax_j2i(struct libj2_j2i *a, va_list args) -{ - const struct libj2_j2i *b; - while ((b = va_arg(args, const struct libj2_j2i *))) - libj2_j2i_max_j2i(a, b); -} - - -/** - * Get the maximum of a set of signed double-max - * precision integers - * - * @param a One of the values, and output parameter for - * the maximum of the values - * @param ... `NULL` terminated list of additional values; each - * argument shall have the type `const struct libj2_j2i *` - * - * @since 1.1 - */ -inline void -libj2_max_j2i(struct libj2_j2i *a, ... /*, NULL */) -{ - va_list args; - va_start(args, a); - libj2_vmax_j2i(a, args); - va_end(args); -} - - -/** - * Get the maximum of a set of signed double-max - * precision integers - * - * @param a One of the values - * @param args `NULL` terminated list of additional values; each - * argument shall have the type `const struct libj2_j2i *` - * @return One of the `const struct libj2_j2i *` that as the - * maximum of the values of each argument - * - * @since 1.1 - */ -inline const struct libj2_j2i * -libj2_vmax_j2i_return(const struct libj2_j2i *a, va_list args) -{ - const struct libj2_j2i *b; - while ((b = va_arg(args, const struct libj2_j2i *))) - if (libj2_j2i_gt_j2i(b, a)) - a = b; - return a; -} - - -/** - * Get the maximum of a set of signed double-max - * precision integers - * - * @param a One of the values - * @param ... `NULL` terminated list of additional values; each - * argument shall have the type `const struct libj2_j2i *` - * @return One of the `const struct libj2_j2i *` that as the - * maximum of the values of each argument - * - * @since 1.1 - */ -LIBJ2_PURE_ inline const struct libj2_j2i * -libj2_max_j2i_return(const struct libj2_j2i *a, ... /*, NULL */) -{ - va_list args; - va_start(args, a); - return libj2_vmax_j2i_return(a, args); - va_end(args); -} - - -/** - * Get the maximum of a set of signed double-max - * precision integers - * - * @param a One of the values - * @param args `NULL` terminated list of additional values, each - * argument shall have the type `const struct libj2_j2i *`, - * followed by a `struct libj2_j2i *` is used as the - * output parameter for the maximum of the values - * - * @since 1.1 - */ -inline void -libj2_vmax_j2i_to_j2i(const struct libj2_j2i *a, va_list args) -{ - struct libj2_j2i *res; - a = libj2_vmax_j2i_return(a, args); - res = va_arg(args, struct libj2_j2i *); - *res = *a; -} - - -/** - * Get the maximum of a set of signed double-max - * precision integers - * - * @param a One of the values - * @param ... `NULL` terminated list of additional values, each - * argument shall have the type `const struct libj2_j2i *`, - * followed by a `struct libj2_j2i *` is used as the - * output parameter for the maximum of the values - * - * @since 1.1 - */ -inline void -libj2_max_j2i_to_j2i(const struct libj2_j2i *a, ... /*, NULL, struct libj2_j2i *res */) -{ - va_list args; - va_start(args, a); - libj2_vmax_j2i_to_j2i(a, args); - va_end(args); -} - - -/** - * Get the minimum of a set of signed double-max - * precision integers - * - * @param a One of the values, and output parameter for - * the minimum of the values - * @param args `NULL` terminated list of additional values; each - * argument shall have the type `const struct libj2_j2i *` - * - * @since 1.1 - */ -inline void -libj2_vmin_j2i(struct libj2_j2i *a, va_list args) -{ - const struct libj2_j2i *b; - while ((b = va_arg(args, const struct libj2_j2i *))) - libj2_j2i_min_j2i(a, b); -} - - -/** - * Get the minimum of a set of signed double-max - * precision integers - * - * @param a One of the values, and output parameter for - * the minimum of the values - * @param ... `NULL` terminated list of additional values; each - * argument shall have the type `const struct libj2_j2i *` - * - * @since 1.1 - */ -inline void -libj2_min_j2i(struct libj2_j2i *a, ... /*, NULL */) -{ - va_list args; - va_start(args, a); - libj2_vmin_j2i(a, args); - va_end(args); -} - - -/** - * Get the minimum of a set of signed double-max - * precision integers - * - * @param a One of the values - * @param args `NULL` terminated list of additional values; each - * argument shall have the type `const struct libj2_j2i *` - * @return One of the `const struct libj2_j2i *` that as the - * minimum of the values of each argument - * - * @since 1.1 - */ -inline const struct libj2_j2i * -libj2_vmin_j2i_return(const struct libj2_j2i *a, va_list args) -{ - const struct libj2_j2i *b; - while ((b = va_arg(args, const struct libj2_j2i *))) - if (libj2_j2i_lt_j2i(b, a)) - a = b; - return a; -} - - -/** - * Get the minimum of a set of signed double-max - * precision integers - * - * @param a One of the values - * @param ... `NULL` terminated list of additional values; each - * argument shall have the type `const struct libj2_j2i *` - * @return One of the `const struct libj2_j2i *` that as the - * minimum of the values of each argument - * - * @since 1.1 - */ -LIBJ2_PURE_ inline const struct libj2_j2i * -libj2_min_j2i_return(const struct libj2_j2i *a, ... /*, NULL */) -{ - va_list args; - va_start(args, a); - return libj2_vmin_j2i_return(a, args); - va_end(args); -} - - -/** - * Get the minimum of a set of signed double-max - * precision integers - * - * @param a One of the values - * @param args `NULL` terminated list of additional values, each - * argument shall have the type `const struct libj2_j2i *`, - * followed by a `struct libj2_j2i *` is used as the - * output parameter for the minimum of the values - * - * @since 1.1 - */ -inline void -libj2_vmin_j2i_to_j2i(const struct libj2_j2i *a, va_list args) -{ - struct libj2_j2i *res; - a = libj2_vmin_j2i_return(a, args); - res = va_arg(args, struct libj2_j2i *); - *res = *a; -} - - -/** - * Get the minimum of a set of signed double-max - * precision integers - * - * @param a One of the values - * @param ... `NULL` terminated list of additional values, each - * argument shall have the type `const struct libj2_j2i *`, - * followed by a `struct libj2_j2i *` is used as the - * output parameter for the minimum of the values - * - * @since 1.1 - */ -inline void -libj2_min_j2i_to_j2i(const struct libj2_j2i *a, ... /*, NULL, struct libj2_j2i *res */) -{ - va_list args; - va_start(args, a); - libj2_vmin_j2i_to_j2i(a, args); - va_end(args); -} diff --git a/libj2/unsigned-comparison.h b/libj2/unsigned-comparison.h new file mode 100644 index 0000000..c13397a --- /dev/null +++ b/libj2/unsigned-comparison.h @@ -0,0 +1,855 @@ +/* See LICENSE file for copyright and license details. */ +#ifndef LIBJ2_H +# error Do not include this header directly, include instead +#endif + + +/** + * Check whether an unsigned double-max precision integer is + * less than another unsigned double-max precision integer + * + * `libj2_j2u_lt_j2u(a, b)` implements `*a < *b` + * + * @param a The left-hand value + * @param b The right-hand value + * @return 1 if `*a` is less than `*b`, 0 otherwise + * + * @since 1.0 + */ +LIBJ2_PURE_ inline int +libj2_j2u_lt_j2u(const struct libj2_j2u *a, const struct libj2_j2u *b) +{ + return a->high < b->high || (a->high == b->high && a->low < b->low); +} + + +/** + * Check whether an unsigned double-max precision integer is less + * than or equal to another unsigned double-max precision integer + * + * `libj2_j2u_le_j2u(a, b)` implements `*a <= *b` + * + * @param a The left-hand value + * @param b The right-hand value + * @return 1 if `*a` is less than or equal to `*b`, 0 otherwise + * + * @since 1.0 + */ +LIBJ2_PURE_ inline int +libj2_j2u_le_j2u(const struct libj2_j2u *a, const struct libj2_j2u *b) +{ + return a->high < b->high || (a->high == b->high && a->low <= b->low); +} + + +/** + * Check whether an unsigned double-max precision integer is + * greater than another unsigned double-max precision integer + * + * `libj2_j2u_gt_j2u(a, b)` implements `*a > *b` + * + * @param a The left-hand value + * @param b The right-hand value + * @return 1 if `*a` is greater than `*b`, 0 otherwise + * + * @since 1.0 + */ +LIBJ2_PURE_ inline int +libj2_j2u_gt_j2u(const struct libj2_j2u *a, const struct libj2_j2u *b) +{ + return a->high > b->high || (a->high == b->high && a->low > b->low); +} + + +/** + * Check whether an unsigned double-max precision integer is greater + * than or equal to another unsigned double-max precision integer + * + * `libj2_j2u_ge_j2u(a, b)` implements `*a >= *b` + * + * @param a The left-hand value + * @param b The right-hand value + * @return 1 if `*a` is greater than or equal to `*b`, 0 otherwise + * + * @since 1.0 + */ +LIBJ2_PURE_ inline int +libj2_j2u_ge_j2u(const struct libj2_j2u *a, const struct libj2_j2u *b) +{ + return a->high > b->high || (a->high == b->high && a->low >= b->low); +} + + +/** + * Check whether an unsigned double-max precision integer is + * equal to another unsigned double-max precision integer + * + * `libj2_j2u_eq_j2u(a, b)` implements `*a == *b` + * + * @param a The left-hand value + * @param b The right-hand value + * @return 1 if `*a` is equal to `*b`, 0 otherwise + * + * @since 1.0 + */ +LIBJ2_PURE_ inline int +libj2_j2u_eq_j2u(const struct libj2_j2u *a, const struct libj2_j2u *b) +{ + return a->high == b->high && a->low == b->low; +} + + +/** + * Check whether an unsigned double-max precision integer is + * not equal to another unsigned double-max precision integer + * + * `libj2_j2u_ne_j2u(a, b)` implements `*a != *b` + * + * @param a The left-hand value + * @param b The right-hand value + * @return 1 if `*a` is not equal to `*b`, 0 otherwise + * + * @since 1.0 + */ +LIBJ2_PURE_ inline int +libj2_j2u_ne_j2u(const struct libj2_j2u *a, const struct libj2_j2u *b) +{ + return a->high != b->high || a->low != b->low; +} + + +/** + * Compare an unsigned double-max precision integer + * against another unsigned double-max precision integer + * + * `libj2_j2u_cmp_j2u(a, b)` implements `*a < *b ? -1 : *a > *b ? +1 : 0`, + * or equivalently, the signum of `*a - *b` where the signum is 0 for 0 + * + * @param a The left-hand value + * @param b The right-hand value + * @return -1 if `*a` is less than `*b`, + * +1 if `*a` is greater than `*b`, + * 0 if `*a` is equal to `*b` + * + * @since 1.0 + */ +LIBJ2_PURE_ inline int +libj2_j2u_cmp_j2u(const struct libj2_j2u *a, const struct libj2_j2u *b) +{ + return a->high < b->high ? -1 : a->high > b->high ? +1 : a->low < b->low ? -1 : a->low > b->low; +} + + +/** + * Check whether an unsigned double-max precision integer + * is less than an unsigned max precision integer + * + * `libj2_j2u_lt_ju(a, b)` implements `*a < b` + * + * @param a The left-hand value + * @param b The right-hand value + * @return 1 if `*a` is less than `b`, 0 otherwise + * + * @since 1.0 + */ +LIBJ2_PURE_ inline int +libj2_j2u_lt_ju(const struct libj2_j2u *a, uintmax_t b) +{ + return !a->high && a->low < b; +} + + +/** + * Check whether an unsigned double-max precision integer is + * less than or equal to an unsigned max precision integer + * + * `libj2_j2u_le_ju(a, b)` implements `*a <= b` + * + * @param a The left-hand value + * @param b The right-hand value + * @return 1 if `*a` is less than or equal to `b`, 0 otherwise + * + * @since 1.0 + */ +LIBJ2_PURE_ inline int +libj2_j2u_le_ju(const struct libj2_j2u *a, uintmax_t b) +{ + return !a->high && a->low <= b; +} + + +/** + * Check whether an unsigned double-max precision integer + * is greater than an unsigned max precision integer + * + * `libj2_j2u_gt_ju(a, b)` implements `*a > b` + * + * @param a The left-hand value + * @param b The right-hand value + * @return 1 if `*a` is less than `b`, 0 otherwise + * + * @since 1.0 + */ +LIBJ2_PURE_ inline int +libj2_j2u_gt_ju(const struct libj2_j2u *a, uintmax_t b) +{ + return a->high || a->low > b; +} + + +/** + * Check whether an unsigned double-max precision integer is + * greater than or equal to an unsigned max precision integer + * + * `libj2_j2u_ge_ju(a, b)` implements `*a >= b` + * + * @param a The left-hand value + * @param b The right-hand value + * @return 1 if `*a` is greater than or equal to `b`, 0 otherwise + * + * @since 1.0 + */ +LIBJ2_PURE_ inline int +libj2_j2u_ge_ju(const struct libj2_j2u *a, uintmax_t b) +{ + return a->high || a->low >= b; +} + + +/** + * Check whether an unsigned double-max precision integer + * is equal to an unsigned max precision integer + * + * `libj2_j2u_eq_ju(a, b)` implements `*a == b` + * + * @param a The left-hand value + * @param b The right-hand value + * @return 1 if `*a` is equal to `b`, 0 otherwise + * + * @since 1.0 + */ +LIBJ2_PURE_ inline int +libj2_j2u_eq_ju(const struct libj2_j2u *a, uintmax_t b) +{ + return !a->high && a->low == b; +} + + +/** + * Check whether an unsigned double-max precision integer + * is not equal to an unsigned max precision integer + * + * `libj2_j2u_ne_ju(a, b)` implements `*a != b` + * + * @param a The left-hand value + * @param b The right-hand value + * @return 1 if `*a` is not equal to `b`, 0 otherwise + * + * @since 1.0 + */ +LIBJ2_PURE_ inline int +libj2_j2u_ne_ju(const struct libj2_j2u *a, uintmax_t b) +{ + return a->high || a->low != b; +} + + +/** + * Compare an unsigned double-max precision integer + * against an unsigned max precision integer + * + * `libj2_j2u_cmp_ju(a, b)` implements `*a < b ? -1 : *a > b ? +1 : 0`, + * or equivalently, the signum of `*a - b` where the signum is 0 for 0 + * + * @param a The left-hand value + * @param b The right-hand value + * @return -1 if `*a` is less than `b`, + * +1 if `*a` is greater than `b`, + * 0 if `*a` is equal to `b` + * + * @since 1.0 + */ +LIBJ2_PURE_ inline int +libj2_j2u_cmp_ju(const struct libj2_j2u *a, uintmax_t b) +{ + return a->high ? +1 : a->low < b ? -1 : a->low > b; +} + + +/** + * Check whether an unsigned max precision integer is + * less than an unsigned double-max precision integer + * + * `libj2_ju_lt_j2u(a, b)` implements `a < *b` + * + * @param a The left-hand value + * @param b The right-hand value + * @return 1 if `a` is less than `*b`, 0 otherwise + * + * @since 1.0 + */ +LIBJ2_PURE_ inline int +libj2_ju_lt_j2u(uintmax_t a, const struct libj2_j2u *b) +{ + return libj2_j2u_gt_ju(b, a); +} + + +/** + * Check whether an unsigned max precision integer is less + * than or equal to an unsigned double-max precision integer + * + * `libj2_ju_le_j2u(a, b)` implements `a <= *b` + * + * @param a The left-hand value + * @param b The right-hand value + * @return 1 if `a` is less than or equal to `*b`, 0 otherwise + * + * @since 1.0 + */ +LIBJ2_PURE_ inline int +libj2_ju_le_j2u(uintmax_t a, const struct libj2_j2u *b) +{ + return libj2_j2u_ge_ju(b, a); +} + + +/** + * Check whether an unsigned max precision integer is + * greater than an unsigned double-max precision integer + * + * `libj2_ju_gt_j2u(a, b)` implements `a > *b` + * + * @param a The left-hand value + * @param b The right-hand value + * @return 1 if `a` is less than `*b`, 0 otherwise + * + * @since 1.0 + */ +LIBJ2_PURE_ inline int +libj2_ju_gt_j2u(uintmax_t a, const struct libj2_j2u *b) +{ + return libj2_j2u_lt_ju(b, a); +} + + +/** + * Check whether an unsigned max precision integer is greater + * than or equal to an unsigned double-max precision integer + * + * `libj2_ju_ge_j2u(a, b)` implements `a >= *b` + * + * @param a The left-hand value + * @param b The right-hand value + * @return 1 if `a` is greater than or equal to `*b`, 0 otherwise + * + * @since 1.0 + */ +LIBJ2_PURE_ inline int +libj2_ju_ge_j2u(uintmax_t a, const struct libj2_j2u *b) +{ + return libj2_j2u_le_ju(b, a); +} + + +/** + * Check whether an unsigned max precision integer is + * equal to an unsigned double-max precision integer + * + * `libj2_ju_eq_j2u(a, b)` implements `a == *b` + * + * @param a The left-hand value + * @param b The right-hand value + * @return 1 if `a` is equal to `*b`, 0 otherwise + * + * @since 1.0 + */ +LIBJ2_PURE_ inline int +libj2_ju_eq_j2u(uintmax_t a, const struct libj2_j2u *b) +{ + return libj2_j2u_eq_ju(b, a); +} + + +/** + * Check whether an unsigned max precision integer is + * not equal to an unsigned double-max precision integer + * + * `libj2_ju_ne_j2u(a, b)` implements `a != *b` + * + * @param a The left-hand value + * @param b The right-hand value + * @return 1 if `a` is not equal to `*b`, 0 otherwise + * + * @since 1.0 + */ +LIBJ2_PURE_ inline int +libj2_ju_ne_j2u(uintmax_t a, const struct libj2_j2u *b) +{ + return libj2_j2u_ne_ju(b, a); +} + + +/** + * Compare an unsigned max precision integer + * against an unsigned double-max precision integer + * + * `libj2_ju_cmp_j2u(a, b)` implements `a < *b ? -1 : a > *b ? +1 : 0`, + * or equivalently, the signum of `a - *b` where the signum is 0 for 0 + * + * @param a The left-hand value + * @param b The right-hand value + * @return -1 if `a` is less than `*b`, + * +1 if `a` is greater than `*b`, + * 0 if `a` is equal to `*b` + * + * @since 1.0 + */ +LIBJ2_PURE_ inline int +libj2_ju_cmp_j2u(uintmax_t a, const struct libj2_j2u *b) +{ + return b->high ? -1 : a < b->low ? -1 : a > b->low; +} + + + + + +/** + * Get the maximum of two unsigned double-max + * precision integers + * + * `libj2_j2u_max_j2u_to_ju2(a, b, res)` implements + * `*res = *a > *b ? *a : *b` + * + * @param a One of the values + * @param b The other value + * @param res Output parameter for the maximum of `*a` and `*b` + * + * @since 1.0 + */ +inline void +libj2_j2u_max_j2u_to_j2u(const struct libj2_j2u *a, const struct libj2_j2u *b, struct libj2_j2u *res) +{ + *res = libj2_j2u_gt_j2u(a, b) ? *a : *b; +} + + +/** + * Get the maximum of two unsigned double-max + * precision integers + * + * `libj2_j2u_max_j2u(a, b)` implements + * `*a = *a > *b ? *a : *b` + * + * @param a One of the values, and output parameter + * for the maximum of `*a` and `*b` + * @param b The other value + * + * @since 1.0 + */ +inline void +libj2_j2u_max_j2u(struct libj2_j2u *a, const struct libj2_j2u *b) +{ + if (libj2_j2u_gt_j2u(b, a)) + *a = *b; +} + + +/** + * Get the maximum of an unsigned double-max + * precision integer and an unsigned precision + * integer + * + * `libj2_j2u_max_ju(a, b)` implements + * `*a = *a > b ? *a : b` + * + * @param a One of the values, and output parameter + * for the maximum of `*a` and `b` + * @param b The other value + * + * @since 1.0 + */ +inline void +libj2_j2u_max_ju(struct libj2_j2u *a, uintmax_t b) +{ + if (!a->high && a->low < b) + a->low = b; +} + + +/** + * Get the maximum of an unsigned double-max + * precision integer and an unsigned precision + * integer + * + * `libj2_j2u_max_ju_to_j2u(a, b, res)` implements + * `*res = *a > b ? *a : b` + * + * @param a One of the values + * @param b The other value + * @param res Output parameter for the maximum of `*a` and `b` + * + * @since 1.0 + */ +inline void +libj2_j2u_max_ju_to_j2u(const struct libj2_j2u *a, uintmax_t b, struct libj2_j2u *res) +{ + if (!a->high && a->low < b) { + res->high = 0; + res->low = b; + } else { + *res = *a; + } +} + + +/** + * Get the minimum of two unsigned double-max + * precision integers + * + * `libj2_j2u_min_j2u_to_ju2(a, b, res)` implements + * `*res = *a < *b ? *a : *b` + * + * @param a One of the values + * @param b The other value + * @param res Output parameter for the minimum of `*a` and `*b` + * + * @since 1.0 + */ +inline void +libj2_j2u_min_j2u_to_j2u(const struct libj2_j2u *a, const struct libj2_j2u *b, struct libj2_j2u *res) +{ + *res = libj2_j2u_lt_j2u(a, b) ? *a : *b; +} + + +/** + * Get the minimum of two unsigned double-max + * precision integers + * + * `libj2_j2u_min_j2u(a, b)` implements + * `*a = *a < *b ? *a : *b` + * + * @param a One of the values, and output parameter + * for the minimum of `*a` and `*b` + * @param b The other value + * + * @since 1.0 + */ +inline void +libj2_j2u_min_j2u(struct libj2_j2u *a, const struct libj2_j2u *b) +{ + if (libj2_j2u_lt_j2u(b, a)) + *a = *b; +} + + +/** + * Get the minimum of an unsigned double-max + * precision integer and an unsigned precision + * integer + * + * `libj2_j2u_min_ju(a, b)` implements + * `*a = *a < b ? *a : b` + * + * @param a One of the values, and output parameter + * for the minimum of `*a` and `b` + * @param b The other value + * + * @since 1.0 + */ +inline void +libj2_j2u_min_ju(struct libj2_j2u *a, uintmax_t b) +{ + if (a->high || a->low > b) { + a->high = 0; + a->low = b; + } +} + + +/** + * Get the minimum of an unsigned double-max + * precision integer and an unsigned precision + * integer + * + * `libj2_j2u_min_ju_to_j2u(a, b, res)` implements + * `*res = *a < b ? *a : b` + * + * @param a One of the values + * @param b The other value + * @param res Output parameter for the minimum of `*a` and `b` + * + * @since 1.0 + */ +inline void +libj2_j2u_min_ju_to_j2u(const struct libj2_j2u *a, uintmax_t b, struct libj2_j2u *res) +{ + if (a->high || a->low > b) { + res->high = 0; + res->low = b; + } else { + *res = *a; + } +} + + +/** + * Get the maximum of a set of unsigned double-max + * precision integers + * + * @param a One of the values, and output parameter for + * the maximum of the values + * @param args `NULL` terminated list of additional values; each + * argument shall have the type `const struct libj2_j2u *` + * + * @since 1.0 + */ +inline void +libj2_vmax_j2u(struct libj2_j2u *a, va_list args) +{ + const struct libj2_j2u *b; + while ((b = va_arg(args, const struct libj2_j2u *))) + libj2_j2u_max_j2u(a, b); +} + + +/** + * Get the maximum of a set of unsigned double-max + * precision integers + * + * @param a One of the values, and output parameter for + * the maximum of the values + * @param ... `NULL` terminated list of additional values; each + * argument shall have the type `const struct libj2_j2u *` + * + * @since 1.0 + */ +inline void +libj2_max_j2u(struct libj2_j2u *a, ... /*, NULL */) +{ + va_list args; + va_start(args, a); + libj2_vmax_j2u(a, args); + va_end(args); +} + + +/** + * Get the maximum of a set of unsigned double-max + * precision integers + * + * @param a One of the values + * @param args `NULL` terminated list of additional values; each + * argument shall have the type `const struct libj2_j2u *` + * @return One of the `const struct libj2_j2u *` that as the + * maximum of the values of each argument + * + * @since 1.0 + */ +inline const struct libj2_j2u * +libj2_vmax_j2u_return(const struct libj2_j2u *a, va_list args) +{ + const struct libj2_j2u *b; + while ((b = va_arg(args, const struct libj2_j2u *))) + if (libj2_j2u_gt_j2u(b, a)) + a = b; + return a; +} + + +/** + * Get the maximum of a set of unsigned double-max + * precision integers + * + * @param a One of the values + * @param ... `NULL` terminated list of additional values; each + * argument shall have the type `const struct libj2_j2u *` + * @return One of the `const struct libj2_j2u *` that as the + * maximum of the values of each argument + * + * @since 1.0 + */ +LIBJ2_PURE_ inline const struct libj2_j2u * +libj2_max_j2u_return(const struct libj2_j2u *a, ... /*, NULL */) +{ + va_list args; + va_start(args, a); + return libj2_vmax_j2u_return(a, args); + va_end(args); +} + + +/** + * Get the maximum of a set of unsigned double-max + * precision integers + * + * @param a One of the values + * @param args `NULL` terminated list of additional values, each + * argument shall have the type `const struct libj2_j2u *`, + * followed by a `struct libj2_j2u *` is used as the + * output parameter for the maximum of the values + * + * @since 1.0 + */ +inline void +libj2_vmax_j2u_to_j2u(const struct libj2_j2u *a, va_list args) +{ + struct libj2_j2u *res; + a = libj2_vmax_j2u_return(a, args); + res = va_arg(args, struct libj2_j2u *); + *res = *a; +} + + +/** + * Get the maximum of a set of unsigned double-max + * precision integers + * + * @param a One of the values + * @param ... `NULL` terminated list of additional values, each + * argument shall have the type `const struct libj2_j2u *`, + * followed by a `struct libj2_j2u *` is used as the + * output parameter for the maximum of the values + * + * @since 1.0 + */ +inline void +libj2_max_j2u_to_j2u(const struct libj2_j2u *a, ... /*, NULL, struct libj2_j2u *res */) +{ + va_list args; + va_start(args, a); + libj2_vmax_j2u_to_j2u(a, args); + va_end(args); +} + + +/** + * Get the minimum of a set of unsigned double-max + * precision integers + * + * @param a One of the values, and output parameter for + * the minimum of the values + * @param args `NULL` terminated list of additional values; each + * argument shall have the type `const struct libj2_j2u *` + * + * @since 1.0 + */ +inline void +libj2_vmin_j2u(struct libj2_j2u *a, va_list args) +{ + const struct libj2_j2u *b; + while ((b = va_arg(args, const struct libj2_j2u *))) + libj2_j2u_min_j2u(a, b); +} + + +/** + * Get the minimum of a set of unsigned double-max + * precision integers + * + * @param a One of the values, and output parameter for + * the minimum of the values + * @param ... `NULL` terminated list of additional values; each + * argument shall have the type `const struct libj2_j2u *` + * + * @since 1.0 + */ +inline void +libj2_min_j2u(struct libj2_j2u *a, ... /*, NULL */) +{ + va_list args; + va_start(args, a); + libj2_vmin_j2u(a, args); + va_end(args); +} + + +/** + * Get the minimum of a set of unsigned double-max + * precision integers + * + * @param a One of the values + * @param args `NULL` terminated list of additional values; each + * argument shall have the type `const struct libj2_j2u *` + * @return One of the `const struct libj2_j2u *` that as the + * minimum of the values of each argument + * + * @since 1.0 + */ +inline const struct libj2_j2u * +libj2_vmin_j2u_return(const struct libj2_j2u *a, va_list args) +{ + const struct libj2_j2u *b; + while ((b = va_arg(args, const struct libj2_j2u *))) + if (libj2_j2u_lt_j2u(b, a)) + a = b; + return a; +} + + +/** + * Get the minimum of a set of unsigned double-max + * precision integers + * + * @param a One of the values + * @param ... `NULL` terminated list of additional values; each + * argument shall have the type `const struct libj2_j2u *` + * @return One of the `const struct libj2_j2u *` that as the + * minimum of the values of each argument + * + * @since 1.0 + */ +LIBJ2_PURE_ inline const struct libj2_j2u * +libj2_min_j2u_return(const struct libj2_j2u *a, ... /*, NULL */) +{ + va_list args; + va_start(args, a); + return libj2_vmin_j2u_return(a, args); + va_end(args); +} + + +/** + * Get the minimum of a set of unsigned double-max + * precision integers + * + * @param a One of the values + * @param args `NULL` terminated list of additional values, each + * argument shall have the type `const struct libj2_j2u *`, + * followed by a `struct libj2_j2u *` is used as the + * output parameter for the minimum of the values + * + * @since 1.0 + */ +inline void +libj2_vmin_j2u_to_j2u(const struct libj2_j2u *a, va_list args) +{ + struct libj2_j2u *res; + a = libj2_vmin_j2u_return(a, args); + res = va_arg(args, struct libj2_j2u *); + *res = *a; +} + + +/** + * Get the minimum of a set of unsigned double-max + * precision integers + * + * @param a One of the values + * @param ... `NULL` terminated list of additional values, each + * argument shall have the type `const struct libj2_j2u *`, + * followed by a `struct libj2_j2u *` is used as the + * output parameter for the minimum of the values + * + * @since 1.0 + */ +inline void +libj2_min_j2u_to_j2u(const struct libj2_j2u *a, ... /*, NULL, struct libj2_j2u *res */) +{ + va_list args; + va_start(args, a); + libj2_vmin_j2u_to_j2u(a, args); + va_end(args); +} diff --git a/libj2/unsigned-comparsion.h b/libj2/unsigned-comparsion.h deleted file mode 100644 index c13397a..0000000 --- a/libj2/unsigned-comparsion.h +++ /dev/null @@ -1,855 +0,0 @@ -/* See LICENSE file for copyright and license details. */ -#ifndef LIBJ2_H -# error Do not include this header directly, include instead -#endif - - -/** - * Check whether an unsigned double-max precision integer is - * less than another unsigned double-max precision integer - * - * `libj2_j2u_lt_j2u(a, b)` implements `*a < *b` - * - * @param a The left-hand value - * @param b The right-hand value - * @return 1 if `*a` is less than `*b`, 0 otherwise - * - * @since 1.0 - */ -LIBJ2_PURE_ inline int -libj2_j2u_lt_j2u(const struct libj2_j2u *a, const struct libj2_j2u *b) -{ - return a->high < b->high || (a->high == b->high && a->low < b->low); -} - - -/** - * Check whether an unsigned double-max precision integer is less - * than or equal to another unsigned double-max precision integer - * - * `libj2_j2u_le_j2u(a, b)` implements `*a <= *b` - * - * @param a The left-hand value - * @param b The right-hand value - * @return 1 if `*a` is less than or equal to `*b`, 0 otherwise - * - * @since 1.0 - */ -LIBJ2_PURE_ inline int -libj2_j2u_le_j2u(const struct libj2_j2u *a, const struct libj2_j2u *b) -{ - return a->high < b->high || (a->high == b->high && a->low <= b->low); -} - - -/** - * Check whether an unsigned double-max precision integer is - * greater than another unsigned double-max precision integer - * - * `libj2_j2u_gt_j2u(a, b)` implements `*a > *b` - * - * @param a The left-hand value - * @param b The right-hand value - * @return 1 if `*a` is greater than `*b`, 0 otherwise - * - * @since 1.0 - */ -LIBJ2_PURE_ inline int -libj2_j2u_gt_j2u(const struct libj2_j2u *a, const struct libj2_j2u *b) -{ - return a->high > b->high || (a->high == b->high && a->low > b->low); -} - - -/** - * Check whether an unsigned double-max precision integer is greater - * than or equal to another unsigned double-max precision integer - * - * `libj2_j2u_ge_j2u(a, b)` implements `*a >= *b` - * - * @param a The left-hand value - * @param b The right-hand value - * @return 1 if `*a` is greater than or equal to `*b`, 0 otherwise - * - * @since 1.0 - */ -LIBJ2_PURE_ inline int -libj2_j2u_ge_j2u(const struct libj2_j2u *a, const struct libj2_j2u *b) -{ - return a->high > b->high || (a->high == b->high && a->low >= b->low); -} - - -/** - * Check whether an unsigned double-max precision integer is - * equal to another unsigned double-max precision integer - * - * `libj2_j2u_eq_j2u(a, b)` implements `*a == *b` - * - * @param a The left-hand value - * @param b The right-hand value - * @return 1 if `*a` is equal to `*b`, 0 otherwise - * - * @since 1.0 - */ -LIBJ2_PURE_ inline int -libj2_j2u_eq_j2u(const struct libj2_j2u *a, const struct libj2_j2u *b) -{ - return a->high == b->high && a->low == b->low; -} - - -/** - * Check whether an unsigned double-max precision integer is - * not equal to another unsigned double-max precision integer - * - * `libj2_j2u_ne_j2u(a, b)` implements `*a != *b` - * - * @param a The left-hand value - * @param b The right-hand value - * @return 1 if `*a` is not equal to `*b`, 0 otherwise - * - * @since 1.0 - */ -LIBJ2_PURE_ inline int -libj2_j2u_ne_j2u(const struct libj2_j2u *a, const struct libj2_j2u *b) -{ - return a->high != b->high || a->low != b->low; -} - - -/** - * Compare an unsigned double-max precision integer - * against another unsigned double-max precision integer - * - * `libj2_j2u_cmp_j2u(a, b)` implements `*a < *b ? -1 : *a > *b ? +1 : 0`, - * or equivalently, the signum of `*a - *b` where the signum is 0 for 0 - * - * @param a The left-hand value - * @param b The right-hand value - * @return -1 if `*a` is less than `*b`, - * +1 if `*a` is greater than `*b`, - * 0 if `*a` is equal to `*b` - * - * @since 1.0 - */ -LIBJ2_PURE_ inline int -libj2_j2u_cmp_j2u(const struct libj2_j2u *a, const struct libj2_j2u *b) -{ - return a->high < b->high ? -1 : a->high > b->high ? +1 : a->low < b->low ? -1 : a->low > b->low; -} - - -/** - * Check whether an unsigned double-max precision integer - * is less than an unsigned max precision integer - * - * `libj2_j2u_lt_ju(a, b)` implements `*a < b` - * - * @param a The left-hand value - * @param b The right-hand value - * @return 1 if `*a` is less than `b`, 0 otherwise - * - * @since 1.0 - */ -LIBJ2_PURE_ inline int -libj2_j2u_lt_ju(const struct libj2_j2u *a, uintmax_t b) -{ - return !a->high && a->low < b; -} - - -/** - * Check whether an unsigned double-max precision integer is - * less than or equal to an unsigned max precision integer - * - * `libj2_j2u_le_ju(a, b)` implements `*a <= b` - * - * @param a The left-hand value - * @param b The right-hand value - * @return 1 if `*a` is less than or equal to `b`, 0 otherwise - * - * @since 1.0 - */ -LIBJ2_PURE_ inline int -libj2_j2u_le_ju(const struct libj2_j2u *a, uintmax_t b) -{ - return !a->high && a->low <= b; -} - - -/** - * Check whether an unsigned double-max precision integer - * is greater than an unsigned max precision integer - * - * `libj2_j2u_gt_ju(a, b)` implements `*a > b` - * - * @param a The left-hand value - * @param b The right-hand value - * @return 1 if `*a` is less than `b`, 0 otherwise - * - * @since 1.0 - */ -LIBJ2_PURE_ inline int -libj2_j2u_gt_ju(const struct libj2_j2u *a, uintmax_t b) -{ - return a->high || a->low > b; -} - - -/** - * Check whether an unsigned double-max precision integer is - * greater than or equal to an unsigned max precision integer - * - * `libj2_j2u_ge_ju(a, b)` implements `*a >= b` - * - * @param a The left-hand value - * @param b The right-hand value - * @return 1 if `*a` is greater than or equal to `b`, 0 otherwise - * - * @since 1.0 - */ -LIBJ2_PURE_ inline int -libj2_j2u_ge_ju(const struct libj2_j2u *a, uintmax_t b) -{ - return a->high || a->low >= b; -} - - -/** - * Check whether an unsigned double-max precision integer - * is equal to an unsigned max precision integer - * - * `libj2_j2u_eq_ju(a, b)` implements `*a == b` - * - * @param a The left-hand value - * @param b The right-hand value - * @return 1 if `*a` is equal to `b`, 0 otherwise - * - * @since 1.0 - */ -LIBJ2_PURE_ inline int -libj2_j2u_eq_ju(const struct libj2_j2u *a, uintmax_t b) -{ - return !a->high && a->low == b; -} - - -/** - * Check whether an unsigned double-max precision integer - * is not equal to an unsigned max precision integer - * - * `libj2_j2u_ne_ju(a, b)` implements `*a != b` - * - * @param a The left-hand value - * @param b The right-hand value - * @return 1 if `*a` is not equal to `b`, 0 otherwise - * - * @since 1.0 - */ -LIBJ2_PURE_ inline int -libj2_j2u_ne_ju(const struct libj2_j2u *a, uintmax_t b) -{ - return a->high || a->low != b; -} - - -/** - * Compare an unsigned double-max precision integer - * against an unsigned max precision integer - * - * `libj2_j2u_cmp_ju(a, b)` implements `*a < b ? -1 : *a > b ? +1 : 0`, - * or equivalently, the signum of `*a - b` where the signum is 0 for 0 - * - * @param a The left-hand value - * @param b The right-hand value - * @return -1 if `*a` is less than `b`, - * +1 if `*a` is greater than `b`, - * 0 if `*a` is equal to `b` - * - * @since 1.0 - */ -LIBJ2_PURE_ inline int -libj2_j2u_cmp_ju(const struct libj2_j2u *a, uintmax_t b) -{ - return a->high ? +1 : a->low < b ? -1 : a->low > b; -} - - -/** - * Check whether an unsigned max precision integer is - * less than an unsigned double-max precision integer - * - * `libj2_ju_lt_j2u(a, b)` implements `a < *b` - * - * @param a The left-hand value - * @param b The right-hand value - * @return 1 if `a` is less than `*b`, 0 otherwise - * - * @since 1.0 - */ -LIBJ2_PURE_ inline int -libj2_ju_lt_j2u(uintmax_t a, const struct libj2_j2u *b) -{ - return libj2_j2u_gt_ju(b, a); -} - - -/** - * Check whether an unsigned max precision integer is less - * than or equal to an unsigned double-max precision integer - * - * `libj2_ju_le_j2u(a, b)` implements `a <= *b` - * - * @param a The left-hand value - * @param b The right-hand value - * @return 1 if `a` is less than or equal to `*b`, 0 otherwise - * - * @since 1.0 - */ -LIBJ2_PURE_ inline int -libj2_ju_le_j2u(uintmax_t a, const struct libj2_j2u *b) -{ - return libj2_j2u_ge_ju(b, a); -} - - -/** - * Check whether an unsigned max precision integer is - * greater than an unsigned double-max precision integer - * - * `libj2_ju_gt_j2u(a, b)` implements `a > *b` - * - * @param a The left-hand value - * @param b The right-hand value - * @return 1 if `a` is less than `*b`, 0 otherwise - * - * @since 1.0 - */ -LIBJ2_PURE_ inline int -libj2_ju_gt_j2u(uintmax_t a, const struct libj2_j2u *b) -{ - return libj2_j2u_lt_ju(b, a); -} - - -/** - * Check whether an unsigned max precision integer is greater - * than or equal to an unsigned double-max precision integer - * - * `libj2_ju_ge_j2u(a, b)` implements `a >= *b` - * - * @param a The left-hand value - * @param b The right-hand value - * @return 1 if `a` is greater than or equal to `*b`, 0 otherwise - * - * @since 1.0 - */ -LIBJ2_PURE_ inline int -libj2_ju_ge_j2u(uintmax_t a, const struct libj2_j2u *b) -{ - return libj2_j2u_le_ju(b, a); -} - - -/** - * Check whether an unsigned max precision integer is - * equal to an unsigned double-max precision integer - * - * `libj2_ju_eq_j2u(a, b)` implements `a == *b` - * - * @param a The left-hand value - * @param b The right-hand value - * @return 1 if `a` is equal to `*b`, 0 otherwise - * - * @since 1.0 - */ -LIBJ2_PURE_ inline int -libj2_ju_eq_j2u(uintmax_t a, const struct libj2_j2u *b) -{ - return libj2_j2u_eq_ju(b, a); -} - - -/** - * Check whether an unsigned max precision integer is - * not equal to an unsigned double-max precision integer - * - * `libj2_ju_ne_j2u(a, b)` implements `a != *b` - * - * @param a The left-hand value - * @param b The right-hand value - * @return 1 if `a` is not equal to `*b`, 0 otherwise - * - * @since 1.0 - */ -LIBJ2_PURE_ inline int -libj2_ju_ne_j2u(uintmax_t a, const struct libj2_j2u *b) -{ - return libj2_j2u_ne_ju(b, a); -} - - -/** - * Compare an unsigned max precision integer - * against an unsigned double-max precision integer - * - * `libj2_ju_cmp_j2u(a, b)` implements `a < *b ? -1 : a > *b ? +1 : 0`, - * or equivalently, the signum of `a - *b` where the signum is 0 for 0 - * - * @param a The left-hand value - * @param b The right-hand value - * @return -1 if `a` is less than `*b`, - * +1 if `a` is greater than `*b`, - * 0 if `a` is equal to `*b` - * - * @since 1.0 - */ -LIBJ2_PURE_ inline int -libj2_ju_cmp_j2u(uintmax_t a, const struct libj2_j2u *b) -{ - return b->high ? -1 : a < b->low ? -1 : a > b->low; -} - - - - - -/** - * Get the maximum of two unsigned double-max - * precision integers - * - * `libj2_j2u_max_j2u_to_ju2(a, b, res)` implements - * `*res = *a > *b ? *a : *b` - * - * @param a One of the values - * @param b The other value - * @param res Output parameter for the maximum of `*a` and `*b` - * - * @since 1.0 - */ -inline void -libj2_j2u_max_j2u_to_j2u(const struct libj2_j2u *a, const struct libj2_j2u *b, struct libj2_j2u *res) -{ - *res = libj2_j2u_gt_j2u(a, b) ? *a : *b; -} - - -/** - * Get the maximum of two unsigned double-max - * precision integers - * - * `libj2_j2u_max_j2u(a, b)` implements - * `*a = *a > *b ? *a : *b` - * - * @param a One of the values, and output parameter - * for the maximum of `*a` and `*b` - * @param b The other value - * - * @since 1.0 - */ -inline void -libj2_j2u_max_j2u(struct libj2_j2u *a, const struct libj2_j2u *b) -{ - if (libj2_j2u_gt_j2u(b, a)) - *a = *b; -} - - -/** - * Get the maximum of an unsigned double-max - * precision integer and an unsigned precision - * integer - * - * `libj2_j2u_max_ju(a, b)` implements - * `*a = *a > b ? *a : b` - * - * @param a One of the values, and output parameter - * for the maximum of `*a` and `b` - * @param b The other value - * - * @since 1.0 - */ -inline void -libj2_j2u_max_ju(struct libj2_j2u *a, uintmax_t b) -{ - if (!a->high && a->low < b) - a->low = b; -} - - -/** - * Get the maximum of an unsigned double-max - * precision integer and an unsigned precision - * integer - * - * `libj2_j2u_max_ju_to_j2u(a, b, res)` implements - * `*res = *a > b ? *a : b` - * - * @param a One of the values - * @param b The other value - * @param res Output parameter for the maximum of `*a` and `b` - * - * @since 1.0 - */ -inline void -libj2_j2u_max_ju_to_j2u(const struct libj2_j2u *a, uintmax_t b, struct libj2_j2u *res) -{ - if (!a->high && a->low < b) { - res->high = 0; - res->low = b; - } else { - *res = *a; - } -} - - -/** - * Get the minimum of two unsigned double-max - * precision integers - * - * `libj2_j2u_min_j2u_to_ju2(a, b, res)` implements - * `*res = *a < *b ? *a : *b` - * - * @param a One of the values - * @param b The other value - * @param res Output parameter for the minimum of `*a` and `*b` - * - * @since 1.0 - */ -inline void -libj2_j2u_min_j2u_to_j2u(const struct libj2_j2u *a, const struct libj2_j2u *b, struct libj2_j2u *res) -{ - *res = libj2_j2u_lt_j2u(a, b) ? *a : *b; -} - - -/** - * Get the minimum of two unsigned double-max - * precision integers - * - * `libj2_j2u_min_j2u(a, b)` implements - * `*a = *a < *b ? *a : *b` - * - * @param a One of the values, and output parameter - * for the minimum of `*a` and `*b` - * @param b The other value - * - * @since 1.0 - */ -inline void -libj2_j2u_min_j2u(struct libj2_j2u *a, const struct libj2_j2u *b) -{ - if (libj2_j2u_lt_j2u(b, a)) - *a = *b; -} - - -/** - * Get the minimum of an unsigned double-max - * precision integer and an unsigned precision - * integer - * - * `libj2_j2u_min_ju(a, b)` implements - * `*a = *a < b ? *a : b` - * - * @param a One of the values, and output parameter - * for the minimum of `*a` and `b` - * @param b The other value - * - * @since 1.0 - */ -inline void -libj2_j2u_min_ju(struct libj2_j2u *a, uintmax_t b) -{ - if (a->high || a->low > b) { - a->high = 0; - a->low = b; - } -} - - -/** - * Get the minimum of an unsigned double-max - * precision integer and an unsigned precision - * integer - * - * `libj2_j2u_min_ju_to_j2u(a, b, res)` implements - * `*res = *a < b ? *a : b` - * - * @param a One of the values - * @param b The other value - * @param res Output parameter for the minimum of `*a` and `b` - * - * @since 1.0 - */ -inline void -libj2_j2u_min_ju_to_j2u(const struct libj2_j2u *a, uintmax_t b, struct libj2_j2u *res) -{ - if (a->high || a->low > b) { - res->high = 0; - res->low = b; - } else { - *res = *a; - } -} - - -/** - * Get the maximum of a set of unsigned double-max - * precision integers - * - * @param a One of the values, and output parameter for - * the maximum of the values - * @param args `NULL` terminated list of additional values; each - * argument shall have the type `const struct libj2_j2u *` - * - * @since 1.0 - */ -inline void -libj2_vmax_j2u(struct libj2_j2u *a, va_list args) -{ - const struct libj2_j2u *b; - while ((b = va_arg(args, const struct libj2_j2u *))) - libj2_j2u_max_j2u(a, b); -} - - -/** - * Get the maximum of a set of unsigned double-max - * precision integers - * - * @param a One of the values, and output parameter for - * the maximum of the values - * @param ... `NULL` terminated list of additional values; each - * argument shall have the type `const struct libj2_j2u *` - * - * @since 1.0 - */ -inline void -libj2_max_j2u(struct libj2_j2u *a, ... /*, NULL */) -{ - va_list args; - va_start(args, a); - libj2_vmax_j2u(a, args); - va_end(args); -} - - -/** - * Get the maximum of a set of unsigned double-max - * precision integers - * - * @param a One of the values - * @param args `NULL` terminated list of additional values; each - * argument shall have the type `const struct libj2_j2u *` - * @return One of the `const struct libj2_j2u *` that as the - * maximum of the values of each argument - * - * @since 1.0 - */ -inline const struct libj2_j2u * -libj2_vmax_j2u_return(const struct libj2_j2u *a, va_list args) -{ - const struct libj2_j2u *b; - while ((b = va_arg(args, const struct libj2_j2u *))) - if (libj2_j2u_gt_j2u(b, a)) - a = b; - return a; -} - - -/** - * Get the maximum of a set of unsigned double-max - * precision integers - * - * @param a One of the values - * @param ... `NULL` terminated list of additional values; each - * argument shall have the type `const struct libj2_j2u *` - * @return One of the `const struct libj2_j2u *` that as the - * maximum of the values of each argument - * - * @since 1.0 - */ -LIBJ2_PURE_ inline const struct libj2_j2u * -libj2_max_j2u_return(const struct libj2_j2u *a, ... /*, NULL */) -{ - va_list args; - va_start(args, a); - return libj2_vmax_j2u_return(a, args); - va_end(args); -} - - -/** - * Get the maximum of a set of unsigned double-max - * precision integers - * - * @param a One of the values - * @param args `NULL` terminated list of additional values, each - * argument shall have the type `const struct libj2_j2u *`, - * followed by a `struct libj2_j2u *` is used as the - * output parameter for the maximum of the values - * - * @since 1.0 - */ -inline void -libj2_vmax_j2u_to_j2u(const struct libj2_j2u *a, va_list args) -{ - struct libj2_j2u *res; - a = libj2_vmax_j2u_return(a, args); - res = va_arg(args, struct libj2_j2u *); - *res = *a; -} - - -/** - * Get the maximum of a set of unsigned double-max - * precision integers - * - * @param a One of the values - * @param ... `NULL` terminated list of additional values, each - * argument shall have the type `const struct libj2_j2u *`, - * followed by a `struct libj2_j2u *` is used as the - * output parameter for the maximum of the values - * - * @since 1.0 - */ -inline void -libj2_max_j2u_to_j2u(const struct libj2_j2u *a, ... /*, NULL, struct libj2_j2u *res */) -{ - va_list args; - va_start(args, a); - libj2_vmax_j2u_to_j2u(a, args); - va_end(args); -} - - -/** - * Get the minimum of a set of unsigned double-max - * precision integers - * - * @param a One of the values, and output parameter for - * the minimum of the values - * @param args `NULL` terminated list of additional values; each - * argument shall have the type `const struct libj2_j2u *` - * - * @since 1.0 - */ -inline void -libj2_vmin_j2u(struct libj2_j2u *a, va_list args) -{ - const struct libj2_j2u *b; - while ((b = va_arg(args, const struct libj2_j2u *))) - libj2_j2u_min_j2u(a, b); -} - - -/** - * Get the minimum of a set of unsigned double-max - * precision integers - * - * @param a One of the values, and output parameter for - * the minimum of the values - * @param ... `NULL` terminated list of additional values; each - * argument shall have the type `const struct libj2_j2u *` - * - * @since 1.0 - */ -inline void -libj2_min_j2u(struct libj2_j2u *a, ... /*, NULL */) -{ - va_list args; - va_start(args, a); - libj2_vmin_j2u(a, args); - va_end(args); -} - - -/** - * Get the minimum of a set of unsigned double-max - * precision integers - * - * @param a One of the values - * @param args `NULL` terminated list of additional values; each - * argument shall have the type `const struct libj2_j2u *` - * @return One of the `const struct libj2_j2u *` that as the - * minimum of the values of each argument - * - * @since 1.0 - */ -inline const struct libj2_j2u * -libj2_vmin_j2u_return(const struct libj2_j2u *a, va_list args) -{ - const struct libj2_j2u *b; - while ((b = va_arg(args, const struct libj2_j2u *))) - if (libj2_j2u_lt_j2u(b, a)) - a = b; - return a; -} - - -/** - * Get the minimum of a set of unsigned double-max - * precision integers - * - * @param a One of the values - * @param ... `NULL` terminated list of additional values; each - * argument shall have the type `const struct libj2_j2u *` - * @return One of the `const struct libj2_j2u *` that as the - * minimum of the values of each argument - * - * @since 1.0 - */ -LIBJ2_PURE_ inline const struct libj2_j2u * -libj2_min_j2u_return(const struct libj2_j2u *a, ... /*, NULL */) -{ - va_list args; - va_start(args, a); - return libj2_vmin_j2u_return(a, args); - va_end(args); -} - - -/** - * Get the minimum of a set of unsigned double-max - * precision integers - * - * @param a One of the values - * @param args `NULL` terminated list of additional values, each - * argument shall have the type `const struct libj2_j2u *`, - * followed by a `struct libj2_j2u *` is used as the - * output parameter for the minimum of the values - * - * @since 1.0 - */ -inline void -libj2_vmin_j2u_to_j2u(const struct libj2_j2u *a, va_list args) -{ - struct libj2_j2u *res; - a = libj2_vmin_j2u_return(a, args); - res = va_arg(args, struct libj2_j2u *); - *res = *a; -} - - -/** - * Get the minimum of a set of unsigned double-max - * precision integers - * - * @param a One of the values - * @param ... `NULL` terminated list of additional values, each - * argument shall have the type `const struct libj2_j2u *`, - * followed by a `struct libj2_j2u *` is used as the - * output parameter for the minimum of the values - * - * @since 1.0 - */ -inline void -libj2_min_j2u_to_j2u(const struct libj2_j2u *a, ... /*, NULL, struct libj2_j2u *res */) -{ - va_list args; - va_start(args, a); - libj2_vmin_j2u_to_j2u(a, args); - va_end(args); -} -- cgit v1.2.3-70-g09d2