# Parma_Polyhedra_Library::Checked_Number< T, Policy > Class Template Reference
[C++ Language Interface]

A wrapper for numeric types implementing a given policy. More...

List of all members.

## Public Member Functions

bool | OK () const
| Checks if all the invariants are satisfied.
Result | classify (bool nan=true, bool inf=true, bool sign=true) const
| Classifies *this.
Constructors
| Checked_Number ()
| Default constructor.
| Checked_Number (const Checked_Number &y)
| Copy-constructor.
template<typename From, typename From_Policy>
| Checked_Number (const Checked_Number< From, From_Policy > &y, Rounding_Dir dir)
| Direct initialization from a Checked_Number and rounding mode.
| Checked_Number (const signed char y, Rounding_Dir dir)
| Direct initialization from a signed char and rounding mode.
| Checked_Number (const signed short y, Rounding_Dir dir)
| Direct initialization from a signed short and rounding mode.
| Checked_Number (const signed int y, Rounding_Dir dir)
| Direct initialization from a signed int and rounding mode.
| Checked_Number (const signed long y, Rounding_Dir dir)
| Direct initialization from a signed long and rounding mode.
| Checked_Number (const signed long long y, Rounding_Dir dir)
| Direct initialization from a signed long long and rounding mode.
| Checked_Number (const unsigned char y, Rounding_Dir dir)
| Direct initialization from an unsigned char and rounding mode.
| Checked_Number (const unsigned short y, Rounding_Dir dir)
| Direct initialization from an unsigned short and rounding mode.
| Checked_Number (const unsigned int y, Rounding_Dir dir)
| Direct initialization from an unsigned int and rounding mode.
| Checked_Number (const unsigned long y, Rounding_Dir dir)
| Direct initialization from an unsigned long and rounding mode.
| Checked_Number (const unsigned long long y, Rounding_Dir dir)
| Direct initialization from an unsigned long long and rounding mode.
| Checked_Number (const float y, Rounding_Dir dir)
| Direct initialization from a float and rounding mode.
| Checked_Number (const double y, Rounding_Dir dir)
| Direct initialization from a double and rounding mode.
| Checked_Number (const long double y, Rounding_Dir dir)
| Direct initialization from a long double and rounding mode.
| Checked_Number (const mpq_class &y, Rounding_Dir dir)
| Direct initialization from a rational and rounding mode.
| Checked_Number (const mpz_class &y, Rounding_Dir dir)
| Direct initialization from an unbounded integer and rounding mode.
| Checked_Number (const char *y, Rounding_Dir dir)
| Direct initialization from a C string and rounding mode.
| Checked_Number (const Minus_Infinity &y, Rounding_Dir dir)
| Direct initialization from minus infinity and rounding mode.
| Checked_Number (const Plus_Infinity &y, Rounding_Dir dir)
| Direct initialization from plus infinity and rounding mode.
| Checked_Number (const Not_A_Number &y, Rounding_Dir dir)
| Direct initialization from NAN and rounding mode.
template<typename From, typename From_Policy>
| Checked_Number (const Checked_Number< From, From_Policy > &y)
| Direct initialization from a Checked_Number, default rounding mode.
| Checked_Number (const signed char y)
| Direct initialization from a signed char, default rounding mode.
| Checked_Number (const signed short y)
| Direct initialization from a signed short, default rounding mode.
| Checked_Number (const signed int y)
| Direct initialization from a signed int, default rounding mode.
| Checked_Number (const signed long y)
| Direct initialization from a signed long, default rounding mode.
| Checked_Number (const signed long long y)
| Direct initialization from a signed long long, default rounding mode.
| Checked_Number (const unsigned char y)
| Direct initialization from an unsigned char, default rounding mode.
| Checked_Number (const unsigned short y)
| Direct initialization from an unsigned short, default rounding mode.
| Checked_Number (const unsigned int y)
| Direct initialization from an unsigned int, default rounding mode.
| Checked_Number (const unsigned long y)
| Direct initialization from an unsigned long, default rounding mode.
| Checked_Number (const unsigned long long y)
| Direct initialization from an unsigned long long, default rounding mode.
| Checked_Number (const float y)
| Direct initialization from a float, default rounding mode.
| Checked_Number (const double y)
| Direct initialization from a double, default rounding mode.
| Checked_Number (const long double y)
| Direct initialization from a long double, default rounding mode.
| Checked_Number (const mpq_class &y)
| Direct initialization from a rational, default rounding mode.
| Checked_Number (const mpz_class &y)
| Direct initialization from an unbounded integer, default rounding mode.
| Checked_Number (const char *y)
| Direct initialization from a C string, default rounding mode.
| Checked_Number (const Minus_Infinity &y)
| Direct initialization from minus infinity, default rounding mode.
| Checked_Number (const Plus_Infinity &y)
| Direct initialization from plus infinity, default rounding mode.
| Checked_Number (const Not_A_Number &y)
| Direct initialization from NAN, default rounding mode.
Accessors and Conversions
| operator T () const
| Conversion operator: returns a copy of the underlying numeric value.
T & | raw_value ()
| Returns a reference to the underlying numeric value.
const T & | raw_value () const
| Returns a const reference to the underlying numeric value.
Assignment Operators
Checked_Number & | operator= (const Checked_Number &y)
| Assignment operator.
template<typename From, typename From_Policy>
Checked_Number & | operator= (const Checked_Number< From, From_Policy > &y)
| Assignment operator.
template<typename From>
Checked_Number & | operator= (const From &y)
| Assignment operator.
Checked_Number & | operator= (const Not_A_Number &y)
| Assignment operator.
Checked_Number & | operator= (const Minus_Infinity &y)
| Assignment operator.
Checked_Number & | operator= (const Plus_Infinity &y)
| Assignment operator.
template<typename From_Policy>
Checked_Number & | operator+= (const Checked_Number< T, From_Policy > &y)
| Add and assign operator.
Checked_Number & | operator+= (const T &y)
| Add and assign operator.
template<typename From, typename From_Policy>
Checked_Number & | operator+= (const Checked_Number< From, From_Policy > &y)
| Add and assign operator.
template<typename From_Policy>
Checked_Number & | operator-= (const Checked_Number< T, From_Policy > &y)
| Subtract and assign operator.
Checked_Number & | operator-= (const T &y)
| Subtract and assign operator.
template<typename From, typename From_Policy>
Checked_Number & | operator-= (const Checked_Number< From, From_Policy > &y)
| Subtract and assign operator.
template<typename From>
Checked_Number & | operator-= (const From &y)
| Subtract and assign operator.
template<typename From_Policy>
Checked_Number & | operator *= (const Checked_Number< T, From_Policy > &y)
| Multiply and assign operator.
Checked_Number & | operator *= (const T &y)
| Multiply and assign operator.
template<typename From, typename From_Policy>
Checked_Number & | operator *= (const Checked_Number< From, From_Policy > &y)
| Multiply and assign operator.
template<typename From>
Checked_Number & | operator *= (const From &y)
| Multiply and assign operator.
template<typename From_Policy>
Checked_Number & | operator/= (const Checked_Number< T, From_Policy > &y)
| Divide and assign operator.
Checked_Number & | operator/= (const T &y)
| Divide and assign operator.
template<typename From, typename From_Policy>
Checked_Number & | operator/= (const Checked_Number< From, From_Policy > &y)
| Divide and assign operator.
template<typename From>
Checked_Number & | operator/= (const From &y)
| Divide and assign operator.
template<typename From_Policy>
Checked_Number & | operator%= (const Checked_Number< T, From_Policy > &y)
| Compute remainder and assign operator.
Checked_Number & | operator%= (const T &y)
| Compute remainder and assign operator.
template<typename From, typename From_Policy>
Checked_Number & | operator%= (const Checked_Number< From, From_Policy > &y)
| Compute remainder and assign operator.
template<typename From>
Checked_Number & | operator%= (const From &y)
| Compute remainder and assign operator.
Increment and Decrement Operators
Checked_Number & | operator++ ()
| Pre-increment operator.
Checked_Number | operator++ (int)
| Post-increment operator.
Checked_Number & | operator-- ()
| Pre-decrement operator.
Checked_Number | operator-- (int)
| Post-decrement operator.

## Related Functions

(Note that these are not member functions.)
void | swap (Checked_Number< T, Policy > &x, Checked_Number< T, Policy > &y)
| Swaps `*this` with `y`.
Accessor Functions
const T & | raw_value (const Checked_Number< T, Policy > &x)
| Returns a const reference to the underlying native integer value.
T & | raw_value (Checked_Number< T, Policy > &x)
| Returns a reference to the underlying native integer value.
Memory Size Inspection Functions
size_t | total_memory_in_bytes (const Checked_Number< T, Policy > &x)
| Returns the total size in bytes of the memory occupied by `x`.
size_t | external_memory_in_bytes (const Checked_Number< T, Policy > &x)
| Returns the size in bytes of the memory managed by `x`.
Arithmetic Operators
Checked_Number< T, Policy > | operator+ (const Checked_Number< T, Policy > &x)
| Unary plus operator.
Checked_Number< T, Policy > | operator- (const Checked_Number< T, Policy > &x)
| Unary minus operator.
void | neg_assign (Checked_Number< T, Policy > &x)
| Assigns to `x` its negation.
void | add_mul_assign (Checked_Number< T, Policy > &x, const Checked_Number< T, Policy > &y, const Checked_Number< T, Policy > &z)
| Assigns to `x` the value `x + y * z`.
void | sub_mul_assign (Checked_Number< T, Policy > &x, const Checked_Number< T, Policy > &y, const Checked_Number< T, Policy > &z)
| Assigns to `x` the value `x - y * z`.
void | gcd_assign (Checked_Number< T, Policy > &x, const Checked_Number< T, Policy > &y, const Checked_Number< T, Policy > &z)
| Assigns to `x` the greatest common divisor of `y` and `z`.
void | gcdext_assign (Checked_Number< T, Policy > &x, const Checked_Number< T, Policy > &y, const Checked_Number< T, Policy > &z, Checked_Number< T, Policy > &s, Checked_Number< T, Policy > &t)
| Assigns to `x` the greatest common divisor of `y` and `z`, setting `s` and `t` such that s*y + t*z = x = gcd(y, z).
void | lcm_assign (Checked_Number< T, Policy > &x, const Checked_Number< T, Policy > &y, const Checked_Number< T, Policy > &z)
| Assigns to `x` the least common multiple of `y` and `z`.
void | exact_div_assign (Checked_Number< T, Policy > &x, const Checked_Number< T, Policy > &y, const Checked_Number< T, Policy > &z)
| If `z` divides `y`, assigns to `x` the quotient of the integer division of `y` and `z`.
void | sqrt_assign (Checked_Number< T, Policy > &x, const Checked_Number< T, Policy > &y)
| Assigns to `x` the integer square root of `y`.
Relational Operators and Comparison Functions
bool | operator== (const Checked_Number< T1, Policy1 > &x, const Checked_Number< T2, Policy2 > &y)
| Equality operator.
bool | operator!= (const Checked_Number< T1, Policy1 > &x, const Checked_Number< T2, Policy2 > &y)
| Disequality operator.
bool | operator>= (const Checked_Number< T1, Policy1 > &x, const Checked_Number< T2, Policy2 > &y)
| Greater than or equal to operator.
bool | operator> (const Checked_Number< T1, Policy1 > &x, const Checked_Number< T2, Policy2 > &y)
| Greater than operator.
bool | operator<= (const Checked_Number< T1, Policy1 > &x, const Checked_Number< T2, Policy2 > &y)
| Less than or equal to operator.
bool | operator< (const Checked_Number< T1, Policy1 > &x, const Checked_Number< T2, Policy2 > &y)
| Less than operator.
int | sgn (const Checked_Number< T, Policy > &x)
| Returns , or depending on whether the value of `x` is negative, zero or positive, respectively.
int | cmp (const Checked_Number< T1, Policy1 > &x, const Checked_Number< T2, Policy2 > &y)
| Returns a negative, zero or positive value depending on whether `x` is lower than, equal to or greater than `y`, respectively.
Input-Output Operators
std::ostream & | operator<< (std::ostream &os, const Checked_Number< T, Policy > &x)
| Output operator.
Result | input (std::istream &is, Checked_Number< T, Policy > &x, Rounding_Dir dir)
| Input function.
std::istream & | operator>> (std::istream &is, Checked_Number< T, Policy > &x)
| Input operator.

## Detailed Description

### template<typename T, typename Policy>
class Parma_Polyhedra_Library::Checked_Number< T, Policy >

A wrapper for numeric types implementing a given policy.

The wrapper and related functions implement an interface which is common to all kinds of coefficient types, therefore allowing for a uniform coding style. This class also implements the policy encoded by the second template parameter. The default policy is to perform the detection of overflow errors.

## Member Function Documentation

template<typename T, typename Policy>

Result Parma_Polyhedra_Library::Checked_Number< T, Policy >::classify | ( | bool | nan = `true`,
|  | bool | inf = `true`,
|  | bool | sign = `true` |
| ) |  |  | const`[inline]`

Classifies *this.

Returns the appropriate Result characterizing:

- whether `*this` is NAN, if `nan` is `true`;
- whether `*this` is a (positive or negative) infinity, if `inf` is `true`;
- the sign of `*this`, if `sign` is `true`.

## Friends And Related Function Documentation

template<typename T, typename Policy>

void exact_div_assign | ( | Checked_Number< T, Policy > & | x,
|  | const Checked_Number< T, Policy > & | y,
|  | const Checked_Number< T, Policy > & | z |
| ) |  |  | `[related]`

If `z` divides `y`, assigns to `x` the quotient of the integer division of `y` and `z`.

The behavior is undefined if `z` does not divide `y`.

template<typename T, typename Policy>

Result input | ( | std::istream & | is,
|  | Checked_Number< T, Policy > & | x,
|  | Rounding_Dir | dir |
| ) |  |  | `[related]`

Input function.

Parameters:

  | is | Input stream to read from;
  | x | Number (possibly extended) to assign to in case of successful reading;
  | dir | Rounding mode to be applied.

Returns:
  Result of the input operation. Success, success with imprecision, overflow, parsing error: all possibilities are taken into account, checked for, and properly reported.

This function attempts reading a (possibly extended) number from the given stream `is`, possibly rounding as specified by `dir`, assigning the result to `x` upon success, and returning the appropriate Result.

The input syntax allows the specification of:

- plain base-10 integer numbers as `34976098`, `-77` and `+13`;
- base-10 integer numbers in scientific notation as `15e2` and `15*^2` (both meaning ), `9200e-2` and `-18*^+11111111111111111`;
- base-10 rational numbers in fraction notation as `15/3` and `15/-3`;
- base-10 rational numbers in fraction/scientific notation as `15/30e-1` (meaning ) and `15*^-3/29e2` (meaning );
- base-10 rational numbers in floating point notation as `71.3` (meaning ) and `-0.123456` (meaning );
- base-10 rational numbers in floating point scientific notation as `2.2e-1` (meaning ) and `-2.20001*^+3` (meaning );
- integers and rationals (in fractional, floating point and scientific notations) specified by using Mathematica-style bases, in the range from 2 to 36, as `2^^11` (meaning ), `36^^z` (meaning ), `36^^xyz` (meaning ), `2^^11.1` (meaning ), `10^^2e3` (meaning ), `8^^2e3` (meaning ), `8^^2.1e3` (meaning ), `8^^20402543.120347e7` (meaning ), `8^^2.1` (meaning ); note that the base and the exponent are always written as plain base-10 integer numbers; also, when an ambiguity may arise, the character `e` is interpreted as a digit, so that `16^^1e2` (meaning ) is different from `16^^1*^2` (meaning );
- the C-style hexadecimal prefix `0x` is interpreted as the Mathematica-style prefix `16^^`;
- special values like `inf` and `+inf` (meaning ), `-inf` (meaning ), and `nan` (meaning "not a number").

The rationale behind the accepted syntax can be summarized as follows:

- if the syntax is accepted by Mathematica, then this function accepts it with the same semantics;
- if the syntax is acceptable as standard C++ integer or floating point literal (except for octal notation and type suffixes, which are not supported), then this function accepts it with the same semantics;
- natural extensions of the above are accepted with the natural extensions of the semantics;
- special values are accepted.

Valid syntax is more formally and completely specified by the following grammar, with the additional provisos that everything is case insensitive, that the syntactic category `BDIGIT` is further restricted by the current base and that for all bases above 14, any `e` is always interpreted as a digit and never as a delimiter for the exponent part (if such a delimiter is desired, it has to be written as `*^`).

    number  : NAN                                   INF     : 'inf'
            | SIGN INF                                      ;
            | INF
            | num                                   NAN     : 'nan'
            | num DIV num                                   ;
            ;
                                                    SIGN    : '-'
    num     : unum                                          | '+'
            | SIGN unum                                     ;

    unum    : unum1                                 EXP     : 'e'
            | HEX unum1                                     | '*^'
            | base BASE unum1                               ;
            ;
                                                    POINT   : '.'
    unum1   : mantissa                                      ;
            | mantissa EXP exponent
            ;                                       DIV     : '/'
                                                            ;
    mantissa: bdigits
            | POINT bdigits                         MINUS   : '-'
            | bdigits POINT                                 ;
            | bdigits POINT bdigits
            ;                                       PLUS    : '+'
                                                    ;
    exponent: SIGN digits
            | digits                                HEX     : '0x'
            ;                                       ;

    bdigits : BDIGIT                                BASE    : '^^'
            | bdigits BDIGIT                                ;
            ;
                                                    DIGIT   : '0' .. '9'
    digits  : DIGIT                                         ;
            | digits DIGIT
            ;                                       BDIGIT  : '0' .. '9'
                                                            | 'a' .. 'z'
                                                            ;