IntSqrtRem
Description
Compute the integer square root and remainder.
Parameters
| Name | Direction | Description |
|---|---|---|
root |
out | Destination for the root |
remainder |
out | Destination for the remainder |
value |
in | Input value |
Usage example (from documentation)
IntSqrtRem(&root, &rem, &value);Success
Returns true. *root holds floor(sqrt(value)), *remainder holds value - root^2.
Failure
Returns false on allocator OOM. *root / *remainder are left untouched.
Usage example (Cross-references)
Usage examples (Cross-references)
- In
Int.c:2179:
}
bool IntSqrtRem(Int *root, Int *remainder, const Int *value) {
return IntRootRem(root, remainder, value, 2);
}- In
Int.c:2194:
bool result = false;
if (!IntSqrtRem(&root, &remainder, value)) {
IntDeinit(&root);
IntDeinit(&remainder);- In
Math.c:584:
bool test_int_sqrt_rem(void) {
WriteFmt("Testing IntSqrtRem\n");
DefaultAllocator alloc = DefaultAllocatorInit();- In
Math.c:592:
Int remainder = IntInit(&alloc.base);
IntSqrtRem(&root, &remainder, &value);
bool result = IntToU64(&root) == 14;- In
Math.c:2938:
Int remainder = IntInit(&alloc.base);
bool ok = IntSqrtRem(&root, &remainder, &value);
bool result = ok && (IntToU64(&root) == 33554432u); // 2^25
result = result && (IntToU64(&remainder) == 0);
Last updated on