Classes | Namespaces | Defines | Typedefs | Functions

integer.hpp File Reference

Declares the arbitrary-length integer type. More...

Go to the source code of this file.

Classes

class  boost::xint::integer_t<>
 The integer_t class template. More...

Namespaces

namespace  boost
namespace  boost::xint
 

All the types and functions of the library are within this namespace.


Defines

#define BOOST_XINT_ANY_COMPARE(rtype, op)
 Allows for comparisons between integer_t types and other integral values.
#define BOOST_XINT_ANY_MATH(op)
 Allows for operations between integer_t types and other integral values.

Typedefs

typedef integer_t boost::xint::integer
 The default arbitrary-length integer type.
typedef integer_t
< options::nothrow > 
boost::xint::nothrow_integer
 The default arbitrary-length nothrow_integer type.

Functions

template<... >
void boost::xint::swap (integer_t<...> &left, integer_t<...> &right)
Mathematical primitives

There are only a few functions here because almost all mathematical primitives are implemented as operators.

template<... >
integer_t<...> boost::xint::abs (const integer_t<...> n)
 Returns the absolute value of an integer.
template<... >
integer_t<...>::divide_t boost::xint::divide (const integer_t<...> dividend, const integer_t<...> divisor)
 Calculate how many dividends would fit into divisor, with the remainder.
template<... >
integer_t<...> boost::xint::difference (const integer_t<...> n1, const integer_t<...> n2)
 Calculate the absolute difference between two integers.
Powers and roots

See also:
integer_t::pow2
integer_t::factorial
template<... >
integer_t<...> boost::xint::square (const integer_t<...> n)
 Calculate the value of n2
template<... >
integer_t<...> boost::xint::pow (const integer_t<...> n, const integer_t<...> e)
 Calculate the value of ne
template<... >
integer_t<...> boost::xint::square_root (const integer_t<...> n)
 Calculate the square root of an integer.
Conversion functions

Note that these only convert an integer type to something else. See the integer constructors for conversions the other way.

template<typename T , ... >
boost::xint::to (const integer_t<...> n)
 Converts an xint::integer type to a built-in integer type.
template<typename charT , ... >
std::basic_string< charT > boost::xint::to_stringtype (const integer_t<...> n, std::size_t base=10, bool uppercase=false)
 Creates a string representation of the specified integer.
template<... >
std::string boost::xint::to_string (const integer_t<...> n, std::size_t base=10, bool uppercase=false)
 A shorthand function that calls to_stringtype<char>.
template<... >
std::wstring boost::xint::to_wstring (const integer_t<...> n, std::size_t base=10, bool uppercase=false)
 A shorthand function that calls to_stringtype<wchar_t>.
template<... >
xint::binary_t boost::xint::to_binary (const integer_t<...> n, bitsize_t bits=0)
 Creates a binary representation of an integer.
Bit-manipulation functions

template<... >
bool boost::xint::getbit (const integer_t<...> n, bitsize_t bit)
 Queries the value of a particular bit in an integer.
template<... >
void boost::xint::setbit (integer_t<...> &n, bitsize_t bit)
 Sets a specific bit in an integer to one.
template<... >
void boost::xint::clearbit (integer_t<...> &n, bitsize_t bit)
 Sets a specific bit in an integer to zero.
template<... >
bitsize_t boost::xint::lowestbit (const integer_t<...> n, bitsize_t return_if_zero=0)
 Obtains the index of the lowest bit in an integer with a value of one.
template<... >
bitsize_t boost::xint::highestbit (const integer_t<...> n, bitsize_t return_if_zero=0)
 Obtains the index of the highest bit in an integer with a value of one.
Modular math functions

A common reason to use a large-integer library is to implement public-key encryption, and the algorithms for such encryption often use modular math.

See also:
operator%(integer_t, integer_t)
integer_t::operator%=
template<... >
integer_t<...> boost::xint::mulmod (const integer_t<...> n, const integer_t<...> by, const integer_t<...> modulus)
 Get the modular product of two integers.
template<... >
integer_t<...> boost::xint::sqrmod (const integer_t<...> n, const integer_t<...> modulus)
 Get the modular product of squaring an integer.
template<... >
integer_t<...> boost::xint::powmod (const integer_t<...> n, const integer_t<...> exponent, const integer_t<...> modulus, bool no_monty=false)
 Get the result of ne % m, keeping the intermediate results (relatively) small.
template<... >
integer_t<...> boost::xint::invmod (const integer_t<...> n, const integer_t<...> modulus)
 Get the modular inverse of a number in a modulus, if there is one.
Random and prime number functions

See also:
integer_t::random_by_size
integer_t::random_prime
template<... >
int boost::xint::is_prime (const integer_t<...> n, callback_t callback=no_callback)
 Tests an integer for primality.
Comparison Operators

The nothrow versions of these functions return false instead of throwing.

See also:
compare(integer_t, integer_t, bool)
template<... >
bool boost::xint::operator< (const integer_t<...> n1, const integer_t<...> n2)
template<... >
bool boost::xint::operator> (const integer_t<...> n1, const integer_t<...> n2)
template<... >
bool boost::xint::operator<= (const integer_t<...> n1, const integer_t<...> n2)
template<... >
bool boost::xint::operator>= (const integer_t<...> n1, const integer_t<...> n2)
template<... >
bool boost::xint::operator== (const integer_t<...> n1, const integer_t<...> n2)
template<... >
bool boost::xint::operator!= (const integer_t<...> n1, const integer_t<...> n2)
Mathematical and Bitwise Operators

These act exactly the same as for the built-in integer types.

template<... >
integer_t<...> boost::xint::operator+ (const integer_t<...> n1, const integer_t<...> n2)
 Calculate the sum of two integers.
template<... >
integer_t<...> boost::xint::operator- (const integer_t<...> n1, const integer_t<...> n2)
 Calculate the difference between two integers.
template<... >
integer_t<...> boost::xint::operator* (const integer_t<...> n1, const integer_t<...> n2)
 Calculate the product of two integers.
template<... >
integer_t<...> boost::xint::operator/ (const integer_t<...> dividend, const integer_t<...> divisor)
 Calculate how many dividends would fit into divisor.
template<... >
integer_t<...> boost::xint::operator% (const integer_t<...> n1, const integer_t<...> n2)
 Get the remainder after dividing a number by another.
template<... >
integer_t<...> boost::xint::operator& (const integer_t<...> n1, const integer_t<...> n2)
 Combine two integers using a bitwise AND operation.
template<... >
integer_t<...> boost::xint::operator| (const integer_t<...> n1, const integer_t<...> n2)
 Combine two integers using a bitwise OR operation.
template<... >
integer_t<...> boost::xint::operator^ (const integer_t<...> n1, const integer_t<...> n2)
 Combine two integers using a bitwise XOR operation.
Miscellaneous functions

template<... >
integer_t<...> boost::xint::gcd (const integer_t<...> num1, const integer_t<...> num2)
 Calculate the Greatest Common Denominator of two integers.
template<... >
integer_t<...> boost::xint::lcm (const integer_t<...> num1, const integer_t<...> num2)
 Calculate the Least Common Multiple of two integers.
template<... >
int boost::xint::compare (const integer_t<...> n1, const integer_t<...> n2, bool ignoresign=false)
 Compare two integer objects.
template<... >
size_t boost::xint::log2 (const integer_t<...> n)
 Get the log2 value of an integer.
Stream input/output functions

template<typename charT , typename traits , ... >
std::basic_ostream< charT,
traits > & 
boost::xint::operator<< (std::basic_ostream< charT, traits > &out, const integer_t<...> n)
template<typename charT , typename traits , ... >
std::basic_istream< charT,
traits > & 
boost::xint::operator>> (std::basic_istream< charT, traits > &in, integer_t<...> &n)

Detailed Description

Declares the arbitrary-length integer type.

Definition in file integer.hpp.


Define Documentation

#define BOOST_XINT_ANY_COMPARE (   rtype,
  op 
)
Value:
template <BOOST_XINT_CLASS_APARAMS, typename N> \
    rtype op(const integer_t<BOOST_XINT_APARAMS> n1, const N n2) { \
        if (integer_t<BOOST_XINT_APARAMS>::Nothrow) { \
            BOOST_XINT_TRY { \
                return op(n1, integer_t<BOOST_XINT_APARAMS>(n2)); \
            } BOOST_XINT_CATCH { \
                return rtype(0); \
            } \
        } else { \
            return op(n1, integer_t<BOOST_XINT_APARAMS>(n2)); \
        } \
    } \
    \
    template <typename N, BOOST_XINT_CLASS_APARAMS> \
    rtype op(const N n1, const integer_t<BOOST_XINT_APARAMS> n2) { \
        if (integer_t<BOOST_XINT_APARAMS>::Nothrow) { \
            BOOST_XINT_TRY { \
                return op(integer_t<BOOST_XINT_APARAMS>(n1), n2); \
            } BOOST_XINT_CATCH { \
                return rtype(0); \
            } \
        } else { \
            return op(integer_t<BOOST_XINT_APARAMS>(n1), n2); \
        } \
    }

Allows for comparisons between integer_t types and other integral values.

Definition at line 2359 of file integer.hpp.

#define BOOST_XINT_ANY_MATH (   op  ) 

Allows for operations between integer_t types and other integral values.

Definition at line 2395 of file integer.hpp.


© Copyright Chad Nelson, 2010-2011. Distributed under the Boost Software License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)