#include <mpf.h>
Inheritance diagram for mp::mpf:
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::float_type | float_type |
Type for float conversion. | |
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 | |
mpf (const mpf_ &n) | |
mpf () | |
mpf (int_type n, size_type p=0) | |
mpf (float_type n, size_type p=0) | |
mpf (const mpi &n, size_type p=0) | |
mpf (const mpf &n, size_type p=0) | |
mpf (const std::string &s, char b=0) | |
mpf & | operator++ () |
const mpf | operator++ (int) |
mpf & | operator-- () |
const mpf | operator-- (int) |
const mpf & | operator= (int_type n) |
const mpf & | operator= (float_type n) |
const mpf & | operator= (const mpi &n) |
const mpf & | operator= (const mpf &n) |
const mpf & | operator= (const std::string &n) |
const mpf & | operator+= (int_type n) |
const mpf & | operator+= (float_type n) |
const mpf & | operator+= (const mpi &n) |
const mpf & | operator+= (const mpf &n) |
const mpf & | operator-= (int_type n) |
const mpf & | operator-= (float_type n) |
const mpf & | operator-= (const mpi &n) |
const mpf & | operator-= (const mpf &n) |
const mpf & | operator *= (int_type n) |
const mpf & | operator *= (float_type n) |
const mpf & | operator *= (const mpi &n) |
const mpf & | operator *= (const mpf &n) |
const mpf & | operator/= (int_type n) |
const mpf & | operator/= (float_type n) |
const mpf & | operator/= (const mpi &n) |
const mpf & | operator/= (const mpf &n) |
const mpf & | operator%= (const mpf &n) |
void | init (int_type n, size_type p=0) |
void | init (float_type n, size_type p=0) |
void | init (const mpi_ &n, size_type p=0) |
void | init (const mpf_ &n, size_type p=0) |
void | setPrecision (size_type prec) |
void | clear () |
Resets the number. | |
void | swap (mpf_ &n) |
Swaps this with n . | |
mpi_ | ipart () const |
mpi_ | fpart () const |
mpf_ | getIntPart () const |
mpf_ | getFractPart () const |
size_type | accuracy () const |
Accuracy to zero. | |
size_type | accuracy (const mpf_ &n) const |
Accuracy to another number. | |
int | compare (const mpf_ &n) const |
Compare two numbers. | |
int | compare (const mpi_ &n) const |
Compare two MPIs. | |
void | checkExp () |
Check exponant for bad conditions. | |
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 float_type () const | |
operator std::string () const | |
operator mpi () const | |
Conversion functions | |
int_type | toInt () const |
Conversion to standard signed integer type. | |
float_type | toFloat () const |
Conversion to standard signed integer type. | |
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 . | |
Initialization and basic alteration | |
void | swap (mpi_ &n) |
Swaps this with n . | |
void | resize (size_type size) |
Resizes to size bits. | |
Comparison | |
int | compare (const mpn_ &n) const |
Compare two MPNs. | |
Information retreval | |
size_type | getPrecision () const |
Get the current precision of the number. | |
size_type | getExponant () const |
Get the current exponent of the number. | |
bool | hasIntPart () const |
Get the current precision of the number. | |
bool | hasFractPart () const |
Get the current precision of the number. | |
void | normalize (mpf_ &n) |
Normalize the base MPIs over their radix points. | |
Algebraic functions | |
void | add (const mpf_ &n, size_type p=0) |
void | sub (const mpf_ &n, size_type p=0) |
void | mul (const mpf_ &n, size_type p=0) |
void | div (const mpf_ &n, size_type p=0) |
void | mod (const mpf_ &n, size_type p=0) |
void | mul_pow2 (size_type n) |
void | div_pow2 (size_type n) |
void | sqr () |
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 | |
mpf_ | pow (const mpf_ &n, size_type p=0) const |
Take the number to a real power. | |
mpf_ | sqrt (size_type p=0) const |
Find the square root of a number. | |
mpf_ | root (limb_type n, size_type p=0) const |
Find the integer root of a number. | |
mpf_ | exp (size_type p=0) const |
Set the number to the exponential function of itself. | |
mpf_ | log (size_type p=0) const |
Set the number to the natural logarithm of itself. | |
mpf_ | agm (const mpf_ &n, size_type p) const |
Computes arithmetic-geometric mean. | |
void | pi (size_type p) |
Get a truncated value of Pi. | |
Additional arithmetic operations | |
mpi_ | pow (int_type e) const |
Exponentation. | |
void | negate () |
Flips the sign register, AKA negates. | |
void | abs () |
Clears the sign register, AKA takes the absolute value. | |
mpi_ | pow_mod (const mpi_ &e, const mpi_ &m) const |
Performs modular exponentiation. | |
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. | |
Debugging output | |
void | print () const |
Binary dump to stdout. | |
Information retreval | |
bool | isNeg () const |
Is the number negative? | |
size_type | size () const |
Find the number of bits in use. | |
Bit shifting | |
void | shift_l (size_type n) |
Left shift. | |
void | shift_r (size_type n) |
Right shift. | |
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 | resetMinPrecision () |
Sets the minimum precision to the default value. | |
static void | setMinPrecision (size_type p) |
Sets the minimum precision for calculations when no precision is given. | |
static size_type | getMinPrecision () |
Gets the global minimum precision. | |
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 | |
size_type | exp_ |
floating point exponant, relative to MSL | |
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 size_type | min_precision = _MPF_MIN_PREC |
Global minimum precision. | |
static const size_type | min_prec_default = _MPF_MIN_PREC |
Default minimum precision. | |
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 floating point types, except that there is no chance (within the available heap) of overflow or underflow.
|
Type for float conversion.
|
|
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.
|
|
Accuracy to another number.
|
|
Accuracy to zero.
|
|
Addition of an MPN.
|
|
Addition of an MPI.
|
|
|
|
Addition of a single limb.
|
|
Computes arithmetic-geometric mean.
|
|
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::mpi_. |
|
Check exponant for bad conditions. Makes sure that the exponant is zero if the number is zero |
|
Makes sure no -0 condition can exist.
|
|
Resets the number.
Reimplemented from mp::mpi_. |
|
Compare two MPNs.
|
|
Compare two MPIs.
|
|
Compare two numbers.
|
|
Division by an MPI.
|
|
|
|
Division by an MPN.
|
|
Division by a single limb.
|
|
|
|
Set the number to the exponential function of itself.
|
|
|
|
Gets the default base for string conversion.
|
|
Get the current exponent of the number.
|
|
|
|
|
|
Gets the global minimum precision.
|
|
Get the current precision of the number.
|
|
Raw data output.
|
|
String output.
Converts number to a string in base
Reimplemented from mp::mpi_. |
|
Get the current precision of the number.
|
|
Get the current precision of the number.
|
|
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.
|
|
|
|
Reimplemented from mp::mpi_. |
|
|
|
Reimplemented from mp::mpi_. |
|
Interrupt the next main (math, string, PRNG) operation that runs.
|
|
|
|
Is the number negative?
|
|
Is the number zero?
|
|
Set the number to the natural logarithm of itself.
|
|
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.
|
|
Normalize the base MPIs over their radix points.
If necessary, shift either |
|
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.
|
|
Get a truncated value of Pi.
The number is accurate to |
|
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.
|
|
Take the number to a real power.
|
|
Performs modular exponentiation.
The result is equivalent to the expression: (
|
|
Binary dump to stdout. Includes size and radix information. Reimplemented from mp::mpi_. |
|
Generate a pseudo-random number.
|
|
Set the PRNG seed.
|
|
Set the PRNG seed.
|
|
Sets the minimum precision to the default value.
|
|
Resizes to Adds upper zeros or destroys upper bits as necessary.
Reimplemented from mp::mpn_. |
|
Find the integer root of a number.
|
|
Sets the default base for string conversion.
|
|
Sets the minimum precision for calculations when no precision is given.
|
|
|
|
Raw data input.
|
|
String input.
Converts the input string in base
Reimplemented from mp::mpi_. |
|
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_. |
|
Reimplemented from mp::mpi_. |
|
Find the square root of a number.
|
|
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.
|
|
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 has a fractional part, it is truncated. If number is too large to fit in standard integer an overflow_error exception is thrown.
|
|
Conversion to standard signed integer type. If number has a fractional part, it is truncated. If number is too large to fit in standard integer an overflow_error exception is thrown.
Reimplemented from mp::mpi_. |
|
Number of limbs allocated, pointed to by data.
|
|
Pointer to the data.
|
|
floating point exponant, relative to MSL
|
|
Interrupt register.
|
|
A limb with all bits set.
|
|
Size of a single limb (in bits).
|
|
Default minimum precision.
|
|
Global minimum precision.
|
|
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).
|