IntDivExact
Description
Generic exact-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)
bool ok = IntDivExact("ient, &value, 5u);Success
Returns true when the division is exact.
Failure
Returns false otherwise.
Usage example (Cross-references)
Usage examples (Cross-references)
- In
Math.c:389:
bool test_int_div_exact(void) {
WriteFmt("Testing IntDivExact generic dispatch\n");
DefaultAllocator alloc = DefaultAllocatorInit();- In
Math.c:397:
Str text = StrInit(&alloc.base);
bool result = IntDivExact(&result_value, ÷nd, 90u);
text = IntToStr(&result_value);
result = result && (ZstrCompare(StrBegin(&text), "137174210013717421") == 0);- In
Math.c:409:
bool test_int_div_exact_failure_preserves_result(void) {
WriteFmt("Testing IntDivExact failure handling\n");
DefaultAllocator alloc = DefaultAllocatorInit();- In
Math.c:417:
Int result_value = IntFrom(99, &alloc.base);
bool result = !IntDivExact(&result_value, ÷nd, &divisor);
result = result && (IntToU64(&result_value) == 99);- In
Math.c:1908:
Int divisor = IntFrom(4, &alloc.base);
IntDivExact(NULL, ÷nd, &divisor);
IntDeinit(÷nd);- In
Math.c:2208:
// 1001 / 7 == 143 exactly.
bool ok = IntDivExact("ient, ÷nd, (i64)7);
bool result = ok;
result = result && (IntToU64("ient) == 143u);- In
Math.c:2228:
Int quotient = IntFrom(55, &alloc.base);
bool failed = !IntDivExact("ient, ÷nd, (i64)-7);
bool result = failed;- In
Math.c:2810:
// divisible by 10, so real code returns false, mutant returns true.
bool test_fe_1513_div_exact_u64_inexact_false(void) {
WriteFmt("Testing IntDivExact u64 inexact return value\n");
DefaultAllocator alloc = DefaultAllocatorInit();- In
Math.c:2817:
Int quotient = IntInit(&alloc.base);
bool ok = IntDivExact("ient, ÷nd, 10u);
bool result = (ok == false);- In
Math.c:2827:
bool test_fe_1526_div_exact_i64_inexact_false(void) {
WriteFmt("Testing IntDivExact i64 inexact return value\n");
DefaultAllocator alloc = DefaultAllocatorInit();- In
Math.c:2834:
Int quotient = IntInit(&alloc.base);
bool ok = IntDivExact("ient, ÷nd, (i64)10);
bool result = (ok == false);- In
Math.c:3883:
Int r = IntFrom(7u, a);
bool ok = IntDivExact(&r, &dvd, &dvs); // frees remainder on success (1474)
ok = ok && IntToU64(&r) == 125u;- In
Math.c:3906:
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;- In
Math.c:4676:
Int r = IntFrom(7u, a);
bool ok = IntDivExact(&r, &dvd, (i64)8);
ok = ok && IntToU64(&r) == 125u;
Last updated on