IntDiv
Description
Generic division convenience macro.
Parameters
| Name | Direction | Description |
|---|---|---|
result |
out | Destination for the quotient |
dividend |
in | Dividend |
divisor |
in | Divisor selected through generic dispatch |
Usage example (from documentation)
IntDiv("ient, &value, 10u);Success
Returns true; *result holds the floor quotient of dividend / 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:371:
bool test_int_div(void) {
WriteFmt("Testing IntDiv generic dispatch\n");
DefaultAllocator alloc = DefaultAllocatorInit();- In
Math.c:378:
Int result_value = IntInit(&alloc.base);
IntDiv(&result_value, ÷nd, 10u);
bool result = IntToU64(&result_value) == 12;- In
Math.c:1026:
bool test_int_div_scalar_zero_divisor(void) {
WriteFmt("Testing IntDiv scalar zero-divisor handling\n");
DefaultAllocator alloc = DefaultAllocatorInit();- In
Math.c:1033:
Int quotient = IntFrom(99, &alloc.base);
IntDiv("ient, ÷nd, 0u);
bool result = IntCompare("ient, 99) == 0;- In
Math.c:2162:
// 1000 / 7 == 142 (floor).
bool ok = IntDiv("ient, ÷nd, (i64)7);
bool result = ok;
result = result && (IntToU64("ient) == 142u);- In
Math.c:2184:
Int quotient = IntFrom(55, &alloc.base);
bool failed = !IntDiv("ient, ÷nd, (i64)-7);
bool result = failed;- In
Math.c:2400:
/* Unsigned literal forces int_div_u64 dispatch. */
bool ok = IntDiv(&result_value, ÷nd, 7u);
bool result = ok && (IntToU64(&result_value) == 14);- In
Math.c:2770:
// (42). The quotient is left unchanged on failure.
bool test_fe_1487_div_u64_zero_returns_false(void) {
WriteFmt("Testing IntDiv u64 zero-divisor return value\n");
DefaultAllocator alloc = DefaultAllocatorInit();- In
Math.c:2777:
Int quotient = IntFrom(99, &alloc.base);
bool ok = IntDiv("ient, ÷nd, 0u);
bool result = (ok == false);
result = result && (IntCompare("ient, 99) == 0);- In
Math.c:2788:
bool test_fe_1500_div_i64_zero_returns_false(void) {
WriteFmt("Testing IntDiv i64 zero-divisor return value\n");
DefaultAllocator alloc = DefaultAllocatorInit();- In
Math.c:2795:
Int quotient = IntFrom(99, &alloc.base);
bool ok = IntDiv("ient, ÷nd, (i64)0);
bool result = (ok == false);
result = result && (IntCompare("ient, 99) == 0);- In
Math.c:3864:
Int r = IntFrom(7u, a);
bool ok = IntDiv(&r, &dvd, &dvs); // int_div frees remainder on success (1445)
ok = ok && IntToU64(&r) == 1000003u / 101u;- In
Math.c:3905:
Int r3 = IntFrom(7u, a);
bool ok = IntDiv(&r1, &dvd, 8u);
ok = ok && IntDivExact(&r2, &dvd, 8u);
ok = ok && IntDiv(&r3, &dvd, (i64)8);- In
Math.c:3907:
bool ok = IntDiv(&r1, &dvd, 8u);
ok = ok && IntDivExact(&r2, &dvd, 8u);
ok = ok && IntDiv(&r3, &dvd, (i64)8);
ok = ok && IntToU64(&r1) == 125u && IntToU64(&r2) == 125u && IntToU64(&r3) == 125u;
Last updated on