IntDivMod
Description
Generic quotient-and-remainder convenience macro.
Parameters
| Name | Direction | Description |
|---|---|---|
quotient |
out | Destination for the quotient |
remainder |
out | Destination for the remainder |
dividend |
in | Dividend |
divisor |
in | Divisor selected through generic dispatch |
Usage example (from documentation)
IntDivMod(&q, &r, &value, 97u);Success
Returns true; *quotient and *remainder jointly satisfy dividend = quotient * divisor + remainder.
Failure
LOG_FATAL if quotient and remainder alias the same object. Returns false when divisor is zero (logged) or when an intermediate allocation fails; *quotient and *remainder are unchanged.
Usage example (Cross-references)
Usage examples (Cross-references)
- In
Int.Math.c:337:
bool test_int_div_mod(void) {
WriteFmt("Testing IntDivMod generic dispatch\n");
DefaultAllocator alloc = DefaultAllocatorInit();- In
Int.Math.c:346:
Str qtext = StrInit(&alloc.base);
IntDivMod("ient, &remainder, ÷nd, 97u);
qtext = IntToStr("ient);- In
Int.Math.c:418:
bool test_int_div_mod_scalar(void) {
WriteFmt("Testing IntDivMod scalar-divisor dispatch\n");
DefaultAllocator alloc = DefaultAllocatorInit();- In
Int.Math.c:427:
Str text = StrInit(&alloc.base);
IntDivMod("ient, &remainder, ÷nd, 97);
text = IntToStr("ient);- In
Int.Math.c:982:
Int remainder = IntFrom(77, &alloc.base);
bool result = !IntDivMod("ient, &remainder, ÷nd, &divisor);
result = result && (IntCompare("ient, 99) == 0);
Last updated on