Boost.Real  1.0.0
Boost.Real numerical data type for real numbers representation using range arithmetic.
boost::real::real_algorithm Class Reference

boost::real::real_algorithm is a C++ class that represents real numbers as a a function that calculates the n-th digit o the number, a sign and an exponent. More...

#include <real_algorithm.hpp>

Classes

class  const_precision_iterator
 is a forward iterator that iterates a boost::real::real_algorithm number approximation intervals. The iterator calculates the initial interval with the initial precision and then it increase the precision in each iteration (++) and recalculate the interval. More...
 

Public Member Functions

 real_algorithm ()=default
 Default constructor: Construct an empty boost::real::real_algorithm with undefined representation and behaviour.
 
 real_algorithm (const real_algorithm &other)=default
 Copy constructor: Creates a copy of the boost::real::real_algorithm number other. More...
 
 real_algorithm (int(*get_nth_digit)(unsigned int), int exponent)
 Lambda function constructor with exponent: Creates a boost::real::real_algorithm instance that represents the number where the exponent is used to set the number integer part and the lambda function digits is used to know the number digits, this function returns the n-th number digit. The number is positive. More...
 
 real_algorithm (int(*get_nth_digit)(unsigned int), int exponent, bool positive)
 Lambda function constructor with exponent and sign: Creates a boost::real::real_algorithm instance that represents the number where the exponent is used to set the number integer part and the lambda function digits is used to know the number digit, this function returns the n-th number digit. This constructor uses the sign to determine if the number is positive or negative. More...
 
unsigned int max_precision () const
 Returns the maximum allowed precision, if that precision is reached and an operator need more precision, a precision_exception should be thrown. More...
 
void set_maximum_precision (unsigned int maximum_precision)
 Set a new maximum precision for the instance. More...
 
int exponent () const
 
bool positive () const
 
const_precision_iterator cbegin () const
 Construct a new boost::real::real_algorithm::con_precision_iterator that iterates the number approximation intervals in increasing order according to the approximation precision. More...
 
const_precision_iterator cend () const
 Construct a new boost::real::real_algorithm::con_precision_iterator that iterates the number approximation intervals in increasing order according to the approximation precision. More...
 
int operator[] (unsigned int n) const
 Returns the n-th digit the number. More...
 
real_algorithmoperator= (const real_algorithm &other)=default
 It assign a new copy of the other boost::real::real_algorithm number in the *this boost::real::real_algorithm number. More...
 

Static Public Attributes

static unsigned int maximum_precision
 

Detailed Description

boost::real::real_algorithm is a C++ class that represents real numbers as a a function that calculates the n-th digit o the number, a sign and an exponent.

Author
Laouen Mayal Louan Belloli

Because a function pointer of lambda function is used to obtain the number digits on demand, numbers with infinite representations as the irrational numbers can be represented using this class.

Constructor & Destructor Documentation

boost::real::real_algorithm::real_algorithm ( const real_algorithm other)
default

Copy constructor: Creates a copy of the boost::real::real_algorithm number other.

Parameters
other- the boost::real::real instance to copy.
boost::real::real_algorithm::real_algorithm ( int(*)(unsigned int)  get_nth_digit,
int  exponent 
)
inlineexplicit

Lambda function constructor with exponent: Creates a boost::real::real_algorithm instance that represents the number where the exponent is used to set the number integer part and the lambda function digits is used to know the number digits, this function returns the n-th number digit. The number is positive.

Parameters
get_nth_digit- a function pointer or lambda function that given an unsigned int "n" as parameter, it returns the number n-th digit.
exponent- an integer representing the number exponent.
boost::real::real_algorithm::real_algorithm ( int(*)(unsigned int)  get_nth_digit,
int  exponent,
bool  positive 
)
inlineexplicit

Lambda function constructor with exponent and sign: Creates a boost::real::real_algorithm instance that represents the number where the exponent is used to set the number integer part and the lambda function digits is used to know the number digit, this function returns the n-th number digit. This constructor uses the sign to determine if the number is positive or negative.

Parameters
get_nth_digit- a function pointer or lambda function that given an unsigned int "n" as parameter, it returns the number n-th digit.
exponent- an integer representing the number exponent.
positive- a bool that represent the number sign. If positive is set to true, the number is positive, otherwise is negative.

Member Function Documentation

const_precision_iterator boost::real::real_algorithm::cbegin ( ) const
inline

Construct a new boost::real::real_algorithm::con_precision_iterator that iterates the number approximation intervals in increasing order according to the approximation precision.

The iterator starts pointing the interval with the minimum precision.

Returns
a boost::real::real_algorithm::const_precision_iterator of the number.
const_precision_iterator boost::real::real_algorithm::cend ( ) const
inline

Construct a new boost::real::real_algorithm::con_precision_iterator that iterates the number approximation intervals in increasing order according to the approximation precision.

The iterator starts pointing the interval with the maximum allowed precision.

Returns
a boost::real::real_algorithm::const_precision_iterator of the number.
int boost::real::real_algorithm::exponent ( ) const
inline
Returns
An integer with the number exponent
unsigned int boost::real::real_algorithm::max_precision ( ) const
inline

Returns the maximum allowed precision, if that precision is reached and an operator need more precision, a precision_exception should be thrown.

Returns
an integer with the maximum allowed precision.
real_algorithm& boost::real::real_algorithm::operator= ( const real_algorithm other)
default

It assign a new copy of the other boost::real::real_algorithm number in the *this boost::real::real_algorithm number.

Parameters
other- the boost::real::real_algorithm number to copy.
Returns
a reference of *this with the new represented number.
int boost::real::real_algorithm::operator[] ( unsigned int  n) const
inline

Returns the n-th digit the number.

Parameters
n- an unsigned int number indicating the index of the requested digit.
Returns
an integer with the value of the number n-th digit.
bool boost::real::real_algorithm::positive ( ) const
inline
Returns
A bool indicating if the number is positive (true) or negative (false)
void boost::real::real_algorithm::set_maximum_precision ( unsigned int  maximum_precision)
inline

Set a new maximum precision for the instance.

Parameters
maximum_precision- an unsigned int to set as the new precision.

The documentation for this class was generated from the following file: