Skip to content

IntInit

Description

Initialize an Int (numeric value 0). Inside a Scope block the allocator argument may be omitted (MisraScope is used). Otherwise pass a typed allocator handle or a raw Allocator *.

Usage example (from documentation)

  Scope(alloc, DefaultAllocator) {
      Int value = IntInit();
      ...
  }

Success

Returns a numerically-zero Int whose backing bitvector is bound to the chosen allocator.

Failure

Cannot fail at construction; first allocator OOM surfaces from later math/grow.

Usage example (Cross-references)

Usage examples (Cross-references)
    
        Str  temp   = StrInitFromCstr(start, StrIterIndex(&si) - StrIterIndex(&saved), IntAllocator(value));
        Int  parsed = IntInit(IntAllocator(value));
        bool ok     = IntTryFromStrRadix(&parsed, StrBegin(&temp), radix);
        if (capacity != 0 && BitVecCapacity(INT_BITS(out)) < capacity) {
            IntDeinit(out);
            *out = IntInit(alloc);
            return false;
        }
        }
    
        *out = IntInit(alloc);
        if (bits == 0) {
            return true;
        if (!BitVecTryFromInteger(INT_BITS(out), value, bits, alloc)) {
            IntDeinit(out);
            *out = IntInit(alloc);
            return false;
        }
    
    static SignedInt sint_init(Allocator *alloc) {
        SignedInt value = {.negative = false, .magnitude = IntInit(alloc)};
        return value;
    }
        Int lhs;
        Int rhs;
        Int result = IntInit(IntAllocator(value));
    
        if (!int_try_clone_value(&lhs, value)) {
        Int lhs;
        Int rhs;
        Int result = IntInit(IntAllocator(value));
    
        if (!int_try_clone_value(&lhs, value)) {
    
        ValidateInt(out);
        result = IntInit(IntAllocator(out));
    
        if (!int_validate_radix(radix)) {
    
        ValidateInt(value);
        *out = IntInit(IntAllocator(value));
        if (!BitVecTryClone(INT_BITS(out), INT_BITS(value))) {
            return false;
    
        ValidateInt(value);
        clone = IntInit(IntAllocator(value));
        (void)int_try_clone_value(&clone, value);
        return clone;
    
    Int int_from_u64(u64 value, Allocator *alloc) {
        Int result = IntInit(alloc);
    
        (void)int_try_from_u64(&result, value, alloc);
        }
    
        Int result = IntInit(alloc);
    
        if (len == 0) {
        }
    
        Int result = IntInit(alloc);
    
        for (u64 i = 0; i < len; i++) {
            if (!IntShiftLeft(&result, 8) || !int_add_u64_in_place(&result, bytes[i])) {
                IntDeinit(&result);
                return IntInit(alloc);
            }
        }
    
    Int int_from_str_zstr(Zstr decimal, Allocator *alloc) {
        Int out = IntInit(alloc);
    
        (void)int_try_from_str_zstr(&out, decimal);
    
    Int int_from_str_str(const Str *decimal, Allocator *alloc) {
        Int out = IntInit(alloc);
    
        (void)int_try_from_str_str(&out, decimal);
    
    Int int_from_str_radix_zstr(Zstr digits, u8 radix, Allocator *alloc) {
        Int out = IntInit(alloc);
    
        (void)int_try_from_str_radix_zstr(&out, digits, radix);
    
    Int int_from_str_radix_str(const Str *digits, u8 radix, Allocator *alloc) {
        Int out = IntInit(alloc);
    
        (void)int_try_from_str_radix_str(&out, digits, radix);
    
        while (!IntIsZero(&current)) {
            Int quotient = IntInit(alloc);
            u64 digit    = 0;
    
    Int int_from_binary_zstr(Zstr binary, Allocator *alloc) {
        Int out = IntInit(alloc);
    
        (void)int_try_from_binary_zstr(&out, binary);
    
    Int int_from_binary_str(const Str *binary, Allocator *alloc) {
        Int out = IntInit(alloc);
    
        (void)int_try_from_binary_str(&out, binary);
    
    Int int_from_oct_str_zstr(Zstr octal, Allocator *alloc) {
        Int out = IntInit(alloc);
    
        (void)int_try_from_oct_str_zstr(&out, octal);
    
    Int int_from_oct_str_str(const Str *octal, Allocator *alloc) {
        Int out = IntInit(alloc);
    
        (void)int_try_from_oct_str_str(&out, octal);
    
    Int int_from_hex_str_zstr(Zstr hex, Allocator *alloc) {
        Int out = IntInit(alloc);
    
        (void)int_try_from_hex_str_zstr(&out, hex);
    
    Int int_from_hex_str_str(const Str *hex, Allocator *alloc) {
        Int out = IntInit(alloc);
    
        (void)int_try_from_hex_str_str(&out, hex);
    
        u64 b_bits = IntBitLength(b);
        Int acc    = IntInit(IntAllocator(result));
    
        if (IntIsZero(a) || IntIsZero(b)) {
    
            Int partial;
            Int next = IntInit(IntAllocator(result));
    
            if (!int_try_clone_value(&partial, a)) {
        while (exponent > 0) {
            if (exponent & 1u) {
                Int next = IntInit(IntAllocator(result));
    
                if (!int_mul(&next, &acc, &current)) {
            exponent >>= 1u;
            if (exponent > 0) {
                Int next = IntInit(IntAllocator(result));
    
                if (!IntSquare(&next, &current)) {
        }
    
        Int  normalized_dividend = IntInit(IntAllocator(quotient));
        Int  normalized_divisor  = IntInit(IntAllocator(quotient));
        Int  q                   = IntInit(IntAllocator(quotient));
    
        Int  normalized_dividend = IntInit(IntAllocator(quotient));
        Int  normalized_divisor  = IntInit(IntAllocator(quotient));
        Int  q                   = IntInit(IntAllocator(quotient));
        Int  r                   = IntInit(IntAllocator(remainder));
        Int  normalized_dividend = IntInit(IntAllocator(quotient));
        Int  normalized_divisor  = IntInit(IntAllocator(quotient));
        Int  q                   = IntInit(IntAllocator(quotient));
        Int  r                   = IntInit(IntAllocator(remainder));
        bool ok                  = false;
        Int  normalized_divisor  = IntInit(IntAllocator(quotient));
        Int  q                   = IntInit(IntAllocator(quotient));
        Int  r                   = IntInit(IntAllocator(remainder));
        bool ok                  = false;
            for (u64 shift = dividend_bits - divisor_bits + 1; shift > 0; shift--) {
                u64 bit     = shift - 1;
                Int shifted = IntInit(IntAllocator(quotient));
    
                if (!int_try_clone_value(&shifted, &normalized_divisor) || !IntShiftLeft(&shifted, bit)) {
    
                if (IntGE(&r, &shifted)) {
                    Int next = IntInit(IntAllocator(quotient));
    
                    if (!int_sub(&next, &r, &shifted)) {
        } else {
            IntDeinit(&q);
            q = IntInit(IntAllocator(quotient));
        }
    
    bool int_div(Int *result, const Int *dividend, const Int *divisor) {
        Int quotient  = IntInit(IntAllocator(result));
        Int remainder = IntInit(IntAllocator(result));
    bool int_div(Int *result, const Int *dividend, const Int *divisor) {
        Int quotient  = IntInit(IntAllocator(result));
        Int remainder = IntInit(IntAllocator(result));
    
        if (!int_div_mod(&quotient, &remainder, dividend, divisor)) {
        }
    
        Int quotient  = IntInit(IntAllocator(result));
        Int remainder = IntInit(IntAllocator(result));
    
        Int quotient  = IntInit(IntAllocator(result));
        Int remainder = IntInit(IntAllocator(result));
    
        if (!int_div_mod(&quotient, &remainder, dividend, divisor)) {
    
    bool int_div_u64(Int *result, const Int *dividend, u64 divisor) {
        Int divisor_value = IntInit(IntAllocator(dividend));
    
        if (!int_try_from_u64(&divisor_value, divisor, IntAllocator(dividend))) {
    
    bool int_div_i64(Int *result, const Int *dividend, i64 divisor) {
        Int divisor_value = IntInit(IntAllocator(dividend));
    
        if (!int_try_from_i64_with_allocator(&divisor_value, divisor, IntAllocator(dividend))) {
    
    bool int_div_exact_u64(Int *result, const Int *dividend, u64 divisor) {
        Int divisor_value = IntInit(IntAllocator(dividend));
    
        if (!int_try_from_u64(&divisor_value, divisor, IntAllocator(dividend))) {
    
    bool int_div_exact_i64(Int *result, const Int *dividend, i64 divisor) {
        Int divisor_value = IntInit(IntAllocator(dividend));
    
        if (!int_try_from_i64_with_allocator(&divisor_value, divisor, IntAllocator(dividend))) {
    
    bool int_div_mod_u64(Int *quotient, Int *remainder, const Int *dividend, u64 divisor) {
        Int divisor_value = IntInit(IntAllocator(dividend));
    
        if (!int_try_from_u64(&divisor_value, divisor, IntAllocator(dividend))) {
    
    bool int_div_mod_i64(Int *quotient, Int *remainder, const Int *dividend, i64 divisor) {
        Int divisor_value = IntInit(IntAllocator(dividend));
    
        if (!int_try_from_i64_with_allocator(&divisor_value, divisor, IntAllocator(dividend))) {
        }
    
        Int divisor_value = IntInit(IntAllocator(dividend));
        Int remainder     = IntInit(IntAllocator(quotient));
        u64 rem           = 0;
    
        Int divisor_value = IntInit(IntAllocator(dividend));
        Int remainder     = IntInit(IntAllocator(quotient));
        u64 rem           = 0;
    
    bool int_mod(Int *result, const Int *dividend, const Int *divisor) {
        Int quotient  = IntInit(IntAllocator(result));
        Int remainder = IntInit(IntAllocator(result));
    bool int_mod(Int *result, const Int *dividend, const Int *divisor) {
        Int quotient  = IntInit(IntAllocator(result));
        Int remainder = IntInit(IntAllocator(result));
    
        if (!int_div_mod(&quotient, &remainder, dividend, divisor)) {
    
    bool int_mod_u64_into(Int *result, const Int *dividend, u64 divisor) {
        Int quotient = IntInit(IntAllocator(result));
    
        bool ok = int_div_mod_u64(&quotient, result, dividend, divisor);
    
    bool int_mod_i64_into(Int *result, const Int *dividend, i64 divisor) {
        Int quotient = IntInit(IntAllocator(result));
    
        bool ok = int_div_mod_i64(&quotient, result, dividend, divisor);
        }
    
        Int quotient = IntInit(IntAllocator(value));
        u64 rem      = int_div_u64_rem(&quotient, value, modulus);
        ValidateInt(b);
    
        Int x = IntInit(IntAllocator(a));
        Int y = IntInit(IntAllocator(b));
    
        Int x = IntInit(IntAllocator(a));
        Int y = IntInit(IntAllocator(b));
    
        if (!int_try_clone_value(&x, a) || !int_try_clone_value(&y, b)) {
    
        while (!IntIsZero(&y)) {
            Int r = IntInit(IntAllocator(result));
    
            if (!int_mod(&r, &x, &y)) {
    
        if (IntIsZero(a) || IntIsZero(b)) {
            Int zero = IntInit(IntAllocator(result));
            int_replace(result, &zero);
            return true;
        }
    
        Int gcd      = IntInit(IntAllocator(result));
        Int quotient = IntInit(IntAllocator(result));
        Int lcm      = IntInit(IntAllocator(result));
    
        Int gcd      = IntInit(IntAllocator(result));
        Int quotient = IntInit(IntAllocator(result));
        Int lcm      = IntInit(IntAllocator(result));
        Int gcd      = IntInit(IntAllocator(result));
        Int quotient = IntInit(IntAllocator(result));
        Int lcm      = IntInit(IntAllocator(result));
    
        if (!IntGCD(&gcd, a, b) || !int_div(&quotient, a, &gcd) || !int_mul(&lcm, &quotient, b)) {
    
        if (IntIsZero(value)) {
            Int zero_root = IntInit(IntAllocator(root));
            Int zero_rem  = IntInit(IntAllocator(remainder));
        if (IntIsZero(value)) {
            Int zero_root = IntInit(IntAllocator(root));
            Int zero_rem  = IntInit(IntAllocator(remainder));
    
            int_replace(root, &zero_root);
        }
        if (degree == 1) {
            Int exact_root = IntInit(IntAllocator(root));
            Int zero_rem   = IntInit(IntAllocator(remainder));
        if (degree == 1) {
            Int exact_root = IntInit(IntAllocator(root));
            Int zero_rem   = IntInit(IntAllocator(remainder));
    
            if (!IntTryClone(&exact_root, value)) {
        u64 bits       = IntBitLength(value);
        u64 high_shift = bits / degree;
        Int low        = IntInit(IntAllocator(root));
        Int high       = IntInit(IntAllocator(root));
        Int best       = IntInit(IntAllocator(root));
        u64 high_shift = bits / degree;
        Int low        = IntInit(IntAllocator(root));
        Int high       = IntInit(IntAllocator(root));
        Int best       = IntInit(IntAllocator(root));
        Int one        = IntInit(IntAllocator(root));
        Int low        = IntInit(IntAllocator(root));
        Int high       = IntInit(IntAllocator(root));
        Int best       = IntInit(IntAllocator(root));
        Int one        = IntInit(IntAllocator(root));
        Int high       = IntInit(IntAllocator(root));
        Int best       = IntInit(IntAllocator(root));
        Int one        = IntInit(IntAllocator(root));
    
        if ((bits % degree) != 0) {
    
        while (IntLE(&low, &high)) {
            Int sum     = IntInit(IntAllocator(root));
            Int mid     = IntInit(IntAllocator(root));
            Int mid_pow = IntInit(IntAllocator(root));
        while (IntLE(&low, &high)) {
            Int sum     = IntInit(IntAllocator(root));
            Int mid     = IntInit(IntAllocator(root));
            Int mid_pow = IntInit(IntAllocator(root));
            int cmp     = 0;
            Int sum     = IntInit(IntAllocator(root));
            Int mid     = IntInit(IntAllocator(root));
            Int mid_pow = IntInit(IntAllocator(root));
            int cmp     = 0;
    
            if (cmp <= 0) {
                Int next = IntInit(IntAllocator(root));
    
                IntDeinit(&best);
                low = next;
            } else {
                Int next = IntInit(IntAllocator(root));
    
                if (IntEQ(&mid, &one) || IntIsZero(&mid)) {
                if (IntEQ(&mid, &one) || IntIsZero(&mid)) {
                    IntDeinit(&high);
                    high = IntInit(IntAllocator(root));
                } else {
                    if (!int_sub(&next, &mid, &one)) {
    
        {
            Int power = IntInit(IntAllocator(root));
            Int rem   = IntInit(IntAllocator(remainder));
        {
            Int power = IntInit(IntAllocator(root));
            Int rem   = IntInit(IntAllocator(remainder));
    
            if (!int_pow_u64(&power, &best, degree) || !int_sub(&rem, value, &power)) {
    
    bool IntRoot(Int *result, const Int *value, u64 degree) {
        Int root      = IntInit(IntAllocator(result));
        Int remainder = IntInit(IntAllocator(result));
    bool IntRoot(Int *result, const Int *value, u64 degree) {
        Int root      = IntInit(IntAllocator(result));
        Int remainder = IntInit(IntAllocator(result));
    
        if (!IntRootRem(&root, &remainder, value, degree)) {
        ValidateInt(value);
    
        Int  root      = IntInit(IntAllocator(value));
        Int  remainder = IntInit(IntAllocator(value));
        bool result    = false;
    
        Int  root      = IntInit(IntAllocator(value));
        Int  remainder = IntInit(IntAllocator(value));
        bool result    = false;
    
        for (u64 degree = 2; degree <= max_degree; degree++) {
            Int  root      = IntInit(IntAllocator(value));
            Int  remainder = IntInit(IntAllocator(value));
            bool exact     = false;
        for (u64 degree = 2; degree <= max_degree; degree++) {
            Int  root      = IntInit(IntAllocator(value));
            Int  remainder = IntInit(IntAllocator(value));
            bool exact     = false;
        }
    
        Int aa     = IntInit(IntAllocator(a));
        Int nn     = IntInit(IntAllocator(n));
        int result = 1;
    
        Int aa     = IntInit(IntAllocator(a));
        Int nn     = IntInit(IntAllocator(n));
        int result = 1;
        }
    
        Int ar  = IntInit(IntAllocator(result));
        Int br  = IntInit(IntAllocator(result));
        Int sum = IntInit(IntAllocator(result));
    
        Int ar  = IntInit(IntAllocator(result));
        Int br  = IntInit(IntAllocator(result));
        Int sum = IntInit(IntAllocator(result));
        Int ar  = IntInit(IntAllocator(result));
        Int br  = IntInit(IntAllocator(result));
        Int sum = IntInit(IntAllocator(result));
    
        if (!int_mod(&ar, a, modulus) || !int_mod(&br, b, modulus) || !int_add(&sum, &ar, &br) ||
        }
    
        Int ar = IntInit(IntAllocator(result));
        Int br = IntInit(IntAllocator(result));
    
        Int ar = IntInit(IntAllocator(result));
        Int br = IntInit(IntAllocator(result));
    
        if (!int_mod(&ar, a, modulus) || !int_mod(&br, b, modulus)) {
            }
        } else {
            Int diff = IntInit(IntAllocator(result));
    
            if (!int_sub(&diff, &br, &ar)) {
            }
            if (IntIsZero(&diff)) {
                Int zero = IntInit(IntAllocator(result));
                int_replace(result, &zero);
            } else {
        }
    
        Int ar   = IntInit(IntAllocator(result));
        Int br   = IntInit(IntAllocator(result));
        Int prod = IntInit(IntAllocator(result));
    
        Int ar   = IntInit(IntAllocator(result));
        Int br   = IntInit(IntAllocator(result));
        Int prod = IntInit(IntAllocator(result));
        Int ar   = IntInit(IntAllocator(result));
        Int br   = IntInit(IntAllocator(result));
        Int prod = IntInit(IntAllocator(result));
    
        if (!int_mod(&ar, a, modulus) || !int_mod(&br, b, modulus) || !int_mul(&prod, &ar, &br) ||
        }
    
        Int  inverse = IntInit(IntAllocator(result));
        Int  value   = IntInit(IntAllocator(result));
        bool ok      = false;
    
        Int  inverse = IntInit(IntAllocator(result));
        Int  value   = IntInit(IntAllocator(result));
        bool ok      = false;
        }
    
        Int acc      = IntInit(IntAllocator(result));
        Int base_mod = IntInit(IntAllocator(result));
    
        Int acc      = IntInit(IntAllocator(result));
        Int base_mod = IntInit(IntAllocator(result));
    
        if (!int_try_from_u64(&acc, 1, IntAllocator(result))) {
        while (exponent > 0) {
            if (exponent & 1u) {
                Int next = IntInit(IntAllocator(result));
    
                if (!IntModMul(&next, &acc, &base_mod, modulus)) {
            exponent >>= 1u;
            if (exponent > 0) {
                Int next = IntInit(IntAllocator(result));
    
                if (!IntModMul(&next, &base_mod, &base_mod, modulus)) {
        }
    
        Int acc      = IntInit(IntAllocator(result));
        Int base_mod = IntInit(IntAllocator(result));
        Int exp      = IntInit(IntAllocator(exponent));
    
        Int acc      = IntInit(IntAllocator(result));
        Int base_mod = IntInit(IntAllocator(result));
        Int exp      = IntInit(IntAllocator(exponent));
        Int acc      = IntInit(IntAllocator(result));
        Int base_mod = IntInit(IntAllocator(result));
        Int exp      = IntInit(IntAllocator(exponent));
    
        if (!int_try_from_u64(&acc, 1, IntAllocator(result)) || !IntTryClone(&exp, exponent) ||
        while (!IntIsZero(&exp)) {
            if (int_is_odd(&exp)) {
                Int next = IntInit(IntAllocator(result));
    
                if (!IntModMul(&next, &acc, &base_mod, modulus)) {
            }
            if (!IntIsZero(&exp)) {
                Int next = IntInit(IntAllocator(result));
    
                if (!IntModMul(&next, &base_mod, &base_mod, modulus)) {
        }
    
        Int       reduced = IntInit(IntAllocator(result));
        SignedInt t       = sint_init(IntAllocator(result));
        SignedInt new_t   = sint_from_u64(1, IntAllocator(result));
        SignedInt t       = sint_init(IntAllocator(result));
        SignedInt new_t   = sint_from_u64(1, IntAllocator(result));
        Int       r       = IntInit(IntAllocator(modulus));
        Int       new_r   = IntInit(IntAllocator(result));
        Int       one     = int_from_u64(1, IntAllocator(result));
        SignedInt new_t   = sint_from_u64(1, IntAllocator(result));
        Int       r       = IntInit(IntAllocator(modulus));
        Int       new_r   = IntInit(IntAllocator(result));
        Int       one     = int_from_u64(1, IntAllocator(result));
        bool      ok      = false;
    
        while (!IntIsZero(&new_r)) {
            Int       q       = IntInit(IntAllocator(result));
            Int       rem     = IntInit(IntAllocator(result));
            SignedInt q_new_t = sint_init(IntAllocator(result));
        while (!IntIsZero(&new_r)) {
            Int       q       = IntInit(IntAllocator(result));
            Int       rem     = IntInit(IntAllocator(result));
            SignedInt q_new_t = sint_init(IntAllocator(result));
            SignedInt next_t  = sint_init(IntAllocator(result));
            SignedInt q_new_t = sint_init(IntAllocator(result));
            SignedInt next_t  = sint_init(IntAllocator(result));
            Int       next_r  = IntInit(IntAllocator(result));
    
            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(IntAllocator(result));
            Int mag_mod  = IntInit(IntAllocator(result));
        if (IntEQ(&r, &one)) {
            Int positive = IntInit(IntAllocator(result));
            Int mag_mod  = IntInit(IntAllocator(result));
    
            if (!int_mod(&mag_mod, &t.magnitude, modulus)) {
        }
    
        Int  a  = IntInit(IntAllocator(result));
        bool ok = false;
    
        if (IntIsZero(&a)) {
            Int zero = IntInit(IntAllocator(result));
            int_replace(result, &zero);
            IntDeinit(&a);
        }
        if (int_mod_u64(modulus, 4) == 3) {
            Int exponent = IntInit(IntAllocator(modulus));
            Int root     = IntInit(IntAllocator(result));
        if (int_mod_u64(modulus, 4) == 3) {
            Int exponent = IntInit(IntAllocator(modulus));
            Int root     = IntInit(IntAllocator(result));
    
            if (!IntTryClone(&exponent, modulus) || !int_add_u64(&exponent, &exponent, 1) || !IntShiftRight(&exponent, 2) ||
    
        {
            Int q        = IntInit(IntAllocator(modulus));
            Int z        = IntInit(IntAllocator(modulus));
            Int c        = IntInit(IntAllocator(result));
        {
            Int q        = IntInit(IntAllocator(modulus));
            Int z        = IntInit(IntAllocator(modulus));
            Int c        = IntInit(IntAllocator(result));
            Int t        = IntInit(IntAllocator(result));
            Int q        = IntInit(IntAllocator(modulus));
            Int z        = IntInit(IntAllocator(modulus));
            Int c        = IntInit(IntAllocator(result));
            Int t        = IntInit(IntAllocator(result));
            Int r        = IntInit(IntAllocator(result));
            Int z        = IntInit(IntAllocator(modulus));
            Int c        = IntInit(IntAllocator(result));
            Int t        = IntInit(IntAllocator(result));
            Int r        = IntInit(IntAllocator(result));
            Int exponent = IntInit(IntAllocator(result));
            Int c        = IntInit(IntAllocator(result));
            Int t        = IntInit(IntAllocator(result));
            Int r        = IntInit(IntAllocator(result));
            Int exponent = IntInit(IntAllocator(result));
            u64 m        = 0;
            Int t        = IntInit(IntAllocator(result));
            Int r        = IntInit(IntAllocator(result));
            Int exponent = IntInit(IntAllocator(result));
            u64 m        = 0;
    
            while (int_compare_u64(&t, 1) != 0) {
                Int t_power = IntInit(IntAllocator(&t));
                u64 i       = 0;
    
                for (i = 1; i < m; i++) {
                    Int next = IntInit(IntAllocator(result));
    
                    if (!IntSquareMod(&next, &t_power, modulus)) {
    
                {
                    Int b    = IntInit(IntAllocator(&c));
                    Int b_sq = IntInit(IntAllocator(result));
                    Int next = IntInit(IntAllocator(result));
                {
                    Int b    = IntInit(IntAllocator(&c));
                    Int b_sq = IntInit(IntAllocator(result));
                    Int next = IntInit(IntAllocator(result));
                    Int b    = IntInit(IntAllocator(&c));
                    Int b_sq = IntInit(IntAllocator(result));
                    Int next = IntInit(IntAllocator(result));
    
                    if (!IntTryClone(&b, &c)) {
    
                    for (u64 j = 0; j + i + 1 < m; j++) {
                        Int square = IntInit(IntAllocator(result));
    
                        if (!IntSquareMod(&square, &b, modulus)) {
                        return false;
                    }
                    next = IntInit(IntAllocator(result));
                    if (!IntModMul(&next, &t, &b_sq, modulus)) {
                        IntDeinit(&b);
    
        {
            Int  d           = IntInit(IntAllocator(value));
            Int  n_minus_one = IntInit(IntAllocator(value));
            u64  s           = 0;
        {
            Int  d           = IntInit(IntAllocator(value));
            Int  n_minus_one = IntInit(IntAllocator(value));
            u64  s           = 0;
            bool probable    = true;
    
            for (u64 i = 0; i < (u64)(sizeof(bases) / sizeof(bases[0])); i++) {
                Int base = IntInit(IntAllocator(value));
                Int x    = IntInit(IntAllocator(value));
            for (u64 i = 0; i < (u64)(sizeof(bases) / sizeof(bases[0])); i++) {
                Int base = IntInit(IntAllocator(value));
                Int x    = IntInit(IntAllocator(value));
    
                if (!int_try_from_u64(&base, bases[i], IntAllocator(value))) {
    
                    for (u64 r = 1; r < s; r++) {
                        Int next = IntInit(IntAllocator(value));
    
                        if (!IntSquareMod(&next, &x, value)) {
    
        if (int_compare_u64(value, 1) <= 0) {
            Int two = IntInit(IntAllocator(result));
    
            if (!int_try_from_u64(&two, 2, IntAllocator(result))) {
        }
    
        Int candidate = IntInit(IntAllocator(result));
    
        if (!IntTryClone(&candidate, value)) {
        }
        if (int_compare_u64(&candidate, 2) <= 0) {
            Int two = IntInit(IntAllocator(result));
    
            if (!int_try_from_u64(&two, 2, IntAllocator(result))) {
        } else if (binexp < 0) {
            u64 n    = (u64)(-(i64)binexp);
            Int five = IntInit(alloc);
            Int pow5 = IntInit(alloc);
            Int sig  = IntInit(alloc);
            u64 n    = (u64)(-(i64)binexp);
            Int five = IntInit(alloc);
            Int pow5 = IntInit(alloc);
            Int sig  = IntInit(alloc);
            if (!int_try_from_u64(&five, 5u, alloc) || !IntPow(&pow5, &five, n) ||
            Int five = IntInit(alloc);
            Int pow5 = IntInit(alloc);
            Int sig  = IntInit(alloc);
            if (!int_try_from_u64(&five, 5u, alloc) || !IntPow(&pow5, &five, n) ||
                !int_mul(&sig, &out->significand, &pow5)) {
        {
            u64 places = (u64)(value->exponent - target_exponent);
            Int factor = IntInit(FloatAllocator(value));
            Int scaled = IntInit(FloatAllocator(value));
            u64 places = (u64)(value->exponent - target_exponent);
            Int factor = IntInit(FloatAllocator(value));
            Int scaled = IntInit(FloatAllocator(value));
    
            if (!float_pow10(&factor, places, FloatAllocator(value)) || !int_mul(&scaled, &value->significand, &factor)) {
    
        while (int_mod_u64(&value->significand, 10) == 0) {
            Int quotient = IntInit(FloatAllocator(value));
    
            (void)int_div_u64_rem(&quotient, &value->significand, 10);
        ValidateFloat(value);
    
        Int temp = IntInit(IntAllocator(result));
    
        if (FloatIsNegative(value)) {
    
        if (value->exponent >= 0) {
            Int factor = IntInit(FloatAllocator(value));
    
            if (!IntTryClone(&temp, &value->significand) ||
        {
            u64  places = (u64)(-value->exponent);
            Int  factor = IntInit(FloatAllocator(value));
            bool ok     = false;
    bool float_div(Float *result, const Float *a, const Float *b, u64 precision) {
        Float temp   = FloatInit(FloatAllocator(result));
        Int   scale  = IntInit(FloatAllocator(result));
        Int   scaled = IntInit(FloatAllocator(result));
        Float temp   = FloatInit(FloatAllocator(result));
        Int   scale  = IntInit(FloatAllocator(result));
        Int   scaled = IntInit(FloatAllocator(result));
    
        ValidateFloat(result);
    
    bool test_int_init(void) {
        WriteFmt("Testing IntInit\n");
    
        DefaultAllocator alloc = DefaultAllocatorInit();
        DefaultAllocator alloc = DefaultAllocatorInit();
    
        Int value = IntInit(&alloc.base);
    
        bool result = IntIsZero(&value);
        alloc.base.retry_limit = 5;
    
        Int original = IntInit(&alloc);
    
        BitVecPush(&original.bits, true);
        Int a   = IntFrom(255, &alloc.base);
        Int b   = IntFrom(1, &alloc.base);
        Int sum = IntInit(&alloc.base);
    
        IntAdd(&sum, &a, &b);
    
        Int  parsed = IntFromBinary("10a1", ALLOCATOR_OF(&alloc));
        Int  value  = IntInit(ALLOCATOR_OF(&alloc));
        bool result = !IntTryFromBinary(&value, "10a1");
    
        Int  parsed = IntFromStr("12x3", ALLOCATOR_OF(&alloc));
        Int  value  = IntInit(ALLOCATOR_OF(&alloc));
        bool result = !IntTryFromStr(&value, "12x3");
    
        Int  parsed = IntFromHexStr("12g3", ALLOCATOR_OF(&alloc));
        Int  value  = IntInit(ALLOCATOR_OF(&alloc));
        bool result = !IntTryFromHexStr(&value, "12g3");
    
        Int  parsed = IntFromStrRadix("102", 2, ALLOCATOR_OF(&alloc));
        Int  value  = IntInit(ALLOCATOR_OF(&alloc));
        bool result = !IntTryFromStrRadix(&value, "102", 2);
    
        Int  parsed = IntFromStrRadix("10", 1, ALLOCATOR_OF(&alloc));
        Int  value  = IntInit(ALLOCATOR_OF(&alloc));
        bool result = !IntTryFromStrRadix(&value, "10", 1);
        DefaultAllocator alloc = DefaultAllocatorInit();
    
        Int value = IntInit(ALLOCATOR_OF(&alloc));
        IntTryFromBinary(&value, (Zstr)NULL);
        IntDeinit(&value);
        DefaultAllocator alloc = DefaultAllocatorInit();
    
        Int value = IntInit(ALLOCATOR_OF(&alloc));
        IntTryFromStr(&value, (Zstr)NULL);
        IntDeinit(&value);
        DefaultAllocator alloc = DefaultAllocatorInit();
    
        Int value = IntInit(ALLOCATOR_OF(&alloc));
        IntTryFromStrRadix(&value, (Zstr)NULL, 10);
        IntDeinit(&value);
        DefaultAllocator alloc = DefaultAllocatorInit();
    
        Int value = IntInit(ALLOCATOR_OF(&alloc));
        IntTryFromOctStr(&value, (Zstr)NULL);
        IntDeinit(&value);
        DefaultAllocator alloc = DefaultAllocatorInit();
    
        Int value = IntInit(ALLOCATOR_OF(&alloc));
        IntTryFromHexStr(&value, (Zstr)NULL);
        IntDeinit(&value);
        Int a       = IntFrom((u64)13u, &alloc.base);
        Int b       = IntFrom((u64)21u, &alloc.base);
        Int product = IntInit(&alloc.base);
    
        bool ok = IntMul(&product, &a, &b);
        DefaultAllocator alloc = DefaultAllocatorInit();
    
        Int  value  = IntInit(ALLOCATOR_OF(&alloc));
        bool result = !IntTryFromStrRadix(&value, "_", 10);
        DefaultAllocator alloc = DefaultAllocatorInit();
    
        Int  value  = IntInit(ALLOCATOR_OF(&alloc));
        bool ok     = IntTryFromStrRadix(&value, "7", 10);
        bool result = ok && (IntToU64(&value) == 7);
        DefaultAllocator alloc = DefaultAllocatorInit();
    
        Int valid   = IntInit(ALLOCATOR_OF(&alloc));
        Int invalid = IntInit(ALLOCATOR_OF(&alloc));
    
        Int valid   = IntInit(ALLOCATOR_OF(&alloc));
        Int invalid = IntInit(ALLOCATOR_OF(&alloc));
    
        bool ok_valid       = IntTryFromStrRadix(&valid, "5", 10);
    
        Str  text   = StrInitFromZstr("0b101", &alloc);
        Int  out    = IntInit(&alloc.base);
        bool ok     = int_try_from_binary_str(&out, &text);
        bool result = ok && (IntToU64(&out) == 5u);
    
        Str  text   = StrInitFromZstr("0B101", &alloc);
        Int  out    = IntInit(&alloc.base);
        bool ok     = int_try_from_binary_str(&out, &text);
        bool result = ok && (IntToU64(&out) == 5u);
    
        Str  text   = StrInitFromZstr("1101", &alloc);
        Int  out    = IntInit(&alloc.base);
        bool ok     = int_try_from_binary_str(&out, &text);
        bool result = ok && (IntToU64(&out) == 13u);
    
        Str  text   = StrInitFromZstr("0o17", &alloc);
        Int  out    = IntInit(&alloc.base);
        bool ok     = int_try_from_oct_str_str(&out, &text);
        bool result = ok && (IntToU64(&out) == 15u);
    
        Str  text   = StrInitFromZstr("0O17", &alloc);
        Int  out    = IntInit(&alloc.base);
        bool ok     = int_try_from_oct_str_str(&out, &text);
        bool result = ok && (IntToU64(&out) == 15u);
    
        Str  text   = StrInitFromZstr("17", &alloc);
        Int  out    = IntInit(&alloc.base);
        bool ok     = int_try_from_oct_str_str(&out, &text);
        bool result = ok && (IntToU64(&out) == 15u);
        DefaultAllocator alloc = DefaultAllocatorInit();
    
        Int  out    = IntInit(&alloc.base);
        bool parsed = IntTryFromStrRadix(&out, "AZ", 36);
        DefaultAllocator alloc = DefaultAllocatorInit();
    
        Int  out    = IntInit(&alloc.base);
        bool parsed = IntTryFromStrRadix(&out, "FF", 16);
    
        Str  text   = StrInitFromZstr("123", &alloc);
        Int  out    = IntInit(&alloc.base);
        bool parsed = IntTryFromStr(&out, &text);
    
        Str  text   = StrInitFromZstr("+5", &alloc);
        Int  out    = IntInit(&alloc.base);
        bool parsed = IntTryFromStr(&out, &text);
    
        Str  digits = StrInitFromZstr("123", ALLOCATOR_OF(&alloc));
        Int  value  = IntInit(ALLOCATOR_OF(&alloc));
        bool ok     = IntTryFromStrRadix(&value, &digits, 10);
    
        Str  digits = StrInitFromZstr("+5", ALLOCATOR_OF(&alloc));
        Int  value  = IntInit(ALLOCATOR_OF(&alloc));
        bool ok     = IntTryFromStrRadix(&value, &digits, 10);
        DefaultAllocator alloc = DefaultAllocatorInit();
    
        Int         out  = IntInit(&alloc.base);
        const char *text = "+5";
        DefaultAllocator alloc = DefaultAllocatorInit();
    
        Int         out  = IntInit(&alloc.base);
        const char *text = "42";
        DefaultAllocator alloc = DefaultAllocatorInit();
    
        Int  out = IntInit(&alloc.base);
        bool ok  = IntTryFromStrRadix(&out, "+5", (u8)10);
        DefaultAllocator alloc = DefaultAllocatorInit();
    
        Int  out = IntInit(&alloc.base);
        bool ok  = IntTryFromOctStr(&out, "17");
        DefaultAllocator alloc = DefaultAllocatorInit();
    
        Int  out = IntInit(&alloc.base);
        bool ok  = IntTryFromOctStr(&out, "017");
        DefaultAllocator alloc = DefaultAllocatorInit();
    
        Int  out    = IntInit(&alloc.base);
        bool parsed = IntTryFromBinary(&out, "0c1");
        DefaultAllocator alloc = DefaultAllocatorInit();
    
        Int  out    = IntInit(&alloc.base);
        bool parsed = IntTryFromBinary(&out, "0b101");
    
        Str hex   = StrInitFromZstr("ff", &alloc.base);
        Int value = IntInit(&alloc.base);
    
        bool ok = int_try_from_hex_str_str(&value, &hex);
    
        Str hex   = StrInitFromZstr("12g3", &alloc.base);
        Int value = IntInit(&alloc.base);
    
        bool ok = int_try_from_hex_str_str(&value, &hex);
        Allocator       *alloc_base = ALLOCATOR_OF(&alloc);
    
        Int oct = IntInit(alloc_base);
    
        Zstr z = "78";
        DefaultAllocator alloc = DefaultAllocatorInit();
    
        Int  v = IntInit(ALLOCATOR_OF(&alloc));
        Zstr z = "9z";
        StrReadFmt(z, "{}", v);
        DefaultAllocator alloc = DefaultAllocatorInit();
    
        Int  v = IntInit(ALLOCATOR_OF(&alloc));
        Zstr z = "5";
        StrReadFmt(z, "{}", v);
        DefaultAllocator alloc = DefaultAllocatorInit();
    
        Int  v = IntInit(ALLOCATOR_OF(&alloc));
        Zstr z = "+8";
        StrReadFmt(z, "{}", v);
        DefaultAllocator alloc = DefaultAllocatorInit();
    
        Int  v = IntInit(ALLOCATOR_OF(&alloc));
        Zstr z = "ff";
        StrReadFmt(z, "{x}", v);
        DefaultAllocator alloc = DefaultAllocatorInit();
    
        Int  v = IntInit(ALLOCATOR_OF(&alloc));
        Zstr z = "101";
        StrReadFmt(z, "{b}", v);
        DefaultAllocator alloc = DefaultAllocatorInit();
    
        Int  v = IntInit(ALLOCATOR_OF(&alloc));
        Zstr z = "17";
        StrReadFmt(z, "{o}", v);
        DefaultAllocator alloc = DefaultAllocatorInit();
    
        Int  v = IntInit(ALLOCATOR_OF(&alloc));
        Zstr z = "   42";
        StrReadFmt(z, "{}", v);
    
        Float v = FloatFromStr("1e3", &dbg.base); // exponent 3 > 0 -> pow10
        Int   r = IntInit(&dbg.base);
    
        bool ok = FloatToInt(&r, &v);             // drives float_pow10 + success path
    static bool test_read_int_plain(void) {
        DebugAllocator dbg = DebugAllocatorInit();
        Int            v   = IntInit(&dbg.base);
        Zstr           z   = "12345";
        StrReadFmt(z, "{}", v);
    static bool test_read_int_leading_plus(void) {
        DefaultAllocator alloc = DefaultAllocatorInit();
        Int              v     = IntInit(&alloc.base);
        Zstr             z     = "+99";
        StrReadFmt(z, "{}", v);
    static bool test_read_int_hex_plain(void) {
        DefaultAllocator alloc = DefaultAllocatorInit();
        Int              v     = IntInit(&alloc.base);
        Zstr             z     = "ff";
        StrReadFmt(z, "{x}", v);
        DefaultAllocator alloc = DefaultAllocatorInit();
    
        Int zero = IntInit(&alloc.base);
    
        int  cmp    = int_compare_i64(&zero, (i64)0);
        Int x = IntFrom(123456u, a);
        Int y = IntFrom(7891011u, a);
        Int r = IntInit(a);
    
        bool ok = IntMul(&r, &x, &y);
        u64  rem = 0;
        {
            Int q = IntInit(a);
            rem   = int_div_u64_rem(&q, &v, 1000u);
            IntDeinit(&q);
    
        Float value        = FloatFromStr("1234500e-2", ALLOCATOR_OF(&alloc));
        Int   result_value = IntInit(ALLOCATOR_OF(&alloc));
        Str   text         = StrInit(ALLOCATOR_OF(&alloc));
    
        Float neg = FloatFromStr("-5", &alloc.base);
        Int   out = IntInit(&alloc.base);
    
        bool ok = (FloatToInt(&out, &neg) == false);
            .exponent    = -1,
        };
        Int result = IntInit(&alloc.base);
    
        bool ok = FloatToInt(&result, &value);
    
        Float value  = FloatFromStr("120", &alloc.base);
        Int   result = IntInit(&alloc.base);
    
        bool ok = FloatToInt(&result, &value);
    
        Float value  = FloatFromStr("-7", &alloc.base);
        Int   result = IntInit(&alloc.base);
    
        bool ok    = FloatToInt(&result, &value);
        DefaultAllocator alloc = DefaultAllocatorInit();
    
        Int zero     = IntInit(&alloc.base);
        Int non_zero = IntFrom(1, &alloc.base);
    
        Int value = IntFromBinary("1010000", &alloc.base);
        Int zero  = IntInit(&alloc.base);
    
        bool result = IntTrailingZeroCount(&value) == 4;
        Int power = IntFrom(1, &alloc.base);
        Int other = IntFrom(24, &alloc.base);
        Int zero  = IntInit(&alloc.base);
    
        IntShiftLeft(&power, 20);
        DefaultAllocator alloc = DefaultAllocatorInit();
    
        Int  value = IntInit(&alloc.base);
        bool error = false;
        Int base         = IntFrom(7, &alloc.base);
        Int mod          = IntFrom(13, &alloc.base);
        Int result_value = IntInit(&alloc.base);
    
        bool ok = IntPowMod(&result_value, &base, 20u, &mod);
        Int a            = IntFrom(255, &alloc.base);
        Int b            = IntFrom(1, &alloc.base);
        Int result_value = IntInit(&alloc.base);
        Str text         = StrInit(&alloc.base);
        Int base         = IntFrom(40, &alloc.base);
        Int rhs          = IntFrom(2, &alloc.base);
        Int result_value = IntInit(&alloc.base);
        Int huge         = IntFromStr("123456789012345678901234567890", &alloc.base);
        Str text         = StrInit(&alloc.base);
        Int a            = IntFrom(256, &alloc.base);
        Int b            = IntFrom(1, &alloc.base);
        Int result_value = IntInit(&alloc.base);
    
        bool result = IntSub(&result_value, &a, &b);
        Int base         = IntFrom(40, &alloc.base);
        Int rhs          = IntFrom(2, &alloc.base);
        Int result_value = IntInit(&alloc.base);
        Int preserved    = IntFrom(99, &alloc.base);
        Int huge         = IntFromStr("12345678901234567890", &alloc.base);
        Int a            = IntFrom(21, &alloc.base);
        Int b            = IntFrom(6, &alloc.base);
        Int result_value = IntInit(&alloc.base);
    
        IntMul(&result_value, &a, &b);
    
        Int value        = IntFromStr("12345678901234567890", &alloc.base);
        Int result_value = IntInit(&alloc.base);
        Str text         = StrInit(&alloc.base);
        Int a            = IntFrom(0, &alloc.base);
        Int b            = IntFrom(12345, &alloc.base);
        Int result_value = IntInit(&alloc.base);
    
        IntMul(&result_value, &a, &b);
    
        Int value        = IntFrom(12345, &alloc.base);
        Int result_value = IntInit(&alloc.base);
    
        IntSquare(&result_value, &value);
        Int base         = IntFrom(7, &alloc.base);
        Int exponent     = IntFrom(20, &alloc.base);
        Int result_value = IntInit(&alloc.base);
        Str text         = StrInit(&alloc.base);
    
        Int dividend  = IntFromStr("12345678901234567890", &alloc.base);
        Int quotient  = IntInit(&alloc.base);
        Int remainder = IntInit(&alloc.base);
        Str qtext     = StrInit(&alloc.base);
        Int dividend  = IntFromStr("12345678901234567890", &alloc.base);
        Int quotient  = IntInit(&alloc.base);
        Int remainder = IntInit(&alloc.base);
        Str qtext     = StrInit(&alloc.base);
    
        Int dividend     = IntFrom(126, &alloc.base);
        Int result_value = IntInit(&alloc.base);
    
        IntDiv(&result_value, &dividend, 10u);
    
        Int dividend     = IntFromStr("12345678901234567890", &alloc.base);
        Int result_value = IntInit(&alloc.base);
        Str text         = StrInit(&alloc.base);
    
        Int dividend  = IntFromStr("12345678901234567890", &alloc.base);
        Int quotient  = IntInit(&alloc.base);
        Int remainder = IntInit(&alloc.base);
        Str text      = StrInit(&alloc.base);
        Int dividend  = IntFromStr("12345678901234567890", &alloc.base);
        Int quotient  = IntInit(&alloc.base);
        Int remainder = IntInit(&alloc.base);
        Str text      = StrInit(&alloc.base);
    
        Int dividend     = IntFrom(126, &alloc.base);
        Int result_value = IntInit(&alloc.base);
    
        IntMod(&result_value, &dividend, 10u);
    
        Int value     = IntFromStr("12345678901234567890", &alloc.base);
        Int remainder = IntInit(&alloc.base);
    
        IntMod(&remainder, &value, 97u);
        Int a            = IntFrom(48, &alloc.base);
        Int b            = IntFrom(18, &alloc.base);
        Int result_value = IntInit(&alloc.base);
    
        IntGCD(&result_value, &a, &b);
        Int a            = IntFrom(21, &alloc.base);
        Int b            = IntFrom(6, &alloc.base);
        Int result_value = IntInit(&alloc.base);
    
        IntLCM(&result_value, &a, &b);
    
        Int value        = IntFrom(4096, &alloc.base);
        Int result_value = IntInit(&alloc.base);
    
        IntRoot(&result_value, &value, 4);
    
        Int value     = IntFrom(200, &alloc.base);
        Int root      = IntInit(&alloc.base);
        Int remainder = IntInit(&alloc.base);
        Int value     = IntFrom(200, &alloc.base);
        Int root      = IntInit(&alloc.base);
        Int remainder = IntInit(&alloc.base);
    
        IntRootRem(&root, &remainder, &value, 3);
    
        Int value        = IntFrom(200, &alloc.base);
        Int result_value = IntInit(&alloc.base);
    
        IntSqrt(&result_value, &value);
    
        Int value     = IntFrom(200, &alloc.base);
        Int root      = IntInit(&alloc.base);
        Int remainder = IntInit(&alloc.base);
        Int value     = IntFrom(200, &alloc.base);
        Int root      = IntInit(&alloc.base);
        Int remainder = IntInit(&alloc.base);
    
        IntSqrtRem(&root, &remainder, &value);
        Int value        = IntFrom(12345, &alloc.base);
        Int mod          = IntFrom(97, &alloc.base);
        Int result_value = IntInit(&alloc.base);
    
        IntSquareMod(&result_value, &value, &mod);
        Int b            = IntFrom(250, &alloc.base);
        Int m            = IntFrom(13, &alloc.base);
        Int result_value = IntInit(&alloc.base);
    
        IntModAdd(&result_value, &a, &b, &m);
        Int b            = IntFrom(9, &alloc.base);
        Int m            = IntFrom(13, &alloc.base);
        Int result_value = IntInit(&alloc.base);
    
        IntModSub(&result_value, &a, &b, &m);
        Int b            = IntFrom(456, &alloc.base);
        Int m            = IntFrom(97, &alloc.base);
        Int result_value = IntInit(&alloc.base);
    
        IntModMul(&result_value, &a, &b, &m);
        Int b            = IntFrom(3, &alloc.base);
        Int m            = IntFrom(13, &alloc.base);
        Int result_value = IntInit(&alloc.base);
        Int check        = IntInit(&alloc.base);
        Int m            = IntFrom(13, &alloc.base);
        Int result_value = IntInit(&alloc.base);
        Int check        = IntInit(&alloc.base);
    
        bool result = IntModDiv(&result_value, &a, &b, &m);
        Int base         = IntFrom(7, &alloc.base);
        Int mod          = IntFrom(13, &alloc.base);
        Int result_value = IntInit(&alloc.base);
    
        IntPowMod(&result_value, &base, 20u, &mod);
        Int exp          = IntFrom(13, &alloc.base);
        Int mod          = IntFrom(497, &alloc.base);
        Int result_value = IntInit(&alloc.base);
    
        IntPowMod(&result_value, &base, &exp, &mod);
        Int value        = IntFrom(3, &alloc.base);
        Int mod          = IntFrom(11, &alloc.base);
        Int result_value = IntInit(&alloc.base);
        Int check        = IntInit(&alloc.base);
        Int mod          = IntFrom(11, &alloc.base);
        Int result_value = IntInit(&alloc.base);
        Int check        = IntInit(&alloc.base);
    
        bool result = IntModInv(&result_value, &value, &mod);
        Int value = IntFrom(10, &alloc.base);
        Int mod   = IntFrom(13, &alloc.base);
        Int root  = IntInit(&alloc.base);
        Int check = IntInit(&alloc.base);
        Int mod   = IntFrom(13, &alloc.base);
        Int root  = IntInit(&alloc.base);
        Int check = IntInit(&alloc.base);
    
        bool result = IntModSqrt(&root, &value, &mod);
    
        Int value = IntFromStr("1000000000", &alloc.base);
        Int next  = IntInit(&alloc.base);
        Str text  = StrInit(&alloc.base);
    
        Int dividend  = IntFrom(1, &alloc.base);
        Int divisor   = IntInit(&alloc.base);
        Int quotient  = IntFrom(99, &alloc.base);
        Int remainder = IntFrom(77, &alloc.base);
        Int a            = IntFrom(10, &alloc.base);
        Int b            = IntFrom(3, &alloc.base);
        Int m            = IntInit(&alloc.base);
        Int result_value = IntFrom(99, &alloc.base);
    
        Int base         = IntFrom(2, &alloc.base);
        Int mod          = IntInit(&alloc.base);
        Int result_value = IntInit(&alloc.base);
        Int base         = IntFrom(2, &alloc.base);
        Int mod          = IntInit(&alloc.base);
        Int result_value = IntInit(&alloc.base);
    
        IntPowMod(&result_value, &base, 8u, &mod);
        Int base         = IntFrom(2, &alloc.base);
        Int exp          = IntFrom(8, &alloc.base);
        Int mod          = IntInit(&alloc.base);
        Int result_value = IntFrom(99, &alloc.base);
        Int mod   = IntFrom(7, &alloc.base);
        Int root  = IntFrom(99, &alloc.base);
        Int check = IntInit(&alloc.base);
    
        bool result = IntModSqrt(&root, &value, &mod);
        Int mod   = IntFrom(17, &alloc.base);
        Int root  = IntFrom(99, &alloc.base);
        Int check = IntInit(&alloc.base);
    
        bool result = IntModSqrt(&root, &value, &mod);
        Int mod   = IntFrom(17, &alloc.base);
        Int root  = IntFrom(99, &alloc.base);
        Int check = IntInit(&alloc.base);
    
        bool result = IntModSqrt(&root, &value, &mod);
        Int mod   = IntFrom(97, &alloc.base);
        Int root  = IntFrom(99, &alloc.base);
        Int check = IntInit(&alloc.base);
    
        bool result = IntModSqrt(&root, &value, &mod);
        Int mod   = IntFrom(257, &alloc.base);
        Int root  = IntFrom(99, &alloc.base);
        Int check = IntInit(&alloc.base);
    
        bool result = IntModSqrt(&root, &value, &mod);
        Int mod   = IntFrom(13, &alloc.base);
        Int root  = IntFrom(99, &alloc.base);
        Int check = IntInit(&alloc.base);
    
        bool result = IntModSqrt(&root, &value, &mod);
    
        Int value = IntFrom(4, &alloc.base);
        Int mod   = IntInit(&alloc.base);
        Int root  = IntFrom(99, &alloc.base);
        Int mod   = IntFrom(7, &alloc.base);
        Int root  = IntFrom(99, &alloc.base);
        Int check = IntInit(&alloc.base);
    
        bool result = IntModSqrt(&root, &value, &mod);
        Int a       = IntFrom((u64)123456789u, &alloc.base);
        Int b       = IntFrom((u64)987654321u, &alloc.base);
        Int product = IntInit(&alloc.base);
    
        bool ok = IntMul(&product, &a, &b);
    
        Int a       = IntFrom((u64)999u, &alloc.base);
        Int zero    = IntInit(&alloc.base);
        Int product = IntInit(&alloc.base);
        Int a       = IntFrom((u64)999u, &alloc.base);
        Int zero    = IntInit(&alloc.base);
        Int product = IntInit(&alloc.base);
    
        bool ok = IntMul(&product, &a, &zero);
    
        Int base   = IntFrom(7, &alloc.base);
        Int result = IntInit(&alloc.base);
    
        // exponent 0 -> 1 (loop body never runs)
    
        Int b      = IntFrom(8, &alloc.base);
        Int result = IntInit(&alloc.base);
    
        IntGCD(&result, NULL, &b);
    
        Int a      = IntFrom(12, &alloc.base);
        Int result = IntInit(&alloc.base);
    
        IntGCD(&result, &a, NULL);
        Int a            = IntFrom(4, &alloc.base);
        Int b            = IntFrom(1, &alloc.base);
        Int result_value = IntInit(&alloc.base);
    
        bool ok = IntSub(&result_value, &a, &b);
        DefaultAllocator alloc = DefaultAllocatorInit();
    
        Int quotient = IntInit(&alloc.base);
    
        int_div_u64_rem(&quotient, NULL, 7);
        Int ones = IntFromBinary("1111111", &alloc.base); // 127
        Int one  = IntFrom(1u, &alloc.base);
        Int sum  = IntInit(&alloc.base);
    
        IntAdd(&sum, &ones, &one);
    
        Int value     = IntFrom(10000, &alloc.base);
        Int root      = IntInit(&alloc.base);
        Int remainder = IntInit(&alloc.base);
        Int value     = IntFrom(10000, &alloc.base);
        Int root      = IntInit(&alloc.base);
        Int remainder = IntInit(&alloc.base);
    
        bool ok     = IntRootRem(&root, &remainder, &value, 2);
    
        Int value     = IntFrom(1000, &alloc.base);
        Int root      = IntInit(&alloc.base);
        Int remainder = IntInit(&alloc.base);
        Int value     = IntFrom(1000, &alloc.base);
        Int root      = IntInit(&alloc.base);
        Int remainder = IntInit(&alloc.base);
    
        bool ok     = IntRootRem(&root, &remainder, &value, 3);
    
        Int value     = IntFrom(1001, &alloc.base);
        Int root      = IntInit(&alloc.base);
        Int remainder = IntInit(&alloc.base);
        Int value     = IntFrom(1001, &alloc.base);
        Int root      = IntInit(&alloc.base);
        Int remainder = IntInit(&alloc.base);
    
        bool ok     = IntRootRem(&root, &remainder, &value, 3);
    
        Int value     = IntFrom(999, &alloc.base);
        Int root      = IntInit(&alloc.base);
        Int remainder = IntInit(&alloc.base);
        Int value     = IntFrom(999, &alloc.base);
        Int root      = IntInit(&alloc.base);
        Int remainder = IntInit(&alloc.base);
    
        bool ok     = IntRootRem(&root, &remainder, &value, 3);
    
        Int value     = IntFrom(1000000, &alloc.base);
        Int root      = IntInit(&alloc.base);
        Int remainder = IntInit(&alloc.base);
        Int value     = IntFrom(1000000, &alloc.base);
        Int root      = IntInit(&alloc.base);
        Int remainder = IntInit(&alloc.base);
    
        bool ok     = IntRootRem(&root, &remainder, &value, 4);
        Int base  = IntFrom(7, &alloc.base);
        Int exp   = IntFrom(5, &alloc.base);
        Int power = IntInit(&alloc.base);
    
        // 7**5 == 16807.
    
        Int dividend = IntFrom(1000, &alloc.base);
        Int quotient = IntInit(&alloc.base);
    
        // 1000 / 7 == 142 (floor).
    
        Int dividend = IntFrom(1001, &alloc.base);
        Int quotient = IntInit(&alloc.base);
    
        // 1001 / 7 == 143 exactly.
    
        Int dividend     = IntFrom(123456789, &alloc.base);
        Int result_value = IntInit(&alloc.base);
    
        bool ok = int_div_exact_u64(&result_value, &dividend, 3u);
    
        Int dividend  = IntFromStr("12345678901234567890", &alloc.base);
        Int quotient  = IntInit(&alloc.base);
        Int remainder = IntInit(&alloc.base);
        Str qtext     = StrInit(&alloc.base);
        Int dividend  = IntFromStr("12345678901234567890", &alloc.base);
        Int quotient  = IntInit(&alloc.base);
        Int remainder = IntInit(&alloc.base);
        Str qtext     = StrInit(&alloc.base);
    
        Int dividend  = IntFromStr("12345678901234567890", &alloc.base);
        Int quotient  = IntInit(&alloc.base);
        Int remainder = IntInit(&alloc.base);
        Str qtext     = StrInit(&alloc.base);
        Int dividend  = IntFromStr("12345678901234567890", &alloc.base);
        Int quotient  = IntInit(&alloc.base);
        Int remainder = IntInit(&alloc.base);
        Str qtext     = StrInit(&alloc.base);
    
        Int dividend     = IntFromStr("12345678901234567890", &alloc.base);
        Int result_value = IntInit(&alloc.base);
    
        bool ok = int_mod_i64_into(&result_value, &dividend, (i64)13);
        Int base         = IntFrom(7, &alloc.base);
        Int modulus      = IntFrom(1000000007, &alloc.base);
        Int result_value = IntInit(&alloc.base);
    
        bool ok = int_pow_i64_mod(&result_value, &base, (i64)13, &modulus);
        Int base         = IntFrom(7, &alloc.base);
        Int modulus      = IntFrom(1000000007, &alloc.base);
        Int result_value = IntInit(&alloc.base);
    
        bool ok = int_pow_i64_mod(&result_value, &base, (i64)0, &modulus);
    
        Int value        = IntFrom(4096, &alloc.base);
        Int result_value = IntInit(&alloc.base);
    
        bool ok = IntRoot(&result_value, &value, 4);
        DefaultAllocator alloc = DefaultAllocatorInit();
    
        Int zero = IntInit(&alloc.base);
    
        bool result = (IntIsOdd(&zero) == false);
    
        Int dividend = IntFrom((u64)100u, &alloc.base);
        Int result   = IntInit(&alloc.base);
    
        bool ok      = IntMod(&result, &dividend, (unsigned long)7u);
        Int value  = IntFrom(3, &alloc.base);
        Int mod    = IntFrom(11, &alloc.base);
        Int result = IntInit(&alloc.base);
        Int check  = IntInit(&alloc.base);
        Int mod    = IntFrom(11, &alloc.base);
        Int result = IntInit(&alloc.base);
        Int check  = IntInit(&alloc.base);
    
        bool ok = IntModInv(&result, &value, &mod);
        Int value  = IntFrom(5, &alloc.base);
        Int mod    = IntFrom(11, &alloc.base);
        Int result = IntInit(&alloc.base);
        Int check  = IntInit(&alloc.base);
        Int mod    = IntFrom(11, &alloc.base);
        Int result = IntInit(&alloc.base);
        Int check  = IntInit(&alloc.base);
    
        bool ok = IntModInv(&result, &value, &mod);
    
        Int dividend = IntFrom(127, &alloc.base);
        Int quotient = IntInit(&alloc.base);
    
        bool ok     = IntDivExact(&quotient, &dividend, 10u);
    
        Int dividend = IntFrom(127, &alloc.base);
        Int quotient = IntInit(&alloc.base);
    
        bool ok     = IntDivExact(&quotient, &dividend, (i64)10);
    
        Int dividend  = IntFrom(127, &alloc.base);
        Int quotient  = IntInit(&alloc.base);
        Int remainder = IntInit(&alloc.base);
        Int dividend  = IntFrom(127, &alloc.base);
        Int quotient  = IntInit(&alloc.base);
        Int remainder = IntInit(&alloc.base);
    
        bool ok     = IntDivMod(&quotient, &remainder, &dividend, 0u);
    
        Int dividend  = IntFrom(127, &alloc.base);
        Int quotient  = IntInit(&alloc.base);
        Int remainder = IntInit(&alloc.base);
        Int dividend  = IntFrom(127, &alloc.base);
        Int quotient  = IntInit(&alloc.base);
        Int remainder = IntInit(&alloc.base);
    
        bool ok     = IntDivMod(&quotient, &remainder, &dividend, (i64)0);
    
        Int dividend     = IntFrom(127, &alloc.base);
        Int result_value = IntInit(&alloc.base);
    
        bool ok     = IntMod(&result_value, &dividend, 0u);
    
        Int dividend     = IntFrom(127, &alloc.base);
        Int result_value = IntInit(&alloc.base);
    
        bool ok     = IntMod(&result_value, &dividend, (i64)0);
        IntShiftLeft(&value, 50); // 2^50
    
        Int root      = IntInit(&alloc.base);
        Int remainder = IntInit(&alloc.base);
    
        Int root      = IntInit(&alloc.base);
        Int remainder = IntInit(&alloc.base);
    
        bool ok     = IntSqrtRem(&root, &remainder, &value);
        Int value = IntFrom(2, &alloc.base);
        Int mod   = IntFrom(17, &alloc.base);
        Int root  = IntInit(&alloc.base);
        Int check = IntInit(&alloc.base);
        Int mod   = IntFrom(17, &alloc.base);
        Int root  = IntInit(&alloc.base);
        Int check = IntInit(&alloc.base);
    
        bool ok = IntModSqrt(&root, &value, &mod);
        Int dividend  = IntFromStr("12345678901234567890123456789", &alloc.base);
        Int divisor   = IntFromStr("987654321987654321", &alloc.base);
        Int quotient  = IntInit(&alloc.base);
        Int remainder = IntInit(&alloc.base);
        Int divisor   = IntFromStr("987654321987654321", &alloc.base);
        Int quotient  = IntInit(&alloc.base);
        Int remainder = IntInit(&alloc.base);
    
        bool ok = int_div_mod(&quotient, &remainder, &dividend, &divisor);
        Int dividend  = IntFromStr("1000000007", &alloc.base);
        Int divisor   = IntFromStr("97", &alloc.base);
        Int quotient  = IntInit(&alloc.base);
        Int remainder = IntInit(&alloc.base);
        Int divisor   = IntFromStr("97", &alloc.base);
        Int quotient  = IntInit(&alloc.base);
        Int remainder = IntInit(&alloc.base);
    
        bool ok = int_div_mod(&quotient, &remainder, &dividend, &divisor);
        Int dividend  = IntFromStr("11975308533", &alloc.base);
        Int divisor   = IntFromStr("97", &alloc.base);
        Int quotient  = IntInit(&alloc.base);
        Int remainder = IntInit(&alloc.base);
        Int divisor   = IntFromStr("97", &alloc.base);
        Int quotient  = IntInit(&alloc.base);
        Int remainder = IntInit(&alloc.base);
    
        bool ok = int_div_mod(&quotient, &remainder, &dividend, &divisor);
        Int dividend  = IntFromStr("42", &alloc.base);
        Int divisor   = IntFromStr("1000", &alloc.base);
        Int quotient  = IntInit(&alloc.base);
        Int remainder = IntInit(&alloc.base);
        Int divisor   = IntFromStr("1000", &alloc.base);
        Int quotient  = IntInit(&alloc.base);
        Int remainder = IntInit(&alloc.base);
    
        bool ok = int_div_mod(&quotient, &remainder, &dividend, &divisor);
        Int dividend  = IntFromStr("12345", &alloc.base);
        Int divisor   = IntInit(&alloc.base); /* zero */
        Int quotient  = IntInit(&alloc.base);
        Int remainder = IntInit(&alloc.base);
        Int divisor   = IntInit(&alloc.base); /* zero */
        Int quotient  = IntInit(&alloc.base);
        Int remainder = IntInit(&alloc.base);
    
        bool ok = int_div_mod(&quotient, &remainder, &dividend, &divisor);
        Int dividend  = IntFromStr("100", &alloc.base);
        Int divisor   = IntFromStr("7", &alloc.base);
        Int remainder = IntInit(&alloc.base);
    
        /* Must abort inside int_div_mod via ValidateInt(quotient). */
        Int dividend = IntFromStr("100", &alloc.base);
        Int divisor  = IntFromStr("7", &alloc.base);
        Int quotient = IntInit(&alloc.base);
    
        /* Must abort inside int_div_mod via ValidateInt(remainder). */
        Int exp          = IntFrom(13, &alloc.base);
        Int mod          = IntFrom(497, &alloc.base);
        Int result_value = IntInit(&alloc.base);
    
        bool ok = int_pow_mod(&result_value, &base, &exp, &mod);
        Int exp          = IntFrom(987654321u, &dbg.base); // many set bits + bits
        Int mod          = IntFrom(1000000007u, &dbg.base);
        Int result_value = IntInit(&dbg.base);
    
        bool ok = int_pow_mod(&result_value, &base, &exp, &mod);
    
        Int value = IntFrom(0, &alloc.base);
        Int next  = IntInit(&alloc.base);
    
        bool ok = IntNextPrime(&next, &value);
    
        Int value = IntFrom(10, &alloc.base);
        Int next  = IntInit(&alloc.base);
    
        bool ok = IntNextPrime(&next, &value);
    
        Int value = IntFrom(9, &alloc.base);
        Int next  = IntInit(&alloc.base);
    
        bool ok = IntNextPrime(&next, &value);
        Int b            = IntFrom(5, &alloc.base);
        Int m            = IntFrom(13, &alloc.base);
        Int result_value = IntInit(&alloc.base);
    
        bool ok = IntModSub(&result_value, &a, &b, &m);
        Int base         = IntFrom(3, &alloc.base);
        Int mod          = IntFrom(17, &alloc.base);
        Int result_value = IntInit(&alloc.base);
    
        bool ok = IntPowMod(&result_value, &base, 13u, &mod);
        Int base         = IntFrom(123456789, &alloc.base);
        Int mod          = IntFrom(1000000007, &alloc.base);
        Int result_value = IntInit(&alloc.base);
    
        bool ok = IntPowMod(&result_value, &base, 0u, &mod);
        Int base         = IntFrom(2, &alloc.base);
        Int mod          = IntFrom(1000000007, &alloc.base);
        Int result_value = IntInit(&alloc.base);
    
        bool ok = IntPowMod(&result_value, &base, 64u, &mod);
        DefaultAllocator alloc = DefaultAllocatorInit();
    
        Int result_value = IntInit(&alloc.base);
        Int mod          = IntFrom(7, &alloc.base);
        DefaultAllocator alloc = DefaultAllocatorInit();
    
        Int result_value = IntInit(&alloc.base);
        Int base         = IntFrom(2, &alloc.base);
        bool success = true;
    
        Int dec = IntInit(alloc_base);
        Int hex = IntInit(alloc_base);
        Int bin = IntInit(alloc_base);
    
        Int dec = IntInit(alloc_base);
        Int hex = IntInit(alloc_base);
        Int bin = IntInit(alloc_base);
        Int oct = IntInit(alloc_base);
        Int dec = IntInit(alloc_base);
        Int hex = IntInit(alloc_base);
        Int bin = IntInit(alloc_base);
        Int oct = IntInit(alloc_base);
        Int hex = IntInit(alloc_base);
        Int bin = IntInit(alloc_base);
        Int oct = IntInit(alloc_base);
    
        Str dec_text = StrInit(&alloc);
Last updated on