51 mpz_init_set(input.
data, value.
data);
59 mpz_init_set_si(input.
data, value);
67 mpz_init_set_ui(input.
data, value);
83 mpf_set_default_prec(1024);
93 mpf_init_set_d(tempFloat, value);
98 mpf_init(tempScaling);
99 mpf_set_z(tempScaling, scaling.
data);
102 mpf_init_set_d(zeroPointFive, 0.5);
105 mpf_mul(tempFloat, tempFloat, tempScaling);
109 mpf_trunc(tempFloat, tempFloat);
114 if (-1 == mpf_sgn(tempFloat)) {
115 mpf_sub(tempFloat, tempFloat, zeroPointFive);
116 mpf_ceil(tempFloat, tempFloat);
119 mpf_add(tempFloat, tempFloat, zeroPointFive);
120 mpf_floor(tempFloat, tempFloat);
127 mpz_set_f(input.
data, tempFloat);
132 mpf_clear(tempFloat);
133 mpf_clear(tempScaling);
134 mpf_clear(zeroPointFive);
148 mpz_init(input.
data);
150 mpf_set_default_prec(1024);
160 mpf_init_set_d(tempFloat, value);
165 if (numberOfDigits > 0) {
166 mpf_init_set_si(tempScaling, 10);
167 mpf_pow_ui(tempScaling, tempScaling, numberOfDigits);
170 mpf_init_set_si(tempScaling, 1);
174 mpf_init_set_d(zeroPointFive, 0.5);
177 mpf_mul(tempFloat, tempFloat, tempScaling);
181 mpf_trunc(tempFloat, tempFloat);
186 if (-1 == mpf_sgn(tempFloat)) {
187 mpf_sub(tempFloat, tempFloat, zeroPointFive);
188 mpf_ceil(tempFloat, tempFloat);
191 mpf_add(tempFloat, tempFloat, zeroPointFive);
192 mpf_floor(tempFloat, tempFloat);
199 mpz_set_f(input.
data, tempFloat);
204 mpf_clear(tempFloat);
205 mpf_clear(tempScaling);
206 mpf_clear(zeroPointFive);
233 if (0 != mpz_init_set_str(input.
data, value.c_str(), base)) {
234 throw std::runtime_error(
"The input string is not a valid number in the specified base.");
242 mpz_clear(input.
data);
258 mpz_set_si(input.
data, value);
266 mpz_set_ui(input.
data, value);
293 mpz_sub_ui(output.
data, lhs.
data, -rhs);
296 mpz_add_ui(output.
data, lhs.
data, rhs);
306 mpz_add_ui(output.
data, lhs.
data, rhs);
325 mpz_add_ui(output.
data, lhs.
data, -rhs);
328 mpz_sub_ui(output.
data, lhs.
data, rhs);
338 mpz_sub_ui(output.
data, lhs.
data, rhs);
356 mpz_mul_si(output.
data, lhs.
data, rhs);
365 mpz_mul_ui(output.
data, lhs.
data, rhs);
388 mpz_tdiv_q_ui(output.
data, lhs.
data, -rhs);
392 mpz_tdiv_q_ui(output.
data, lhs.
data, rhs);
404 mpz_tdiv_q_ui(output.
data, lhs.
data, rhs);
433 mpz_mod_ui(output.
data, lhs.
data, -rhs);
437 mpz_mod_ui(output.
data, lhs.
data, rhs);
452 mpz_mod_ui(output.
data, lhs.
data, rhs);
463 mpz_tdiv_q_2exp(output.
data, input.
data, numberOfBits);
472 mpz_mul_2exp(output.
data, input.
data, numberOfBits);
490 return mpz_cmp_si(lhs.
data, rhs);
499 return mpz_cmp_ui(lhs.
data, rhs);
549 mpz_nextprime(output.
data, input.
data);
588 mpz_setbit(input.
data, index);
599 return mpz_tstbit(input.
data, index);
626 return mpz_sizeinbase(input.
data, base);
663 mpz_set_si(output.
data, 0);
666 mpz_pow_ui(output.
data, input.
data, power);
680 mpz_pow_ui(output.
data, input.
data, power);
773 throw std::runtime_error(
"Failed to compute inverse modulo n.");
844 void (*deallocator)(
void *, size_t);
845 mp_get_memory_functions(NULL, NULL, &deallocator);
848 char *data = mpz_get_str(NULL, base, input.
data);
850 std::string output(data);
854 (*deallocator)((
void *)data, std::char_traits<char>::length(data) + 1);
876 return mpz_get_ui(input.
data);
static void Modulo(BigIntegerBase< BigIntegerGmp > &output, const BigIntegerBase< BigIntegerGmp > &input, const BigIntegerBase< BigIntegerGmp > &n)
Computes input mod n.
static void Lcm(BigIntegerBase< BigIntegerGmp > &output, const BigIntegerBase< BigIntegerGmp > &lhs, const BigIntegerBase< BigIntegerGmp > &rhs)
Computes the least common multiple of lhs and rhs.
static void LeftShift(BigIntegerBase< BigIntegerGmp > &output, const BigIntegerBase< BigIntegerGmp > &input, const unsigned long numberOfBits)
Bitwise left shift input by numberOfBits.
static void Gcd(BigIntegerBase< BigIntegerGmp > &output, const BigIntegerBase< BigIntegerGmp > &lhs, const BigIntegerBase< BigIntegerGmp > &rhs)
Computes the greatest common divisor of lhs and rhs.
static void Swap(BigIntegerBase< BigIntegerGmp > &lhs, BigIntegerBase< BigIntegerGmp > &rhs)
Swaps lhs with rhs efficiently.
unsigned long ToUnsignedLong() const
Convert to unsigned long.
static void InvertModN(BigIntegerBase< BigIntegerGmp > &output, const BigIntegerBase< BigIntegerGmp > &input, const BigIntegerBase< BigIntegerGmp > &n)
Inverts input modulo n.
static void Destroy(BigIntegerBase< BigIntegerGmp > &input)
Destroys the underlying data from input.
static int GetBit(const BigIntegerBase< BigIntegerGmp > &input, const size_t index)
Returns the bit specified by index.
static void Subtract(BigIntegerBase< BigIntegerGmp > &output, const BigIntegerBase< BigIntegerGmp > &lhs, const BigIntegerBase< BigIntegerGmp > &rhs)
Subtracts rhs from lhs.
static void Pow(BigIntegerBase< BigIntegerGmp > &output, const BigIntegerBase< BigIntegerGmp > &input, const BigIntegerBase< BigIntegerGmp > &power)
Raises input to the specified power.
static void Initialize(BigIntegerBase< BigIntegerGmp > &input)
Initializes the underlying data from input.
static void BitwiseXor(BigIntegerBase< BigIntegerGmp > &output, const BigIntegerBase< BigIntegerGmp > &lhs, const BigIntegerBase< BigIntegerGmp > &rhs)
Computes lhs bitwise exclusive OR rhs.
static void BitwiseOr(BigIntegerBase< BigIntegerGmp > &output, const BigIntegerBase< BigIntegerGmp > &lhs, const BigIntegerBase< BigIntegerGmp > &rhs)
Computes lhs bitwise inclusive OR rhs.
static void InvertSign(BigIntegerBase< BigIntegerGmp > &output, const BigIntegerBase< BigIntegerGmp > &input)
Inverts the sign of input.
static void RightShift(BigIntegerBase< BigIntegerGmp > &output, const BigIntegerBase< BigIntegerGmp > &input, const unsigned long numberOfBits)
Bitwise right shift input by numberOfBits.
static void Abs(BigIntegerBase< BigIntegerGmp > &output, const BigIntegerBase< BigIntegerGmp > &input)
Computes the absolute value of input.
static size_t GetSize(const BigIntegerBase< BigIntegerGmp > &input, const unsigned int base=2)
Gets the length of the integer in the specified base.
static bool IsPrime(const BigIntegerBase< BigIntegerGmp > &input)
Tests if input is a prime number.
static void InvertBits(BigIntegerBase< BigIntegerGmp > &output, const BigIntegerBase< BigIntegerGmp > &input)
Computes one's complement of input.
static void Add(BigIntegerBase< BigIntegerGmp > &output, const BigIntegerBase< BigIntegerGmp > &lhs, const BigIntegerBase< BigIntegerGmp > &rhs)
Adds lhs and rhs.
static std::string ToString(const BigIntegerBase< BigIntegerGmp > &input, const unsigned int base=2)
Convert input to std::string in the specified base.
static void PowModN(BigIntegerBase< BigIntegerGmp > &output, const BigIntegerBase< BigIntegerGmp > &input, const BigIntegerBase< BigIntegerGmp > &power, const BigIntegerBase< BigIntegerGmp > &n)
Raises input to the specified power modulo n.
#define MILLER_RABIN_PRIMALITY_TEST_COUNT
The number of Miller-Rabin probabilistic primality tests to execute before a number is considered pri...
static void Multiply(BigIntegerBase< BigIntegerGmp > &output, const BigIntegerBase< BigIntegerGmp > &lhs, const BigIntegerBase< BigIntegerGmp > &rhs)
Multiplies lhs with rhs.
static void Divide(BigIntegerBase< BigIntegerGmp > &output, const BigIntegerBase< BigIntegerGmp > &lhs, const BigIntegerBase< BigIntegerGmp > &rhs)
Divides lhs by rhs.
T_Impl::BigIntegerType data
Implementation-defined big integer variable.
Definition of class BigIntegerGmp.
static void Set(BigIntegerBase< BigIntegerGmp > &input, const BigIntegerBase< BigIntegerGmp > &value)
Sets input to the specified BigInteger value.
static void GetNextPrime(BigIntegerBase< BigIntegerGmp > &output, const BigIntegerBase< BigIntegerGmp > &input)
Computes the first prime greater than the current instance.
static void BitwiseAnd(BigIntegerBase< BigIntegerGmp > &output, const BigIntegerBase< BigIntegerGmp > &lhs, const BigIntegerBase< BigIntegerGmp > &rhs)
Computes lhs bitwise AND rhs.
Template class which adds syntactic sugar to big integer operations.
static unsigned long ToUnsignedLong(const BigIntegerBase< BigIntegerGmp > &input)
Convert input to unsigned long.
static int Compare(const BigIntegerBase< BigIntegerGmp > &lhs, const BigIntegerBase< BigIntegerGmp > &rhs)
Compares lhs to rhs.
static void SetBit(BigIntegerBase< BigIntegerGmp > &input, const size_t index)
Sets a bit in input at the specified index.