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
Math.c:347:
bool test_int_div_mod(void) {
WriteFmt("Testing IntDivMod generic dispatch\n");
DefaultAllocator alloc = DefaultAllocatorInit();- In
Math.c:356:
Str qtext = StrInit(&alloc.base);
IntDivMod("ient, &remainder, ÷nd, 97u);
qtext = IntToStr("ient);- In
Math.c:428:
bool test_int_div_mod_scalar(void) {
WriteFmt("Testing IntDivMod scalar-divisor dispatch\n");
DefaultAllocator alloc = DefaultAllocatorInit();- In
Math.c:437:
Str text = StrInit(&alloc.base);
IntDivMod("ient, &remainder, ÷nd, 97);
text = IntToStr("ient);- In
Math.c:992:
Int remainder = IntFrom(77, &alloc.base);
bool result = !IntDivMod("ient, &remainder, ÷nd, &divisor);
result = result && (IntCompare("ient, 99) == 0);- In
Math.c:2847:
// faithful mutant yields 42 (truthy). Observe the return value.
bool test_fe_1539_div_mod_u64_zero_returns_false(void) {
WriteFmt("Testing IntDivMod u64 zero-divisor return value\n");
DefaultAllocator alloc = DefaultAllocatorInit();- In
Math.c:2855:
Int remainder = IntInit(&alloc.base);
bool ok = IntDivMod("ient, &remainder, ÷nd, 0u);
bool result = (ok == false);- In
Math.c:2866:
bool test_fe_1552_div_mod_i64_zero_returns_false(void) {
WriteFmt("Testing IntDivMod i64 zero-divisor return value\n");
DefaultAllocator alloc = DefaultAllocatorInit();- In
Math.c:2874:
Int remainder = IntInit(&alloc.base);
bool ok = IntDivMod("ient, &remainder, ÷nd, (i64)0);
bool result = (ok == false);- In
Math.c:3822:
Int r = IntFrom(9u, a);
bool ok = IntDivMod(&q, &r, &dvd, &dvs);
ok = ok && IntToU64(&q) == 1000003u / 101u && IntToU64(&r) == 1000003u % 101u;- In
Math.c:3844:
Int r = IntFrom(9u, a);
bool ok = IntDivMod(&q, &r, &dvd, &dvs);
ok = ok && IntIsZero(&q) && IntToU64(&r) == 50u;- In
Math.c:3931:
Int m2 = IntFrom(7u, a);
bool ok = IntDivMod(&q, &r, &dvd, 100u);
ok = ok && IntMod(&m1, &dvd, 100u);
ok = ok && IntMod(&m2, &dvd, (i64)100);
Last updated on