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
Int.Math.c:442:
bool test_int_mod(void) {
WriteFmt("Testing IntMod generic dispatch\n");
DefaultAllocator alloc = DefaultAllocatorInit();- In
Int.Math.c:449:
Int result_value = IntInit(&alloc.base);
IntMod(&result_value, ÷nd, 10u);
bool result = IntToU64(&result_value) == 6;- In
Int.Math.c:460:
bool test_int_mod_scalar(void) {
WriteFmt("Testing IntMod scalar-divisor dispatch\n");
DefaultAllocator alloc = DefaultAllocatorInit();- In
Int.Math.c:467:
Int remainder = IntInit(&alloc.base);
IntMod(&remainder, &value, 97u);
IntDeinit(&value);- In
Int.Math.c:1033:
bool test_int_mod_scalar_zero_modulus(void) {
WriteFmt("Testing IntMod scalar zero-modulus handling\n");
DefaultAllocator alloc = DefaultAllocatorInit();- In
Int.Math.c:1040:
Int result_value = IntFrom(99, &alloc.base);
IntMod(&result_value, &value, 0u);
bool result = IntCompare(&result_value, 99) == 0;
Last updated on