Main Page | Modules | Namespace List | Class Hierarchy | Class List | Directories | File List | Namespace Members | Class Members | File Members

mp::mpn_ Class Reference
[Natural numbers]

First level core class that provides natural numbers to the MP++ library. More...

#include <mpn.h>

Inheritance diagram for mp::mpn_:

mp::mpi_ mp::mpf_ mp::mpi mp::mpf List of all members.

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_typeoperator[] (size_type i) const
 Const limb retreval.
limb_typeoperator[] (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_typedata_
 Pointer to the data.

Static Protected Attributes

static bool interrupted
 Interrupt register.

Detailed Description

First level core class that provides natural numbers to the MP++ library.

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.


Member Typedef Documentation

typedef mp::limb_long_type mp::mpn_::limb_long_type
 

Type of double-long limbs.

typedef mp::limb_type mp::mpn_::limb_type
 

Type of normal limbs.

typedef mp::radix_type mp::mpn_::radix_type
 

Type of radix identifier.

typedef mp::size_type mp::mpn_::size_type
 

Type of index registers.


Constructor & Destructor Documentation

mp::mpn_::mpn_ limb_type  n = 0,
size_type  size = 0
[inline]
 

Calls init() with respective parameters.

mp::mpn_::mpn_ const mpn_ n,
size_type  size = 0
[inline]
 

Calls init() with respective parameters.

mp::mpn_::~mpn_  )  [inline]
 

Free the data.


Member Function Documentation

void mp::mpn_::add const mpn_ n  ) 
 

Addition of an MPN.

Parameters:
n Number to add

void mp::mpn_::add_l limb_type  n  )  [protected]
 

Addition of a single limb.

Parameters:
n Limb to add

void mp::mpn_::bitwise const mpn_ y,
int  type
 

Binary bitwise operations.

Parameters:
y Second parameter of the operation
type Type of bitwise operation to perform
  • 1: AND
  • 2: OR
  • 3: XOR

void mp::mpn_::bitwise_not  ) 
 

Bitwise not operation.

Operates on chunks of bytes, so that a not of a not is equal to the origional.

const byte mp::mpn_::capabilities  )  [static]
 

A bitmask of this class' numerical and functional capabilities.

Reimplemented in mp::mpf_, and mp::mpi_.

void mp::mpn_::clear  ) 
 

Resets number.

Reimplemented in mp::mpf_, and mp::mpi_.

int mp::mpn_::compare const mpn_ n  )  const
 

Compare two MPNs.

Parameters:
n Number to compare with
Returns:
sign(this - n)

void mp::mpn_::div_mod mpn_ n  ) 
 

Division by an MPN.

Parameters:
n Divisor and remainder storage. If less than 0, a range_error is thrown.

void mp::mpn_::div_mod_l limb_type n  )  [protected]
 

Division by a single limb.

Parameters:
n Divisor and remainder storage. If less than 0, a range_error is thrown.

raw_type mp::mpn_::getRaw  )  const
 

Raw data output.

string mp::mpn_::getString radix_type  b  )  const
 

String output.

Converts this to a string in base b.

Parameters:
b Base of the output string. If less than 2, an out_of_range exception is thrown.
Returns:
Output string

Reimplemented in mp::mpf_, and mp::mpi_.

void mp::mpn_::init const mpn_ n,
size_type  size = 0
 

Initialization to MPN.

MPN is truncated or padded with zeros in the to fit the size.

Parameters:
n Number to which this is initialized
size Size of the result, in limbs. If 0, size is set to 1. If less than 0, an out_of_range exception is thrown.

void mp::mpn_::init limb_type  n,
size_type  size = 0
 

Initialization to single limb.

MPN is padded with zeros to fit the size.

Parameters:
n Number to which this is initialized
size Size of the result, in limbs. If 0, size is set to 1. If less than 0, an out_of_range exception is thrown.

void mp::mpn_::interrupt  )  [static]
 

Interrupt the next main (math, string, PRNG) operation that runs.

bool mp::mpn_::isZero  )  const
 

Is the number zero?

Returns:
True if the number is zero

mpn_::size_type mp::mpn_::low_zeros  )  const
 

Returns number of consecutive zero limbs, starting at the lowest limb.

void mp::mpn_::mul const mpn_ n  ) 
 

Multiplication by an MPN.

Parameters:
n Number to multiply by

void mp::mpn_::mul_l limb_type  n  )  [protected]
 

Multiplacation by a single limb.

Parameters:
n Limb to multiply by

void mp::mpn_::onInterrupt  )  const [protected]
 

Activated when interrupt register is set.

Throws a runtime_error to break the execution of a main (math, string handling, PRNG) function.

mpn_::limb_type & mp::mpn_::operator[] size_type  i  ) 
 

Limb retreval and writing.

Parameters:
i Index of limb. If less than 0, an out_of_range exception is thrown.

const mpn_::limb_type & mp::mpn_::operator[] size_type  i  )  const
 

Const limb retreval.

Parameters:
i Index of limb. If less than 0, an out_of_range exception is thrown.

mpn_::size_type mp::mpn_::popcount  )  const
 

Population count.

Returns:
Number of set bits

void mp::mpn_::print  )  const
 

Prints data dump to stdout.

Reimplemented in mp::mpf_, and mp::mpi_.

void mp::mpn_::prng size_type  n  ) 
 

Generate a pseudo-random number.

Parameters:
n Number of random bits to generate

void mp::mpn_::prng_seed const mpn_ seed  )  [static]
 

Set the PRNG seed.

Parameters:
seed Seed for the PRNG

void mp::mpn_::prng_seed limb_long_type  seed  )  [static]
 

Set the PRNG seed.

Parameters:
seed Seed for the PRNG

void mp::mpn_::resize size_type  size  ) 
 

Resizes to limbs.

Adds upper zeros or destroys upper limbs as necessary.

Parameters:
size Size of the result, in limbs

Reimplemented in mp::mpi_.

void mp::mpn_::setRaw const raw_type data  ) 
 

Raw data input.

void mp::mpn_::setString const std::string &  s,
radix_type  b
 

String input.

Converts the input string in base b to an MPN.

Parameters:
s Input string
b Base of the input string. If less than 2, an out_of_range exception is thrown.

Reimplemented in mp::mpf_, and mp::mpi_.

void mp::mpn_::setUse  ) 
 

Sets the local use_ variable after an operation.

Not necessary for users unless twiddling with individual limbs.

void mp::mpn_::shift_l size_type  n  ) 
 

Left shift.

Non-destructively shifts left n limbs.

Parameters:
n Number of limbs to shift. If less than 0, an out_of_range exception is thrown.

Reimplemented in mp::mpi_.

void mp::mpn_::shift_r size_type  n  ) 
 

Right shift.

Destructively shifts rigt n limbs.

Parameters:
n Number of limbs to shift. If less than 0, an out_of_range exception is thrown.

Reimplemented in mp::mpi_.

mpn_::size_type mp::mpn_::size  )  const
 

Find the number of limbs in use.

Returns:
Number of limbs in use

Reimplemented in mp::mpi_.

void mp::mpn_::sqr  ) 
 

Squares the number efficiantly.

Reimplemented in mp::mpf_, and mp::mpi_.

void mp::mpn_::sub const mpn_ n  ) 
 

Subtraction of an MPN.

Parameters:
n Number to subtract

void mp::mpn_::sub_l limb_type  n  )  [protected]
 

Subtraction of a single limb.

Parameters:
n Limb to subtract

void mp::mpn_::swap mpn_ n  ) 
 

Swaps this with n.

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.

Parameters:
n Number to swap with


Member Data Documentation

size_type mp::mpn_::alloc_ [protected]
 

Number of limbs allocated, pointed to by data.

limb_type* mp::mpn_::data_ [protected]
 

Pointer to the data.

bool mp::mpn_::interrupted [static, protected]
 

Interrupt register.

const mpn_::limb_type mp::mpn_::limb_full = (1 << limb_size_bits) - 1 [static]
 

A limb with all bits set.

const mpn_::size_type mp::mpn_::limb_size_bits = _MP_SIZE / 2 [static]
 

Size of a single limb (in bits).

const mpn_::size_type mp::mpn_::size_max = INT_MAX [static]
 

The largest positive size_type value.

const string mp::mpn_::string_digits = _MP_STR_DIGIT [static]
 

The digits used in string conversion.

size_type mp::mpn_::use_ [protected]
 

Number of limbs used (always <= alloc).


The documentation for this class was generated from the following files:
Generated on Fri Feb 4 16:17:55 2005 for LibMP++ by  doxygen 1.4.1