IntMod
Description
Generic modulo convenience macro.
Parameters
| Name | Direction | Description |
|---|---|---|
result |
out | Destination for the remainder |
dividend |
in | Dividend |
divisor |
in | Divisor selected through generic dispatch |
Usage example (from documentation)
IntMod(&remainder, &value, 97u);Success
Returns true; *result holds dividend mod divisor in the range [0, |divisor|).
Failure
Returns false when divisor is zero (logged) or when an intermediate allocation fails; *result is unchanged.
Usage example (Cross-references)
Usage examples (Cross-references)
- In
Math.c:452:
bool test_int_mod(void) {
WriteFmt("Testing IntMod generic dispatch\n");
DefaultAllocator alloc = DefaultAllocatorInit();- In
Math.c:459:
Int result_value = IntInit(&alloc.base);
IntMod(&result_value, ÷nd, 10u);
bool result = IntToU64(&result_value) == 6;- In
Math.c:470:
bool test_int_mod_scalar(void) {
WriteFmt("Testing IntMod scalar-divisor dispatch\n");
DefaultAllocator alloc = DefaultAllocatorInit();- In
Math.c:477:
Int remainder = IntInit(&alloc.base);
IntMod(&remainder, &value, 97u);
IntDeinit(&value);- In
Math.c:1043:
bool test_int_mod_scalar_zero_modulus(void) {
WriteFmt("Testing IntMod scalar zero-modulus handling\n");
DefaultAllocator alloc = DefaultAllocatorInit();- In
Math.c:1050:
Int result_value = IntFrom(99, &alloc.base);
IntMod(&result_value, &value, 0u);
bool result = IntCompare(&result_value, 99) == 0;- In
Math.c:2636:
Int result = IntInit(&alloc.base);
bool ok = IntMod(&result, ÷nd, (unsigned long)7u);
bool correct = ok && (IntToU64(&result) == (u64)2u);- In
Math.c:2888:
// false; the faithful mutant yields 42 (truthy). Observe the return value.
bool test_fe_1606_mod_u64_zero_returns_false(void) {
WriteFmt("Testing IntMod u64 zero-divisor return value\n");
DefaultAllocator alloc = DefaultAllocatorInit();- In
Math.c:2895:
Int result_value = IntInit(&alloc.base);
bool ok = IntMod(&result_value, ÷nd, 0u);
bool result = (ok == false);- In
Math.c:2905:
bool test_fe_1614_mod_i64_zero_returns_false(void) {
WriteFmt("Testing IntMod i64 zero-divisor return value\n");
DefaultAllocator alloc = DefaultAllocatorInit();- In
Math.c:2912:
Int result_value = IntInit(&alloc.base);
bool ok = IntMod(&result_value, ÷nd, (i64)0);
bool result = (ok == false);- In
Math.c:3932:
bool ok = IntDivMod(&q, &r, &dvd, 100u);
ok = ok && IntMod(&m1, &dvd, 100u);
ok = ok && IntMod(&m2, &dvd, (i64)100);
ok = ok && IntToU64(&q) == 10u && IntToU64(&r) == 3u;- In
Math.c:3933:
bool ok = IntDivMod(&q, &r, &dvd, 100u);
ok = ok && IntMod(&m1, &dvd, 100u);
ok = ok && IntMod(&m2, &dvd, (i64)100);
ok = ok && IntToU64(&q) == 10u && IntToU64(&r) == 3u;
ok = ok && IntToU64(&m1) == 3u && IntToU64(&m2) == 3u;- In
Math.c:3955:
Int r = IntFrom(7u, a);
bool ok = IntMod(&r, &dvd, &dvs); // int_mod frees quotient on success (1598)
ok = ok && IntToU64(&r) == 3u;
Last updated on