IntRoot
Description
Compute the integer degree-th root of a value (floor).
Parameters
| Name | Direction | Description |
|---|---|---|
result |
out | Destination for the root |
value |
in | Input value |
degree |
in | Root degree |
Usage example (from documentation)
IntRoot(&root, &value, 3);Success
Returns true. *result holds floor(value^(1/degree)).
Failure
Returns false on degree == 0 or allocator OOM. *result is left untouched.
Usage example (Cross-references)
Usage examples (Cross-references)
- In
Int.c:2164:
}
bool IntRoot(Int *result, const Int *value, u64 degree) {
Int root = IntInit(IntAllocator(result));
Int remainder = IntInit(IntAllocator(result));- In
Int.c:2184:
bool IntSqrt(Int *result, const Int *value) {
return IntRoot(result, value, 2);
}- In
Math.c:527:
bool test_int_root(void) {
WriteFmt("Testing IntRoot\n");
DefaultAllocator alloc = DefaultAllocatorInit();- In
Math.c:534:
Int result_value = IntInit(&alloc.base);
IntRoot(&result_value, &value, 4);
bool result = IntToU64(&result_value) == 8;- In
Math.c:1006:
bool test_int_root_zero_degree(void) {
WriteFmt("Testing IntRoot zero-degree handling\n");
DefaultAllocator alloc = DefaultAllocatorInit();- In
Math.c:2581:
///
bool test_m26_root_value(void) {
WriteFmt("Testing IntRoot success contract\n");
DefaultAllocator alloc = DefaultAllocatorInit();- In
Math.c:2588:
Int result_value = IntInit(&alloc.base);
bool ok = IntRoot(&result_value, &value, 4);
bool result = ok;- In
Math.c:4079:
Int r = IntFrom(7u, a);
bool ok = IntRoot(&r, &v, 3); // frees remainder on success (1877)
ok = ok && IntToU64(&r) == 100u;
Last updated on