IntCompare
IntCompare
Description
Compare an integer against another integer-like value. Dispatches on the type of rhs to the matching internal handler.
Parameters
| Name | Direction | Description |
|---|---|---|
lhs |
in | Left-hand integer |
rhs |
in | Right-hand operand (Int, pointer, u64, or i64 compatible type) |
Usage example (from documentation)
int cmp = IntCompare(&value, 42);Returns
-1 if lhs < rhs, 0 if equal, 1 if lhs > rhs.
Usage example (Cross-references)
Usage examples (Cross-references)
- In
Float.c:123:
float_scale_to_exponent(&lhs_scaled, target_exponent);
float_scale_to_exponent(&rhs_scaled, target_exponent);
cmp = IntCompare(&lhs_scaled.significand, &rhs_scaled.significand);
FloatDeinit(&lhs_scaled);- In
Float.c:479:
temp.negative = lhs.negative;
} else {
int cmp = IntCompare(&lhs.significand, &rhs.significand);
if (cmp > 0) {- In
Int.c:116:
temp.negative = a->negative;
} else {
int cmp = IntCompare(&a->magnitude, &b->magnitude);
if (cmp == 0) {- In
Int.c:594:
}
int(IntCompare)(Int *lhs, Int *rhs) {
ValidateInt(lhs);
ValidateInt(rhs);- In
Int.c:761:
ValidateInt(b);
if (IntCompare(a, b) < 0) {
return false;
}- In
Int.c:943:
Int r = IntClone(&normalized_dividend);
if (IntCompare(&normalized_dividend, &normalized_divisor) >= 0) {
u64 dividend_bits = IntBitLength(&normalized_dividend);
u64 divisor_bits = IntBitLength(&normalized_divisor);- In
Int.c:1219:
MISRA_PRIV_IntPowU64(&mid_pow, &mid, degree);
cmp = IntCompare(&mid_pow, value);
if (cmp <= 0) {- In
Int.c:1827:
Int x = IntInit();
if (IntCompare(&base, value) >= 0) {
IntDeinit(&base);
IntDeinit(&x);
bool test_int_compare_ignores_leading_zeros(void) {
WriteFmt("Testing IntCompare leading-zero normalization\n");
Int lhs = IntFromBinary("0001011"); Int rhs = IntFrom(11);
bool result = IntCompare(&lhs, &rhs) == 0;
result = result && IntEQ(&lhs, &rhs);- In
Int.Compare.c:12:
bool test_int_compare(void) {
WriteFmt("Testing IntCompare\n");
Int a = IntFrom(41);- In
Int.Compare.c:18:
Int c = IntFromBinary("000101010");
bool result = IntCompare(&a, &b) < 0;
result = result && (IntCompare(&b, &a) > 0);
result = result && (IntCompare(&b, &c) == 0);- In
Int.Compare.c:19:
bool result = IntCompare(&a, &b) < 0;
result = result && (IntCompare(&b, &a) > 0);
result = result && (IntCompare(&b, &c) == 0);- In
Int.Compare.c:20:
bool result = IntCompare(&a, &b) < 0;
result = result && (IntCompare(&b, &a) > 0);
result = result && (IntCompare(&b, &c) == 0);
IntDeinit(&a);- In
Int.Compare.c:51:
bool test_int_compare_generic(void) {
WriteFmt("Testing IntCompare generic dispatch\n");
Int value = IntFrom(42);- In
Int.Compare.c:59:
IntShiftLeft(&big, 80);
bool result = (IntCompare(&value, &same) == 0);
result = result && (IntCompare(&value, same) == 0);
result = result && (IntCompare(&value, 42) == 0);- In
Int.Compare.c:60:
bool result = (IntCompare(&value, &same) == 0);
result = result && (IntCompare(&value, same) == 0);
result = result && (IntCompare(&value, 42) == 0);
result = result && (IntCompare(&value, 100ULL) < 0);- In
Int.Compare.c:61:
bool result = (IntCompare(&value, &same) == 0);
result = result && (IntCompare(&value, same) == 0);
result = result && (IntCompare(&value, 42) == 0);
result = result && (IntCompare(&value, 100ULL) < 0);
result = result && (IntCompare(&value, -1) > 0);- In
Int.Compare.c:62:
result = result && (IntCompare(&value, same) == 0);
result = result && (IntCompare(&value, 42) == 0);
result = result && (IntCompare(&value, 100ULL) < 0);
result = result && (IntCompare(&value, -1) > 0);
result = result && (IntCompare(&big, UINT64_MAX) > 0);- In
Int.Compare.c:63:
result = result && (IntCompare(&value, 42) == 0);
result = result && (IntCompare(&value, 100ULL) < 0);
result = result && (IntCompare(&value, -1) > 0);
result = result && (IntCompare(&big, UINT64_MAX) > 0);
result = result && IntEQ(&value, 42);- In
Int.Compare.c:64:
result = result && (IntCompare(&value, 100ULL) < 0);
result = result && (IntCompare(&value, -1) > 0);
result = result && (IntCompare(&big, UINT64_MAX) > 0);
result = result && IntEQ(&value, 42);
result = result && IntLE(&value, 42);- In
Int.Math.c:654:
IntModMul(&check, &result_value, &b, &m);
result = result && (IntCompare(&check, 10) == 0);
IntDeinit(&a);- In
Int.Math.c:731:
bool result = IntModSqrt(&root, &value, &mod);
IntSquareMod(&check, &root, &mod);
result = result && (IntCompare(&check, 10) == 0);
IntDeinit(&value);- In
Int.Math.c:748:
bool result = !IntModSqrt(&root, &value, &mod);
result = result && (IntCompare(&root, 99) == 0);
IntDeinit(&value);- In
Int.Math.c:813:
bool result = !IntModDiv(&result_value, &a, &b, &m);
result = result && (IntCompare(&result_value, 99) == 0);
IntDeinit(&a);- In
Compare.h:29:
/// TAGS: Int, Compare, Ordering
///
int (IntCompare)(Int *lhs, Int *rhs);
#ifndef __cplusplus- In
Compare.h:36:
(rhs), \
Int: MISRA_PRIV_IntCompareValue, \
Int *: IntCompare, \
const Int *: MISRA_PRIV_IntCompareConst, \
unsigned char: MISRA_PRIV_IntCompareU64, \
Last updated on