Skip to content

IntRootRem

Description

Compute an integer root and the leftover remainder.

Parameters

Name Direction Description
root out Destination for the root
remainder out Destination for the remainder
value in Input value
degree in Root degree

Usage example (from documentation)

  IntRootRem(&root, &rem, &value, 3);

Success

Returns true. *root holds floor(value^(1/degree)), *remainder holds value - root^degree.

Failure

Returns false on degree == 0 or allocator OOM. *root / *remainder are left untouched.

Usage example (Cross-references)

Usage examples (Cross-references)
    }
    
    bool IntRootRem(Int *root, Int *remainder, const Int *value, u64 degree) {
        ValidateInt(root);
        ValidateInt(remainder);
        Int remainder = IntInit(IntAllocator(result));
    
        if (!IntRootRem(&root, &remainder, value, degree)) {
            IntDeinit(&root);
            IntDeinit(&remainder);
    
    bool IntSqrtRem(Int *root, Int *remainder, const Int *value) {
        return IntRootRem(root, remainder, value, 2);
    }
            bool exact     = false;
    
            if (!IntRootRem(&root, &remainder, value, degree)) {
                IntDeinit(&root);
                IntDeinit(&remainder);
    
    bool test_int_root_rem(void) {
        WriteFmt("Testing IntRootRem\n");
    
        DefaultAllocator alloc = DefaultAllocatorInit();
        Int remainder = IntInit(&alloc.base);
    
        IntRootRem(&root, &remainder, &value, 3);
    
        bool result = IntToU64(&root) == 5;
        Int  root      = IntFrom(99, &alloc.base);
        Int  remainder = IntFrom(77, &alloc.base);
        bool result    = !IntRootRem(&root, &remainder, &value, 0);
    
        result = result && (IntCompare(&root, 99) == 0);
Last updated on