Skip to content

IntTryClone

Description

Create a deep copy of an integer.

Parameters

Name Direction Description
out in,out Destination Int that receives the clone. Must already be a valid initialised Int; its existing storage is deinitialised before the copy is installed.
value in Source Int to clone. Not modified.

Success

Returns true. *out holds an independent deep copy of value’s bit-vector, normalised, and bound to value’s allocator.

Failure

Returns false on allocation failure while copying the bit-vector. *out is left as a freshly initialised empty Int bound to value’s allocator.

Usage example (Cross-references)

Usage examples (Cross-references)
    }
    
    bool IntTryClone(Int *out, const Int *value) {
        return int_try_clone_value(out, value);
    }
            Int zero_rem   = IntInit(IntAllocator(remainder));
    
            if (!IntTryClone(&exact_root, value)) {
                IntDeinit(&exact_root);
                IntDeinit(&zero_rem);
    
                IntDeinit(&best);
                if (!IntTryClone(&best, &mid)) {
                    IntDeinit(&mid_pow);
                    IntDeinit(&mid);
        Int exp      = IntInit(IntAllocator(exponent));
    
        if (!int_try_from_u64(&acc, 1, IntAllocator(result)) || !IntTryClone(&exp, exponent) ||
            !int_mod(&acc, &acc, modulus) || !int_mod(&base_mod, base, modulus)) {
            IntDeinit(&acc);
        bool      ok      = false;
    
        if (!IntTryClone(&r, modulus) || !int_mod(&reduced, value, modulus)) {
            IntDeinit(&reduced);
            IntDeinit(&r);
            return false;
        }
        if (!IntTryClone(&new_r, &reduced)) {
            IntDeinit(&reduced);
            IntDeinit(&r);
            Int root     = IntInit(IntAllocator(result));
    
            if (!IntTryClone(&exponent, modulus) || !int_add_u64(&exponent, &exponent, 1) || !IntShiftRight(&exponent, 2) ||
                !int_pow_mod(&root, &a, &exponent, modulus)) {
                IntDeinit(&exponent);
            u64 m        = 0;
    
            if (!IntTryClone(&q, modulus) || !int_try_from_u64(&z, 2, IntAllocator(modulus)) || !int_sub_u64(&q, &q, 1)) {
                IntDeinit(&q);
                IntDeinit(&z);
            }
    
            if (!IntTryClone(&exponent, &q) || !int_add_u64(&exponent, &exponent, 1) || !IntShiftRight(&exponent, 1) ||
                !int_pow_mod(&r, &a, &exponent, modulus)) {
                IntDeinit(&q);
                u64 i       = 0;
    
                if (!IntTryClone(&t_power, &t)) {
                    IntDeinit(&t_power);
                    IntDeinit(&q);
                    Int next = IntInit(IntAllocator(result));
    
                    if (!IntTryClone(&b, &c)) {
                        IntDeinit(&b);
                        IntDeinit(&b_sq);
            bool probable    = true;
    
            if (!IntTryClone(&d, value) || !int_sub_u64(&d, &d, 1)) {
                IntDeinit(&d);
                IntDeinit(&n_minus_one);
                return false;
            }
            if (!IntTryClone(&n_minus_one, &d)) {
                IntDeinit(&d);
                IntDeinit(&n_minus_one);
        Int candidate = IntInit(IntAllocator(result));
    
        if (!IntTryClone(&candidate, value)) {
            IntDeinit(&candidate);
            return false;
        out->negative = value->negative;
        out->exponent = value->exponent;
        if (!IntTryClone(&out->significand, &value->significand)) {
            FloatDeinit(out);
            *out = FloatInit(FloatAllocator(value));
        ValidateInt(value);
        *out = FloatInit(IntAllocator(value));
        if (!IntTryClone(&out->significand, value)) {
            FloatDeinit(out);
            *out = FloatInit(IntAllocator(value));
            Int factor = IntInit(FloatAllocator(value));
    
            if (!IntTryClone(&temp, &value->significand) ||
                !float_pow10(&factor, (u64)value->exponent, FloatAllocator(value)) || !int_mul(&temp, &temp, &factor)) {
                IntDeinit(&factor);
Last updated on