Skip to content

IntInit

Description

Create an empty integer with value 0.

This public macro supports both forms:

  • IntInit() - uses DefaultAllocator().
  • IntInit(alloc) - binds the supplied allocator.

Parameters

Name Direction Description
alloc in Optional allocator override.

Usage example (from documentation)

  Int value = IntInit();

Success

Returns a fresh empty Int representing zero, with the chosen allocator bound to its internal BitVec storage. No heap allocation happens until the integer is mutated.

Failure

Function cannot fail.

Usage example (Cross-references)

Usage examples (Cross-references)
    
        Str  temp   = StrInitFromCstr(start, i - start);
        Int  parsed = IntInit();
        bool ok     = IntTryFromStrRadix(&parsed, temp.data, radix);
        }
    
        *out = IntInit(alloc);
        if (value == 0) {
            return true;
        if (!BitVecTryFromIntegerAlloc(&out->bits, value, bits, alloc)) {
            IntDeinit(out);
            *out = IntInit(alloc);
            return false;
        }
        {
            u64 places = (u64)(value->exponent - target_exponent);
            Int factor = IntInit(value->significand.bits.allocator);
            Int scaled = IntInit(value->significand.bits.allocator);
            u64 places = (u64)(value->exponent - target_exponent);
            Int factor = IntInit(value->significand.bits.allocator);
            Int scaled = IntInit(value->significand.bits.allocator);
    
            if (!float_pow10(&factor, places, value->significand.bits.allocator) ||
    
        while (int_mod_u64(&value->significand, 10) == 0) {
            Int quotient = IntInit(value->significand.bits.allocator);
    
            (void)int_div_u64_rem(&quotient, &value->significand, 10);
    
    bool FloatToInt(Int *result, Float *value) {
        Int temp = IntInit(result->bits.allocator);
    
        ValidateInt(result);
    
        if (value->exponent >= 0) {
            Int factor = IntInit(value->significand.bits.allocator);
    
            if (!IntTryClone(&temp, &value->significand) ||
        {
            u64  places = (u64)(-value->exponent);
            Int  factor = IntInit(value->significand.bits.allocator);
            bool ok     = false;
    bool float_div(Float *result, Float *a, Float *b, u64 precision) {
        Float temp   = FloatInit(result->significand.bits.allocator);
        Int   scale  = IntInit(result->significand.bits.allocator);
        Int   scaled = IntInit(result->significand.bits.allocator);
        Float temp   = FloatInit(result->significand.bits.allocator);
        Int   scale  = IntInit(result->significand.bits.allocator);
        Int   scaled = IntInit(result->significand.bits.allocator);
    
        ValidateFloat(result);
        if (capacity != 0 && out->bits.capacity < capacity) {
            IntDeinit(out);
            *out = IntInit(alloc);
            return false;
        }
        }
    
        *out = IntInit(alloc);
        if (bits == 0) {
            return true;
        if (!BitVecTryFromIntegerAlloc(INT_BITS(out), value, bits, alloc)) {
            IntDeinit(out);
            *out = IntInit(alloc);
            return false;
        }
    
    static SignedInt sint_init(void) {
        SignedInt value = {.negative = false, .magnitude = IntInit()};
        return value;
    }
        Int lhs;
        Int rhs;
        Int result = IntInit(value->bits.allocator);
    
        if (!int_try_clone_value(&lhs, value)) {
        Int lhs;
        Int rhs;
        Int result = IntInit(value->bits.allocator);
    
        if (!int_try_clone_value(&lhs, value)) {
    
        ValidateInt(out);
        result = IntInit(out->bits.allocator);
    
        if (!int_validate_radix(radix)) {
    
        ValidateInt(value);
        *out = IntInit(value->bits.allocator);
        if (!BitVecTryClone(INT_BITS(out), INT_BITS(value))) {
            return false;
    
        ValidateInt(value);
        clone = IntInit(value->bits.allocator);
        (void)int_try_clone_value(&clone, value);
        return clone;
    
    Int int_from_u64(u64 value) {
        Int result = IntInit();
    
        (void)int_try_from_u64_with_allocator(&result, value, DefaultAllocator());
        }
    
        Int result = IntInit();
    
        if (len == 0) {
        }
    
        Int result = IntInit();
    
        for (u64 i = 0; i < len; i++) {
            if (!IntShiftLeft(&result, 8) || !int_add_u64_in_place(&result, bytes[i])) {
                IntDeinit(&result);
                return IntInit();
            }
        }
    
    Int IntFromStr(const char *decimal) {
        Int out = IntInit();
    
        (void)IntTryFromStr(&out, decimal);
    
    Int IntFromStrRadix(const char *digits, u8 radix) {
        Int out = IntInit();
    
        (void)IntTryFromStrRadix(&out, digits, radix);
    
        while (!IntIsZero(&current)) {
            Int quotient = IntInit();
            u64 digit    = 0;
    
    Int IntFromBinary(const char *binary) {
        Int out = IntInit();
    
        (void)IntTryFromBinary(&out, binary);
    
    Int IntFromOctStr(const char *octal) {
        Int out = IntInit();
    
        (void)IntTryFromOctStr(&out, octal);
    
    Int IntFromHexStr(const char *hex) {
        Int out = IntInit();
    
        (void)IntTryFromHexStr(&out, hex);
    
        u64 b_bits = IntBitLength(b);
        Int acc    = IntInit(result->bits.allocator);
    
        if (IntIsZero(a) || IntIsZero(b)) {
    
            Int partial;
            Int next = IntInit(result->bits.allocator);
    
            if (!int_try_clone_value(&partial, a)) {
        while (exponent > 0) {
            if (exponent & 1u) {
                Int next = IntInit(result->bits.allocator);
    
                if (!int_mul(&next, &acc, &current)) {
            exponent >>= 1u;
            if (exponent > 0) {
                Int next = IntInit(result->bits.allocator);
    
                if (!IntSquare(&next, &current)) {
        }
    
        Int  normalized_dividend = IntInit(quotient->bits.allocator);
        Int  normalized_divisor  = IntInit(quotient->bits.allocator);
        Int  q                   = IntInit(quotient->bits.allocator);
    
        Int  normalized_dividend = IntInit(quotient->bits.allocator);
        Int  normalized_divisor  = IntInit(quotient->bits.allocator);
        Int  q                   = IntInit(quotient->bits.allocator);
        Int  r                   = IntInit(remainder->bits.allocator);
        Int  normalized_dividend = IntInit(quotient->bits.allocator);
        Int  normalized_divisor  = IntInit(quotient->bits.allocator);
        Int  q                   = IntInit(quotient->bits.allocator);
        Int  r                   = IntInit(remainder->bits.allocator);
        bool ok                  = false;
        Int  normalized_divisor  = IntInit(quotient->bits.allocator);
        Int  q                   = IntInit(quotient->bits.allocator);
        Int  r                   = IntInit(remainder->bits.allocator);
        bool ok                  = false;
            for (u64 shift = dividend_bits - divisor_bits + 1; shift > 0; shift--) {
                u64 bit     = shift - 1;
                Int shifted = IntInit(quotient->bits.allocator);
    
                if (!int_try_clone_value(&shifted, &normalized_divisor) || !IntShiftLeft(&shifted, bit)) {
    
                if (IntGE(&r, &shifted)) {
                    Int next = IntInit();
    
                    if (!int_sub(&next, &r, &shifted)) {
        } else {
            IntDeinit(&q);
            q = IntInit();
        }
    
    bool int_div(Int *result, Int *dividend, Int *divisor) {
        Int quotient  = IntInit(result->bits.allocator);
        Int remainder = IntInit(result->bits.allocator);
    bool int_div(Int *result, Int *dividend, Int *divisor) {
        Int quotient  = IntInit(result->bits.allocator);
        Int remainder = IntInit(result->bits.allocator);
    
        if (!int_div_mod(&quotient, &remainder, dividend, divisor)) {
        }
    
        Int quotient  = IntInit(result->bits.allocator);
        Int remainder = IntInit(result->bits.allocator);
    
        Int quotient  = IntInit(result->bits.allocator);
        Int remainder = IntInit(result->bits.allocator);
    
        if (!int_div_mod(&quotient, &remainder, dividend, divisor)) {
    
    bool int_div_u64(Int *result, Int *dividend, u64 divisor) {
        Int divisor_value = IntInit(dividend->bits.allocator);
    
        if (!int_try_from_u64_with_allocator(&divisor_value, divisor, dividend->bits.allocator)) {
    
    bool int_div_i64(Int *result, Int *dividend, i64 divisor) {
        Int divisor_value = IntInit(dividend->bits.allocator);
    
        if (!int_try_from_i64_with_allocator(&divisor_value, divisor, dividend->bits.allocator)) {
    
    bool int_div_exact_u64(Int *result, Int *dividend, u64 divisor) {
        Int divisor_value = IntInit(dividend->bits.allocator);
    
        if (!int_try_from_u64_with_allocator(&divisor_value, divisor, dividend->bits.allocator)) {
    
    bool int_div_exact_i64(Int *result, Int *dividend, i64 divisor) {
        Int divisor_value = IntInit(dividend->bits.allocator);
    
        if (!int_try_from_i64_with_allocator(&divisor_value, divisor, dividend->bits.allocator)) {
    
    bool int_div_mod_u64(Int *quotient, Int *remainder, Int *dividend, u64 divisor) {
        Int divisor_value = IntInit(dividend->bits.allocator);
    
        if (!int_try_from_u64_with_allocator(&divisor_value, divisor, dividend->bits.allocator)) {
    
    bool int_div_mod_i64(Int *quotient, Int *remainder, Int *dividend, i64 divisor) {
        Int divisor_value = IntInit(dividend->bits.allocator);
    
        if (!int_try_from_i64_with_allocator(&divisor_value, divisor, dividend->bits.allocator)) {
        }
    
        Int divisor_value = IntInit(dividend->bits.allocator);
        Int remainder     = IntInit(quotient->bits.allocator);
        u64 rem           = 0;
    
        Int divisor_value = IntInit(dividend->bits.allocator);
        Int remainder     = IntInit(quotient->bits.allocator);
        u64 rem           = 0;
    
    bool int_mod(Int *result, Int *dividend, Int *divisor) {
        Int quotient  = IntInit(result->bits.allocator);
        Int remainder = IntInit(result->bits.allocator);
    bool int_mod(Int *result, Int *dividend, Int *divisor) {
        Int quotient  = IntInit(result->bits.allocator);
        Int remainder = IntInit(result->bits.allocator);
    
        if (!int_div_mod(&quotient, &remainder, dividend, divisor)) {
    
    bool int_mod_u64_into(Int *result, Int *dividend, u64 divisor) {
        Int quotient = IntInit(result->bits.allocator);
    
        bool ok = int_div_mod_u64(&quotient, result, dividend, divisor);
    
    bool int_mod_i64_into(Int *result, Int *dividend, i64 divisor) {
        Int quotient = IntInit(result->bits.allocator);
    
        bool ok = int_div_mod_i64(&quotient, result, dividend, divisor);
        }
    
        Int quotient = IntInit();
        u64 rem      = int_div_u64_rem(&quotient, value, modulus);
        ValidateInt(b);
    
        Int x = IntInit(a->bits.allocator);
        Int y = IntInit(b->bits.allocator);
    
        Int x = IntInit(a->bits.allocator);
        Int y = IntInit(b->bits.allocator);
    
        if (!int_try_clone_value(&x, a) || !int_try_clone_value(&y, b)) {
    
        while (!IntIsZero(&y)) {
            Int r = IntInit(result->bits.allocator);
    
            if (!int_mod(&r, &x, &y)) {
    
        if (IntIsZero(a) || IntIsZero(b)) {
            Int zero = IntInit(result->bits.allocator);
            int_replace(result, &zero);
            return true;
        }
    
        Int gcd      = IntInit(result->bits.allocator);
        Int quotient = IntInit(result->bits.allocator);
        Int lcm      = IntInit(result->bits.allocator);
    
        Int gcd      = IntInit(result->bits.allocator);
        Int quotient = IntInit(result->bits.allocator);
        Int lcm      = IntInit(result->bits.allocator);
        Int gcd      = IntInit(result->bits.allocator);
        Int quotient = IntInit(result->bits.allocator);
        Int lcm      = IntInit(result->bits.allocator);
    
        if (!IntGCD(&gcd, a, b) || !int_div(&quotient, a, &gcd) || !int_mul(&lcm, &quotient, b)) {
    
        if (IntIsZero(value)) {
            Int zero_root = IntInit(root->bits.allocator);
            Int zero_rem  = IntInit(remainder->bits.allocator);
        if (IntIsZero(value)) {
            Int zero_root = IntInit(root->bits.allocator);
            Int zero_rem  = IntInit(remainder->bits.allocator);
    
            int_replace(root, &zero_root);
        }
        if (degree == 1) {
            Int exact_root = IntInit(root->bits.allocator);
            Int zero_rem   = IntInit(remainder->bits.allocator);
        if (degree == 1) {
            Int exact_root = IntInit(root->bits.allocator);
            Int zero_rem   = IntInit(remainder->bits.allocator);
    
            if (!IntTryClone(&exact_root, value)) {
        u64 bits       = IntBitLength(value);
        u64 high_shift = bits / degree;
        Int low        = IntInit(root->bits.allocator);
        Int high       = IntInit(root->bits.allocator);
        Int best       = IntInit(root->bits.allocator);
        u64 high_shift = bits / degree;
        Int low        = IntInit(root->bits.allocator);
        Int high       = IntInit(root->bits.allocator);
        Int best       = IntInit(root->bits.allocator);
        Int one        = IntInit(root->bits.allocator);
        Int low        = IntInit(root->bits.allocator);
        Int high       = IntInit(root->bits.allocator);
        Int best       = IntInit(root->bits.allocator);
        Int one        = IntInit(root->bits.allocator);
        Int high       = IntInit(root->bits.allocator);
        Int best       = IntInit(root->bits.allocator);
        Int one        = IntInit(root->bits.allocator);
    
        if ((bits % degree) != 0) {
    
        while (IntLE(&low, &high)) {
            Int sum     = IntInit(root->bits.allocator);
            Int mid     = IntInit(root->bits.allocator);
            Int mid_pow = IntInit(root->bits.allocator);
        while (IntLE(&low, &high)) {
            Int sum     = IntInit(root->bits.allocator);
            Int mid     = IntInit(root->bits.allocator);
            Int mid_pow = IntInit(root->bits.allocator);
            int cmp     = 0;
            Int sum     = IntInit(root->bits.allocator);
            Int mid     = IntInit(root->bits.allocator);
            Int mid_pow = IntInit(root->bits.allocator);
            int cmp     = 0;
    
            if (cmp <= 0) {
                Int next = IntInit(root->bits.allocator);
    
                IntDeinit(&best);
                low = next;
            } else {
                Int next = IntInit(root->bits.allocator);
    
                if (IntEQ(&mid, &one) || IntIsZero(&mid)) {
                if (IntEQ(&mid, &one) || IntIsZero(&mid)) {
                    IntDeinit(&high);
                    high = IntInit(root->bits.allocator);
                } else {
                    if (!int_sub(&next, &mid, &one)) {
    
        {
            Int power = IntInit(root->bits.allocator);
            Int rem   = IntInit(remainder->bits.allocator);
        {
            Int power = IntInit(root->bits.allocator);
            Int rem   = IntInit(remainder->bits.allocator);
    
            if (!int_pow_u64(&power, &best, degree) || !int_sub(&rem, value, &power)) {
    
    bool IntRoot(Int *result, Int *value, u64 degree) {
        Int root      = IntInit(result->bits.allocator);
        Int remainder = IntInit(result->bits.allocator);
    bool IntRoot(Int *result, Int *value, u64 degree) {
        Int root      = IntInit(result->bits.allocator);
        Int remainder = IntInit(result->bits.allocator);
    
        if (!IntRootRem(&root, &remainder, value, degree)) {
        ValidateInt(value);
    
        Int  root      = IntInit();
        Int  remainder = IntInit();
        bool result    = false;
    
        Int  root      = IntInit();
        Int  remainder = IntInit();
        bool result    = false;
    
        for (u64 degree = 2; degree <= max_degree; degree++) {
            Int  root      = IntInit();
            Int  remainder = IntInit();
            bool exact     = false;
        for (u64 degree = 2; degree <= max_degree; degree++) {
            Int  root      = IntInit();
            Int  remainder = IntInit();
            bool exact     = false;
        }
    
        Int aa     = IntInit(a->bits.allocator);
        Int nn     = IntInit(n->bits.allocator);
        int result = 1;
    
        Int aa     = IntInit(a->bits.allocator);
        Int nn     = IntInit(n->bits.allocator);
        int result = 1;
        }
    
        Int ar  = IntInit(result->bits.allocator);
        Int br  = IntInit(result->bits.allocator);
        Int sum = IntInit(result->bits.allocator);
    
        Int ar  = IntInit(result->bits.allocator);
        Int br  = IntInit(result->bits.allocator);
        Int sum = IntInit(result->bits.allocator);
        Int ar  = IntInit(result->bits.allocator);
        Int br  = IntInit(result->bits.allocator);
        Int sum = IntInit(result->bits.allocator);
    
        if (!int_mod(&ar, a, modulus) || !int_mod(&br, b, modulus) || !int_add(&sum, &ar, &br) ||
        }
    
        Int ar = IntInit(result->bits.allocator);
        Int br = IntInit(result->bits.allocator);
    
        Int ar = IntInit(result->bits.allocator);
        Int br = IntInit(result->bits.allocator);
    
        if (!int_mod(&ar, a, modulus) || !int_mod(&br, b, modulus)) {
            }
        } else {
            Int diff = IntInit(result->bits.allocator);
    
            if (!int_sub(&diff, &br, &ar)) {
            }
            if (IntIsZero(&diff)) {
                Int zero = IntInit(result->bits.allocator);
                int_replace(result, &zero);
            } else {
        }
    
        Int ar   = IntInit();
        Int br   = IntInit();
        Int prod = IntInit();
    
        Int ar   = IntInit();
        Int br   = IntInit();
        Int prod = IntInit();
        Int ar   = IntInit();
        Int br   = IntInit();
        Int prod = IntInit();
    
        if (!int_mod(&ar, a, modulus) || !int_mod(&br, b, modulus) || !int_mul(&prod, &ar, &br) ||
        }
    
        Int  inverse = IntInit();
        Int  value   = IntInit();
        bool ok      = false;
    
        Int  inverse = IntInit();
        Int  value   = IntInit();
        bool ok      = false;
        }
    
        Int acc      = IntInit(result->bits.allocator);
        Int base_mod = IntInit();
    
        Int acc      = IntInit(result->bits.allocator);
        Int base_mod = IntInit();
    
        if (!int_try_from_u64_with_allocator(&acc, 1, result->bits.allocator)) {
        while (exponent > 0) {
            if (exponent & 1u) {
                Int next = IntInit();
    
                if (!IntModMul(&next, &acc, &base_mod, modulus)) {
            exponent >>= 1u;
            if (exponent > 0) {
                Int next = IntInit();
    
                if (!IntModMul(&next, &base_mod, &base_mod, modulus)) {
        }
    
        Int acc      = IntInit(result->bits.allocator);
        Int base_mod = IntInit();
        Int exp      = IntInit(exponent->bits.allocator);
    
        Int acc      = IntInit(result->bits.allocator);
        Int base_mod = IntInit();
        Int exp      = IntInit(exponent->bits.allocator);
        Int acc      = IntInit(result->bits.allocator);
        Int base_mod = IntInit();
        Int exp      = IntInit(exponent->bits.allocator);
    
        if (!int_try_from_u64_with_allocator(&acc, 1, result->bits.allocator) || !IntTryClone(&exp, exponent) ||
        while (!IntIsZero(&exp)) {
            if (int_is_odd(&exp)) {
                Int next = IntInit();
    
                if (!IntModMul(&next, &acc, &base_mod, modulus)) {
            }
            if (!IntIsZero(&exp)) {
                Int next = IntInit();
    
                if (!IntModMul(&next, &base_mod, &base_mod, modulus)) {
        }
    
        Int       reduced = IntInit();
        SignedInt t       = sint_init();
        SignedInt new_t   = sint_from_u64(1);
        SignedInt t       = sint_init();
        SignedInt new_t   = sint_from_u64(1);
        Int       r       = IntInit(modulus->bits.allocator);
        Int       new_r   = IntInit();
        Int       one     = int_from_u64(1);
        SignedInt new_t   = sint_from_u64(1);
        Int       r       = IntInit(modulus->bits.allocator);
        Int       new_r   = IntInit();
        Int       one     = int_from_u64(1);
        bool      ok      = false;
    
        while (!IntIsZero(&new_r)) {
            Int       q       = IntInit();
            Int       rem     = IntInit();
            SignedInt q_new_t = sint_init();
        while (!IntIsZero(&new_r)) {
            Int       q       = IntInit();
            Int       rem     = IntInit();
            SignedInt q_new_t = sint_init();
            SignedInt next_t  = sint_init();
            SignedInt q_new_t = sint_init();
            SignedInt next_t  = sint_init();
            Int       next_r  = IntInit();
    
            if (!int_div_mod(&q, &rem, &r, &new_r) || !sint_mul_unsigned(&q_new_t, &new_t, &q) ||
    
        if (IntEQ(&r, &one)) {
            Int positive = IntInit();
            Int mag_mod  = IntInit();
        if (IntEQ(&r, &one)) {
            Int positive = IntInit();
            Int mag_mod  = IntInit();
    
            if (!int_mod(&mag_mod, &t.magnitude, modulus)) {
        }
    
        Int  a  = IntInit();
        bool ok = false;
    
        if (IntIsZero(&a)) {
            Int zero = IntInit();
            int_replace(result, &zero);
            IntDeinit(&a);
        }
        if (int_mod_u64(modulus, 4) == 3) {
            Int exponent = IntInit(modulus->bits.allocator);
            Int root     = IntInit();
        if (int_mod_u64(modulus, 4) == 3) {
            Int exponent = IntInit(modulus->bits.allocator);
            Int root     = IntInit();
    
            if (!IntTryClone(&exponent, modulus) || !int_add_u64(&exponent, &exponent, 1) || !IntShiftRight(&exponent, 2) ||
    
        {
            Int q        = IntInit(modulus->bits.allocator);
            Int z        = IntInit(modulus->bits.allocator);
            Int c        = IntInit();
        {
            Int q        = IntInit(modulus->bits.allocator);
            Int z        = IntInit(modulus->bits.allocator);
            Int c        = IntInit();
            Int t        = IntInit();
            Int q        = IntInit(modulus->bits.allocator);
            Int z        = IntInit(modulus->bits.allocator);
            Int c        = IntInit();
            Int t        = IntInit();
            Int r        = IntInit();
            Int z        = IntInit(modulus->bits.allocator);
            Int c        = IntInit();
            Int t        = IntInit();
            Int r        = IntInit();
            Int exponent = IntInit();
            Int c        = IntInit();
            Int t        = IntInit();
            Int r        = IntInit();
            Int exponent = IntInit();
            u64 m        = 0;
            Int t        = IntInit();
            Int r        = IntInit();
            Int exponent = IntInit();
            u64 m        = 0;
    
            while (int_compare_u64(&t, 1) != 0) {
                Int t_power = IntInit(t.bits.allocator);
                u64 i       = 0;
    
                for (i = 1; i < m; i++) {
                    Int next = IntInit();
    
                    if (!IntSquareMod(&next, &t_power, modulus)) {
    
                {
                    Int b    = IntInit(c.bits.allocator);
                    Int b_sq = IntInit();
                    Int next = IntInit();
                {
                    Int b    = IntInit(c.bits.allocator);
                    Int b_sq = IntInit();
                    Int next = IntInit();
                    Int b    = IntInit(c.bits.allocator);
                    Int b_sq = IntInit();
                    Int next = IntInit();
    
                    if (!IntTryClone(&b, &c)) {
    
                    for (u64 j = 0; j + i + 1 < m; j++) {
                        Int square = IntInit();
    
                        if (!IntSquareMod(&square, &b, modulus)) {
                        return false;
                    }
                    next = IntInit();
                    if (!IntModMul(&next, &t, &b_sq, modulus)) {
                        IntDeinit(&b);
    
        {
            Int  d           = IntInit(value->bits.allocator);
            Int  n_minus_one = IntInit(value->bits.allocator);
            u64  s           = 0;
        {
            Int  d           = IntInit(value->bits.allocator);
            Int  n_minus_one = IntInit(value->bits.allocator);
            u64  s           = 0;
            bool probable    = true;
    
            for (u64 i = 0; i < (u64)(sizeof(bases) / sizeof(bases[0])); i++) {
                Int base = IntInit(value->bits.allocator);
                Int x    = IntInit(value->bits.allocator);
            for (u64 i = 0; i < (u64)(sizeof(bases) / sizeof(bases[0])); i++) {
                Int base = IntInit(value->bits.allocator);
                Int x    = IntInit(value->bits.allocator);
    
                if (!int_try_from_u64_with_allocator(&base, bases[i], value->bits.allocator)) {
    
                    for (u64 r = 1; r < s; r++) {
                        Int next = IntInit(value->bits.allocator);
    
                        if (!IntSquareMod(&next, &x, value)) {
    
        if (int_compare_u64(value, 1) <= 0) {
            Int two = IntInit(result->bits.allocator);
    
            if (!int_try_from_u64_with_allocator(&two, 2, result->bits.allocator)) {
        }
    
        Int candidate = IntInit(result->bits.allocator);
    
        if (!IntTryClone(&candidate, value)) {
        }
        if (int_compare_u64(&candidate, 2) <= 0) {
            Int two = IntInit(result->bits.allocator);
    
            if (!int_try_from_u64_with_allocator(&two, 2, result->bits.allocator)) {
    
        Int parsed = IntFromBinary("10a1");
        Int value  = IntInit();
        bool result = !IntTryFromBinary(&value, "10a1");
    
        Int parsed = IntFromStr("12x3");
        Int value  = IntInit();
        bool result = !IntTryFromStr(&value, "12x3");
    
        Int parsed = IntFromHexStr("12g3");
        Int value  = IntInit();
        bool result = !IntTryFromHexStr(&value, "12g3");
    
        Int parsed = IntFromStrRadix("102", 2);
        Int value  = IntInit();
        bool result = !IntTryFromStrRadix(&value, "102", 2);
    
        Int parsed = IntFromStrRadix("10", 1);
        Int value  = IntInit();
        bool result = !IntTryFromStrRadix(&value, "10", 1);
    
        Int parsed = IntFromBinary(NULL);
        Int value  = IntInit();
        bool result = !IntTryFromBinary(&value, NULL);
    
        Int parsed = IntFromStr(NULL);
        Int value  = IntInit();
        bool result = !IntTryFromStr(&value, NULL);
    
        Int parsed = IntFromStrRadix(NULL, 10);
        Int value  = IntInit();
        bool result = !IntTryFromStrRadix(&value, NULL, 10);
    
        Int parsed = IntFromOctStr(NULL);
        Int value  = IntInit();
        bool result = !IntTryFromOctStr(&value, NULL);
    
        Int parsed = IntFromHexStr(NULL);
        Int value  = IntInit();
        bool result = !IntTryFromHexStr(&value, NULL);
        bool        success = true;
    
        Int dec = IntInit();
        Int hex = IntInit();
        Int bin = IntInit();
    
        Int dec = IntInit();
        Int hex = IntInit();
        Int bin = IntInit();
        Int oct = IntInit();
        Int dec = IntInit();
        Int hex = IntInit();
        Int bin = IntInit();
        Int oct = IntInit();
        Int hex = IntInit();
        Int bin = IntInit();
        Int oct = IntInit();
    
        Str dec_text = StrInit();
        WriteFmt("Testing IntIsZero\n");
    
        Int zero     = IntInit();
        Int non_zero = IntFrom(1);
    
        Int value = IntFromBinary("1010000");
        Int zero  = IntInit();
    
        bool result = IntTrailingZeroCount(&value) == 4;
        Int power = IntFrom(1);
        Int other = IntFrom(24);
        Int zero  = IntInit();
    
        IntShiftLeft(&power, 20);
        WriteFmt("Testing IntLog2 zero handling\n");
    
        Int  value = IntInit();
        bool error = false;
    
        Float value        = FloatFromStr("1234500e-2");
        Int   result_value = IntInit();
        Str   text         = StrInit();
        Int a      = IntFrom(255);
        Int b      = IntFrom(1);
        Int result_value = IntInit();
        Str text   = StrInit();
        Int base         = IntFrom(40);
        Int rhs          = IntFrom(2);
        Int result_value = IntInit();
        Int huge         = IntFromStr("123456789012345678901234567890");
        Str text         = StrInit();
        Int a      = IntFrom(256);
        Int b      = IntFrom(1);
        Int result_value = IntInit();
    
        bool result = IntSub(&result_value, &a, &b);
        Int base         = IntFrom(40);
        Int rhs          = IntFrom(2);
        Int result_value = IntInit();
        Int preserved    = IntFrom(99);
        Int huge         = IntFromStr("12345678901234567890");
        Int a      = IntFrom(21);
        Int b      = IntFrom(6);
        Int result_value = IntInit();
    
        IntMul(&result_value, &a, &b);
    
        Int value = IntFromStr("12345678901234567890");
        Int result_value = IntInit();
        Str text = StrInit();
        Int a      = IntFrom(0);
        Int b      = IntFrom(12345);
        Int result_value = IntInit();
    
        IntMul(&result_value, &a, &b);
    
        Int value = IntFrom(12345);
        Int result_value = IntInit();
    
        IntSquare(&result_value, &value);
        Int base = IntFrom(7);
        Int exponent = IntFrom(20);
        Int result_value = IntInit();
        Str text = StrInit();
    
        Int dividend  = IntFromStr("12345678901234567890");
        Int quotient  = IntInit();
        Int remainder = IntInit();
        Str qtext     = StrInit();
        Int dividend  = IntFromStr("12345678901234567890");
        Int quotient  = IntInit();
        Int remainder = IntInit();
        Str qtext     = StrInit();
    
        Int dividend = IntFrom(126);
        Int result_value = IntInit();
    
        IntDiv(&result_value, &dividend, 10u);
    
        Int dividend = IntFromStr("12345678901234567890");
        Int result_value = IntInit();
        Str text = StrInit();
    
        Int dividend = IntFromStr("12345678901234567890");
        Int quotient = IntInit();
        Int remainder = IntInit();
        Str text = StrInit();
        Int dividend = IntFromStr("12345678901234567890");
        Int quotient = IntInit();
        Int remainder = IntInit();
        Str text = StrInit();
    
        Int dividend = IntFrom(126);
        Int result_value = IntInit();
    
        IntMod(&result_value, &dividend, 10u);
    
        Int value = IntFromStr("12345678901234567890");
        Int remainder = IntInit();
    
        IntMod(&remainder, &value, 97u);
        Int a = IntFrom(48);
        Int b = IntFrom(18);
        Int result_value = IntInit();
    
        IntGCD(&result_value, &a, &b);
        Int a = IntFrom(21);
        Int b = IntFrom(6);
        Int result_value = IntInit();
    
        IntLCM(&result_value, &a, &b);
    
        Int value = IntFrom(4096);
        Int result_value = IntInit();
    
        IntRoot(&result_value, &value, 4);
    
        Int value = IntFrom(200);
        Int root = IntInit();
        Int remainder = IntInit();
        Int value = IntFrom(200);
        Int root = IntInit();
        Int remainder = IntInit();
    
        IntRootRem(&root, &remainder, &value, 3);
    
        Int value = IntFrom(200);
        Int result_value = IntInit();
    
        IntSqrt(&result_value, &value);
    
        Int value = IntFrom(200);
        Int root = IntInit();
        Int remainder = IntInit();
        Int value = IntFrom(200);
        Int root = IntInit();
        Int remainder = IntInit();
    
        IntSqrtRem(&root, &remainder, &value);
        Int value = IntFrom(12345);
        Int mod = IntFrom(97);
        Int result_value = IntInit();
    
        IntSquareMod(&result_value, &value, &mod);
        Int b = IntFrom(250);
        Int m = IntFrom(13);
        Int result_value = IntInit();
    
        IntModAdd(&result_value, &a, &b, &m);
        Int b = IntFrom(9);
        Int m = IntFrom(13);
        Int result_value = IntInit();
    
        IntModSub(&result_value, &a, &b, &m);
        Int b = IntFrom(456);
        Int m = IntFrom(97);
        Int result_value = IntInit();
    
        IntModMul(&result_value, &a, &b, &m);
        Int b = IntFrom(3);
        Int m = IntFrom(13);
        Int result_value = IntInit();
        Int check = IntInit();
        Int m = IntFrom(13);
        Int result_value = IntInit();
        Int check = IntInit();
    
        bool result = IntModDiv(&result_value, &a, &b, &m);
        Int base = IntFrom(7);
        Int mod = IntFrom(13);
        Int result_value = IntInit();
    
        IntPowMod(&result_value, &base, 20u, &mod);
        Int exp = IntFrom(13);
        Int mod = IntFrom(497);
        Int result_value = IntInit();
    
        IntPowMod(&result_value, &base, &exp, &mod);
        Int value = IntFrom(3);
        Int mod = IntFrom(11);
        Int result_value = IntInit();
        Int check = IntInit();
        Int mod = IntFrom(11);
        Int result_value = IntInit();
        Int check = IntInit();
    
        bool result = IntModInv(&result_value, &value, &mod);
        Int value = IntFrom(10);
        Int mod = IntFrom(13);
        Int root = IntInit();
        Int check = IntInit();
        Int mod = IntFrom(13);
        Int root = IntInit();
        Int check = IntInit();
    
        bool result = IntModSqrt(&root, &value, &mod);
    
        Int value = IntFromStr("1000000000");
        Int next = IntInit();
        Str text = StrInit();
    
        Int dividend  = IntFrom(1);
        Int divisor   = IntInit();
        Int quotient  = IntFrom(99);
        Int remainder = IntFrom(77);
        Int a            = IntFrom(10);
        Int b            = IntFrom(3);
        Int m            = IntInit();
        Int result_value = IntFrom(99);
    
        Int base = IntFrom(2);
        Int mod = IntInit();
        Int result_value = IntInit();
        Int base = IntFrom(2);
        Int mod = IntInit();
        Int result_value = IntInit();
    
        IntPowMod(&result_value, &base, 8u, &mod);
        Int base         = IntFrom(2);
        Int exp          = IntFrom(8);
        Int mod          = IntInit();
        Int result_value = IntFrom(99);
    
    bool test_int_init(void) {
        WriteFmt("Testing IntInit\n");
    
        Int value = IntInit();
        WriteFmt("Testing IntInit\n");
    
        Int value = IntInit();
    
        bool result = IntIsZero(&value);
        alloc.flags = 0x4B4Bu;
    
        Int original = IntInit(alloc);
        original.bits.allocator.state = (void *)&original;
    
        value.negative    = false;
        value.significand = IntInit(alloc);
        value.exponent    = 0;
        return value;
Last updated on