#include <mpi.h>
Inheritance diagram for mp::mpi:
Pseudo-random number generator | |
void | prng (size_type n) |
Generate a pseudo-random number. | |
static void | prng_seed (limb_long_type seed) |
Set the PRNG seed. | |
static void | prng_seed (const mpn_ &seed) |
Set the PRNG seed. | |
Public Types | |
typedef mp::int_type | int_type |
Type for integer conversion. | |
typedef mp::size_type | size_type |
Type of index registers. | |
typedef mp::limb_type | limb_type |
Type of normal limbs. | |
typedef mp::limb_long_type | limb_long_type |
Type of double-long limbs. | |
typedef mp::radix_type | radix_type |
Type of radix identifier. | |
Public Member Functions | |
mpi (const mpi_ &n) | |
mpi () | |
mpi (int_type n, size_type size=0) | |
mpi (const mpi &n, size_type size=0) | |
mpi (const std::string &s, radix_type b=0) | |
void | prime (size_type n) |
Set to a random prime number. | |
bool | isPrime (int n=_MP_RM_TESTS) |
Primality testing. | |
int_type | toInt () const |
Conversion to standard signed integer type. | |
int | compare (const mpi_ &n) const |
Compare two MPIs. | |
void | checkNeg () |
Makes sure no -0 condition can exist. | |
void | setUse () |
Sets the local use_ variable after an operation. | |
Conversion operators | |
operator int_type () const | |
operator std::string () const | |
Assignment overloads | |
const mpi & | operator= (int_type n) |
const mpi & | operator= (const mpi &n) |
const mpi & | operator= (const std::string &s) |
Bit shifting assignment overloads | |
const mpi & | operator<<= (size_type y) |
const mpi & | operator>>= (size_type y) |
Bitwise assignment overloads | |
const mpi & | operator &= (const mpi &n) |
const mpi & | operator|= (const mpi &n) |
const mpi & | operator^= (const mpi &n) |
mpi | operator~ () |
Increment & decrement overloads | |
mpi & | operator++ () |
const mpi | operator++ (int) |
mpi & | operator-- () |
const mpi | operator-- (int) |
Arithmetic assignment overloads | |
const mpi & | operator+= (const mpi &n) |
const mpi & | operator-= (const mpi &n) |
const mpi & | operator *= (const mpi &n) |
const mpi & | operator/= (const mpi &n) |
const mpi & | operator%= (const mpi &n) |
Initialization and basic alteration | |
void | init (int_type n, size_type size=0) |
Initialization to signed integer. | |
void | init (const mpi_ &n, size_type size=0) |
Initialization to an MPI. | |
void | clear () |
Resets the number. | |
void | resize (size_type size) |
Resizes to size bits. | |
void | swap (mpi_ &n) |
Swaps this with n . | |
Initialization and basic alteration | |
void | init (limb_type n, size_type size=0) |
Initialization to single limb. | |
void | init (const mpn_ &n, size_type size=0) |
Initialization to MPN. | |
void | swap (mpn_ &n) |
Swaps this with n . | |
Information retreval | |
bool | isNeg () const |
Is the number negative? | |
size_type | size () const |
Find the number of bits in use. | |
String conversion | |
void | setString (const std::string &s, radix_type b=0) |
String input. | |
std::string | getString (radix_type b=string_base) const |
String output. | |
Bit shifting | |
void | shift_l (size_type n) |
Left shift. | |
void | shift_r (size_type n) |
Right shift. | |
Debugging output | |
void | print () const |
Binary dump to stdout. | |
Algebraic functions | |
void | add (const mpi_ &n) |
Addition of an MPI. | |
void | sub (const mpi_ &n) |
Subtraction of an MPI. | |
void | mul (const mpi_ &n) |
Multiplication by an MPI. | |
void | div (const mpi_ &n) |
Division by an MPI. | |
void | mod (const mpi_ &n) |
Modulus by an MPI. | |
Algebraic functions | |
void | add (const mpn_ &n) |
Addition of an MPN. | |
void | sub (const mpn_ &n) |
Subtraction of an MPN. | |
void | mul (const mpn_ &n) |
Multiplication by an MPN. | |
void | div_mod (mpn_ &n) |
Division by an MPN. | |
Additional arithmetic operations | |
void | negate () |
Flips the sign register, AKA negates. | |
void | abs () |
Clears the sign register, AKA takes the absolute value. | |
void | sqr () |
Squares the number efficiantly. | |
mpi_ | pow (int_type e) const |
Exponentation. | |
mpi_ | pow_mod (const mpi_ &e, const mpi_ &m) const |
Performs modular exponentiation. | |
Comparison | |
int | compare (const mpn_ &n) const |
Compare two MPNs. | |
Information retreval | |
bool | isZero () const |
Is the number zero? | |
size_type | low_zeros () const |
Returns number of consecutive zero limbs, starting at the lowest limb. | |
Raw accessors | |
Data format is | |
raw_type | getRaw () const |
Raw data output. | |
void | setRaw (const raw_type &data) |
Raw data input. | |
Limb retreval overloads | |
Subscript operator is overloaded to allow users to interact with the individual limbs of a number in a safe way. | |
const limb_type & | operator[] (size_type i) const |
Const limb retreval. | |
limb_type & | operator[] (size_type i) |
Limb retreval and writing. | |
Bitwise functions | |
size_type | popcount () const |
Population count. | |
void | bitwise (const mpn_ &y, int type) |
Binary bitwise operations. | |
void | bitwise_not () |
Bitwise not operation. | |
Static Public Member Functions | |
static const byte | capabilities () |
A bitmask of this class' numerical and functional capabilities. | |
static void | setDefaultBase (radix_type b) |
Sets the default base for string conversion. | |
static radix_type | getDefaultBase () |
Gets the default base for string conversion. | |
static void | interrupt () |
Interrupt the next main (math, string, PRNG) operation that runs. | |
Static Public Attributes | |
static const size_type | limb_size_bits = _MP_SIZE / 2 |
Size of a single limb (in bits). | |
static const limb_type | limb_full = (1 << limb_size_bits) - 1 |
A limb with all bits set. | |
static const size_type | size_max = INT_MAX |
The largest positive size_type value. | |
static const std::string | string_digits = _MP_STR_DIGIT |
The digits used in string conversion. | |
Protected Member Functions | |
void | onInterrupt () const |
Activated when interrupt register is set. | |
Algebraic functions with single limbs | |
These are much faster than the normal algebraic functions, and are called anyway if the argument fits within a single limb. | |
void | add_l (limb_type n) |
Addition of a single limb. | |
void | sub_l (limb_type n) |
Subtraction of a single limb. | |
void | mul_l (limb_type n) |
Multiplacation by a single limb. | |
void | div_mod_l (limb_type &n) |
Division by a single limb. | |
Protected Attributes | |
bool | neg_ |
negativity register (true if negative). | |
size_type | alloc_ |
Number of limbs allocated, pointed to by data. | |
size_type | use_ |
Number of limbs used (always <= alloc). | |
limb_type * | data_ |
Pointer to the data. | |
Static Protected Attributes | |
static radix_type | string_base = _MP_STR_BASE |
Default base for string conversion. | |
static bool | interrupted |
Interrupt register. |
All standard arithmetic, logical, conversion, and comparison operators are overloaded, so no knowledge of the underlying functions is required.
Most overloads function just as if operating on standard signed integer types, except that there is no chance (within the available heap) of overflow.
|
Type for integer conversion.
|
|
Type of double-long limbs.
|
|
Type of normal limbs.
|
|
Type of radix identifier.
|
|
Type of index registers.
|
|
|
|
|
|
|
|
|
|
|
|
Clears the sign register, AKA takes the absolute value.
|
|
Addition of an MPN.
|
|
Addition of an MPI.
|
|
Addition of a single limb.
|
|
Binary bitwise operations.
|
|
Bitwise not operation. Operates on chunks of bytes, so that a not of a not is equal to the origional. |
|
A bitmask of this class' numerical and functional capabilities.
Reimplemented from mp::mpn_. Reimplemented in mp::mpf_. |
|
Makes sure no -0 condition can exist.
|
|
Resets the number.
Reimplemented from mp::mpn_. Reimplemented in mp::mpf_. |
|
Compare two MPNs.
|
|
Compare two MPIs.
|
|
Division by an MPI.
|
|
Division by an MPN.
|
|
Division by a single limb.
|
|
Gets the default base for string conversion.
|
|
Raw data output.
|
|
String output.
Converts number to a string in base
Reimplemented from mp::mpn_. Reimplemented in mp::mpf_. |
|
Initialization to MPN. MPN is truncated or padded with zeros in the to fit the size.
|
|
Initialization to single limb. MPN is padded with zeros to fit the size.
|
|
Initialization to an MPI. MPI is truncated or padded with zeros to fit the size.
Reimplemented in mp::mpf_. |
|
Initialization to signed integer. MPI is padded with zeros to fit the size.
Reimplemented in mp::mpf_. |
|
Interrupt the next main (math, string, PRNG) operation that runs.
|
|
Is the number negative?
|
|
Primality testing. Uses the Rabin-Miller probabilistic test to determine if a number is likely prime or not.
|
|
Is the number zero?
|
|
Returns number of consecutive zero limbs, starting at the lowest limb.
|
|
Modulus by an MPI.
|
|
Multiplication by an MPN.
|
|
Multiplication by an MPI.
|
|
Multiplacation by a single limb.
|
|
Flips the sign register, AKA negates.
|
|
Activated when interrupt register is set. Throws a runtime_error to break the execution of a main (math, string handling, PRNG) function. |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Limb retreval and writing.
|
|
Const limb retreval.
|
|
|
|
|
|
|
|
Population count.
|
|
Exponentation. Takes the number to a basic signed integer power. The exponant is limited because the number would overflow if allowed to be any larger.
|
|
Performs modular exponentiation.
The result is equivalent to the expression: (
|
|
Set to a random prime number.
|
|
Binary dump to stdout. Includes sign and size information. Reimplemented from mp::mpn_. Reimplemented in mp::mpf_. |
|
Generate a pseudo-random number.
|
|
Set the PRNG seed.
|
|
Set the PRNG seed.
|
|
Resizes to Adds upper zeros or destroys upper bits as necessary.
Reimplemented from mp::mpn_. |
|
Sets the default base for string conversion.
|
|
Raw data input.
|
|
String input.
Converts the input string in base
Reimplemented from mp::mpn_. Reimplemented in mp::mpf_. |
|
Sets the local Not necessary for users unless twiddling with individual limbs. |
|
Left shift. Non-destructively shifts left n bits, AKA "multiplication by 2 ^\a n".
Reimplemented from mp::mpn_. |
|
Right shift. Destructively shifts right n bits, AKA "integer division by 2 ^\a n".
Reimplemented from mp::mpn_. |
|
Find the number of bits in use.
Reimplemented from mp::mpn_. |
|
Squares the number efficiantly.
Reimplemented from mp::mpn_. Reimplemented in mp::mpf_. |
|
Subtraction of an MPN.
|
|
Subtraction of an MPI.
|
|
Subtraction of a single limb.
|
|
Swaps This swaps the internals of the number, so it is very fast. A fast move can be done by clear()ing the destination before swap()ing.
|
|
Swaps Function swaps the internals of the number, so it is very fast. A fast move can be done by clear()ing the destination before swap()ing.
|
|
Conversion to standard signed integer type. If number is too large to fit in standard integer an overflow_error exception is thrown.
Reimplemented in mp::mpf_. |
|
Number of limbs allocated, pointed to by data.
|
|
Pointer to the data.
|
|
Interrupt register.
|
|
A limb with all bits set.
|
|
Size of a single limb (in bits).
|
|
negativity register (true if negative).
|
|
The largest positive size_type value.
|
|
Default base for string conversion.
|
|
The digits used in string conversion.
|
|
Number of limbs used (always <= alloc).
|