#include <mpn.h>
Inheritance diagram for mp::mpn_:
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::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 | |
mpn_ (limb_type n=0, size_type size=0) | |
Calls init() with respective parameters. | |
mpn_ (const mpn_ &n, size_type size=0) | |
Calls init() with respective parameters. | |
~mpn_ () | |
Free the data. | |
void | print () const |
Prints data dump to stdout. | |
void | setUse () |
Sets the local use_ variable after an operation. | |
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 | clear () |
Resets number. | |
void | resize (size_type size) |
Resizes to limbs . | |
void | swap (mpn_ &n) |
Swaps this with n . | |
Information retreval | |
size_type | size () const |
Find the number of limbs in use. | |
bool | isZero () const |
Is the number zero? | |
size_type | low_zeros () const |
Returns number of consecutive zero limbs, starting at the lowest limb. | |
Limb shifting | |
void | shift_l (size_type n) |
Left shift. | |
void | shift_r (size_type n) |
Right shift. | |
String conversion | |
void | setString (const std::string &s, radix_type b) |
String input. | |
std::string | getString (radix_type b) const |
String output. | |
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. | |
Comparison | |
int | compare (const mpn_ &n) const |
Compare two MPNs. | |
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 algebraic functions | |
void | sqr () |
Squares the number efficiantly. | |
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 | 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 | |
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 bool | interrupted |
Interrupt register. |
MPNs are the underlying class for the whole library, they handle all of the memory management, string I/O, bitwise operators, and basic algebra.
MPNs are stored as basic arrays of limbs (a limb is a single digit, half of the regester size of the CPU). None of the MPN functions have overloads, so care must be taken not to use the assignment or any other operator when dealing with them.
All of the memory management takes place here too, so it is abstracted from the higher levels.
There is no special case for zero in the same sense that other systems use (a size of zero). The method for storing a zero is a one-limb MPN set to zero.
All of the sizes here (except for the PRNG) are in number of limbs.
|
Type of double-long limbs.
|
|
Type of normal limbs.
|
|
Type of radix identifier.
|
|
Type of index registers.
|
|
Calls init() with respective parameters.
|
|
Calls init() with respective parameters.
|
|
Free the data.
|
|
Addition of an MPN.
|
|
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.
|
|
Resets number.
|
|
Compare two MPNs.
|
|
Division by an MPN.
|
|
Division by a single limb.
|
|
Raw data output.
|
|
String output.
Converts
|
|
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.
|
|
Interrupt the next main (math, string, PRNG) operation that runs.
|
|
Is the number zero?
|
|
Returns number of consecutive zero limbs, starting at the lowest limb.
|
|
Multiplication by an MPN.
|
|
Multiplacation by a single limb.
|
|
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.
|
|
Prints data dump to stdout.
|
|
Generate a pseudo-random number.
|
|
Set the PRNG seed.
|
|
Set the PRNG seed.
|
|
Resizes to Adds upper zeros or destroys upper limbs as necessary.
Reimplemented in mp::mpi_. |
|
Raw data input.
|
|
String input.
Converts the input string in base
|
|
Sets the local Not necessary for users unless twiddling with individual limbs. |
|
Left shift.
Non-destructively shifts left
Reimplemented in mp::mpi_. |
|
Right shift.
Destructively shifts rigt
Reimplemented in mp::mpi_. |
|
Find the number of limbs in use.
Reimplemented in mp::mpi_. |
|
Squares the number efficiantly.
|
|
Subtraction of an MPN.
|
|
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.
|
|
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).
|
|
The largest positive size_type value.
|
|
The digits used in string conversion.
|
|
Number of limbs used (always <= alloc).
|