IntSub
IntSub
Description
Generic subtraction convenience macro. Dispatches on the type of b to the matching IntSub* overload.
Parameters
| Name | Direction | Description |
|---|---|---|
result |
out | Destination for the difference |
a |
in | Left operand |
b |
in | Right operand (Int, pointer, u64, or i64 compatible type) |
Usage example (from documentation)
bool ok = IntSub(&diff, &value, 1u);Returns
Result of the selected subtraction overload.
Usage example (Cross-references)
Usage examples (Cross-references)
- In
Float.c:482:
if (cmp > 0) {
(void)IntSub(&temp.significand, &lhs.significand, &rhs.significand);
temp.negative = lhs.negative;
} else if (cmp < 0) {- In
Float.c:485:
temp.negative = lhs.negative;
} else if (cmp < 0) {
(void)IntSub(&temp.significand, &rhs.significand, &lhs.significand);
temp.negative = rhs.negative;
} else {- In
Int.c:121:
temp.negative = false;
} else if (cmp > 0) {
(void)IntSub(&temp.magnitude, &a->magnitude, &b->magnitude);
temp.negative = a->negative;
} else {- In
Int.c:124:
temp.negative = a->negative;
} else {
(void)IntSub(&temp.magnitude, &b->magnitude, &a->magnitude);
temp.negative = b->negative;
}- In
Int.c:756:
}
bool(IntSub)(Int *result, Int *a, Int *b) {
ValidateInt(result);
ValidateInt(a);- In
Int.c:796:
Int rhs = MISRA_PRIV_IntFromU64(subtrahend);
bool ok = IntSub(result, value, &rhs);
IntDeinit(&rhs);- In
Int.c:958:
Int next = IntInit();
(void)IntSub(&next, &r, &shifted);
IntDeinit(&r);
r = next;- In
Int.c:1236:
high = IntInit();
} else {
(void)IntSub(&next, &mid, &one);
IntDeinit(&high);
high = next;- In
Int.c:1251:
MISRA_PRIV_IntPowU64(&power, &best, degree);
(void)IntSub(&rem, value, &power);
IntDeinit(&power);- In
Int.c:1408:
if (IntGE(&ar, &br)) {
(void)IntSub(result, &ar, &br);
} else {
Int diff = IntInit();- In
Int.c:1412:
Int diff = IntInit();
(void)IntSub(&diff, &br, &ar);
if (IntIsZero(&diff)) {
Int zero = IntInit();- In
Int.c:1417:
int_replace(result, &zero);
} else {
(void)IntSub(result, modulus, &diff);
}- In
Int.c:1622:
IntMod(&mag_mod, &t.magnitude, modulus);
if (t.negative && !IntIsZero(&mag_mod)) {
(void)IntSub(&positive, modulus, &mag_mod);
} else {
IntMod(&positive, &t.magnitude, modulus);- In
Int.Math.c:141:
bool test_int_sub(void) {
WriteFmt("Testing IntSub\n");
Int a = IntFrom(256);- In
Int.Math.c:147:
Int result_value = IntInit();
bool result = IntSub(&result_value, &a, &b);
result = result && (IntToU64(&result_value) == 255);- In
Int.Math.c:157:
bool test_int_sub_generic(void) {
WriteFmt("Testing IntSub generic dispatch\n");
Int base = IntFrom(40);- In
Int.Math.c:166:
Str text = StrInit();
bool result = IntSub(&result_value, &base, rhs);
result = result && (IntToU64(&result_value) == 38);- In
Int.Math.c:169:
result = result && (IntToU64(&result_value) == 38);
result = result && IntSub(&result_value, &base, 2u);
result = result && (IntToU64(&result_value) == 38);- In
Int.Math.c:172:
result = result && (IntToU64(&result_value) == 38);
result = result && IntSub(&result_value, &base, -2);
result = result && (IntToU64(&result_value) == 42);- In
Int.Math.c:175:
result = result && (IntToU64(&result_value) == 42);
result = result && IntSub(&result_value, &huge, 90);
text = IntToStr(&result_value);
result = result && (strcmp(text.data, "12345678901234567800") == 0);- In
Int.Math.c:179:
result = result && (strcmp(text.data, "12345678901234567800") == 0);
result = result && !IntSub(&preserved, &base, 50);
result = result && (IntToU64(&preserved) == 99);- In
Int.Math.c:192:
bool test_int_sub_underflow_preserves_result(void) {
WriteFmt("Testing IntSub underflow handling\n");
Int a = IntFrom(3);- In
Int.Math.c:198:
Int result_value = IntFrom(99);
bool result = !IntSub(&result_value, &a, &b);
result = result && (IntToU64(&result_value) == 99);- In
Math.h:67:
/// TAGS: Int, Math, Subtract
///
bool (IntSub)(Int *result, Int *a, Int *b);
///
/// Multiply two integers.
- In
Math.h:453:
(rhs), \
Int: MISRA_PRIV_IntSubValue, \
Int *: IntSub, \
const Int *: MISRA_PRIV_IntSubConst, \
unsigned char: MISRA_PRIV_IntSubU64, \
Last updated on