This is a simple implementation of a Big-Unsigned Integer - biguint
in C++.
The main idea is to divide the number into blocks of 6 digits and do the calculations on these blocks. The maximum value of a block is between
On 64-bit machines, the size of int
is vector<int>
is
From this, we can calculate the maximum size of a biguint
number:
- I/O operators:
<<
,>>
- Comparision operators:
==
,!=
,<
,>
,<=
,>=
- Arithmetic operators:
+
,-
,*
,/
,%
- Assignment operators:
=
,+=
,-=
,*=
,/=
,%=
,++
,--
- Modular exponentiation:
pow(exp, modulo)
- Multiplication by
$10^n$ :scale(n)
- Scalar multiplication:
scalar_mult(n)
- Square root:
sqrt()
- Greatest common divisor:
gcd(rhs)
- Modular multiplicative inverse:
mod_inverse(modulo)
- Get
$10^n$ :power_of_10(n)
- Generate random with given number length:
rand_of_num_len(len)
- Generate random with given bit length:
rand_of_bit_len(len)
- Generate random under a maximum value:
rand(max)
- Convert to
int
:to_int()
- Convert to
string
:to_string()
- Convert to
hex
:to_hex(is_big_endian)
- Convert from
hex
:from_hex(s, is_big_endian)
- Check if odd:
is_odd()
- Check if prime:
is_prime(times)
- Fast Fourier Transform and Schönhage–Strassen Algorithm for
*
(multiplication) - Right-to-left binary method for
pow(exp, modulo)
- Bisection Method for
sqrt()
- Extended Euclidean Algorithm for
mod_inverse(modulo)
- Euclidean Algorithm for
gcd(rhs)
- Miller-Rabin Algorithm for
is_prime(times)