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);Success
Returns true; *result holds a - b.
Failure
Returns false if an intermediate allocation fails; *result is unchanged.
Usage example (Cross-references)
Usage examples (Cross-references)
- In
Int.Math.c:154:
bool test_int_sub(void) {
WriteFmt("Testing IntSub\n");
DefaultAllocator alloc = DefaultAllocatorInit();- In
Int.Math.c:162:
Int result_value = IntInit(&alloc.base);
bool result = IntSub(&result_value, &a, &b);
result = result && (IntToU64(&result_value) == 255);- In
Int.Math.c:173:
bool test_int_sub_generic(void) {
WriteFmt("Testing IntSub generic dispatch\n");
DefaultAllocator alloc = DefaultAllocatorInit();- In
Int.Math.c:184:
Str text = StrInit(&alloc.base);
bool result = IntSub(&result_value, &base, &rhs);
result = result && (IntToU64(&result_value) == 38);- In
Int.Math.c:187:
result = result && (IntToU64(&result_value) == 38);
result = result && IntSub(&result_value, &base, 2u);
result = result && (IntToU64(&result_value) == 38);- In
Int.Math.c:190:
result = result && (IntToU64(&result_value) == 38);
result = result && IntSub(&result_value, &base, -2);
result = result && (IntToU64(&result_value) == 42);- In
Int.Math.c:193:
result = result && (IntToU64(&result_value) == 42);
result = result && IntSub(&result_value, &huge, 90);
text = IntToStr(&result_value);
result = result && (ZstrCompare(StrBegin(&text), "12345678901234567800") == 0);- In
Int.Math.c:197:
result = result && (ZstrCompare(StrBegin(&text), "12345678901234567800") == 0);
result = result && !IntSub(&preserved, &base, 50);
result = result && (IntToU64(&preserved) == 99);- In
Int.Math.c:211:
bool test_int_sub_underflow_preserves_result(void) {
WriteFmt("Testing IntSub underflow handling\n");
DefaultAllocator alloc = DefaultAllocatorInit();- In
Int.Math.c:219:
Int result_value = IntFrom(99, &alloc.base);
bool result = !IntSub(&result_value, &a, &b);
result = result && (IntToU64(&result_value) == 99);
Last updated on