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_Numberoperator= (const Checked_Number &y)
 Assignment operator.
template<typename From, typename From_Policy>
Checked_Numberoperator= (const Checked_Number< From, From_Policy > &y)
 Assignment operator.
template<typename From>
Checked_Numberoperator= (const From &y)
 Assignment operator.
Checked_Numberoperator= (const Not_A_Number &y)
 Assignment operator.
Checked_Numberoperator= (const Minus_Infinity &y)
 Assignment operator.
Checked_Numberoperator= (const Plus_Infinity &y)
 Assignment operator.
template<typename From_Policy>
Checked_Numberoperator+= (const Checked_Number< T, From_Policy > &y)
 Add and assign operator.
Checked_Numberoperator+= (const T &y)
 Add and assign operator.
template<typename From, typename From_Policy>
Checked_Numberoperator+= (const Checked_Number< From, From_Policy > &y)
 Add and assign operator.
template<typename From>
Checked_Numberoperator+= (const From &y)
template<typename From_Policy>
Checked_Numberoperator-= (const Checked_Number< T, From_Policy > &y)
 Subtract and assign operator.
Checked_Numberoperator-= (const T &y)
 Subtract and assign operator.
template<typename From, typename From_Policy>
Checked_Numberoperator-= (const Checked_Number< From, From_Policy > &y)
 Subtract and assign operator.
template<typename From>
Checked_Numberoperator-= (const From &y)
 Subtract and assign operator.
template<typename From_Policy>
Checked_Numberoperator*= (const Checked_Number< T, From_Policy > &y)
 Multiply and assign operator.
Checked_Numberoperator*= (const T &y)
 Multiply and assign operator.
template<typename From, typename From_Policy>
Checked_Numberoperator*= (const Checked_Number< From, From_Policy > &y)
 Multiply and assign operator.
template<typename From>
Checked_Numberoperator*= (const From &y)
 Multiply and assign operator.
template<typename From_Policy>
Checked_Numberoperator/= (const Checked_Number< T, From_Policy > &y)
 Divide and assign operator.
Checked_Numberoperator/= (const T &y)
 Divide and assign operator.
template<typename From, typename From_Policy>
Checked_Numberoperator/= (const Checked_Number< From, From_Policy > &y)
 Divide and assign operator.
template<typename From>
Checked_Numberoperator/= (const From &y)
 Divide and assign operator.
template<typename From_Policy>
Checked_Numberoperator%= (const Checked_Number< T, From_Policy > &y)
 Compute remainder and assign operator.
Checked_Numberoperator%= (const T &y)
 Compute remainder and assign operator.
template<typename From, typename From_Policy>
Checked_Numberoperator%= (const Checked_Number< From, From_Policy > &y)
 Compute remainder and assign operator.
template<typename From>
Checked_Numberoperator%= (const From &y)
 Compute remainder and assign operator.
Increment and Decrement Operators
Checked_Numberoperator++ ()
 Pre-increment operator.
Checked_Number operator++ (int)
 Post-increment operator.
Checked_Numberoperator-- ()
 Pre-decrement operator.
Checked_Number operator-- (int)
 Post-decrement operator.

Related Functions

(Note that these are not member functions.)

template<typename T, typename Policy>
void swap (Checked_Number< T, Policy > &x, Checked_Number< T, Policy > &y)
 Swaps *this with y.
template<typename T, typename Policy>
Result input (Checked_Number< T, Policy > &x, std::istream &is, Rounding_Dir dir)
Accessor Functions
template<typename T, typename Policy>
const T & raw_value (const Checked_Number< T, Policy > &x)
 Returns a const reference to the underlying native integer value.
template<typename T, typename Policy>
T & raw_value (Checked_Number< T, Policy > &x)
 Returns a reference to the underlying native integer value.
Memory Size Inspection Functions
template<typename T, typename Policy>
size_t total_memory_in_bytes (const Checked_Number< T, Policy > &x)
 Returns the total size in bytes of the memory occupied by x.
template<typename T, typename Policy>
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
template<typename T, typename Policy>
Checked_Number< T, Policy > operator+ (const Checked_Number< T, Policy > &x)
 Unary plus operator.
template<typename T, typename Policy>
Checked_Number< T, Policy > operator- (const Checked_Number< T, Policy > &x)
 Unary minus operator.
template<typename T, typename Policy>
void neg_assign (Checked_Number< T, Policy > &x)
 Assigns to x its negation.
template<typename T, typename Policy>
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.
template<typename T, typename Policy>
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.
template<typename T, typename Policy>
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.
template<typename T, typename Policy>
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).
template<typename T, typename Policy>
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.
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)
 If z divides y, assigns to x the quotient of the integer division of y and z.
template<typename T, typename Policy>
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
template<typename T1, typename Policy1, typename T2, typename Policy2>
bool operator== (const Checked_Number< T1, Policy1 > &x, const Checked_Number< T2, Policy2 > &y)
 Equality operator.
template<typename T1, typename Policy1, typename T2, typename Policy2>
bool operator!= (const Checked_Number< T1, Policy1 > &x, const Checked_Number< T2, Policy2 > &y)
 Disequality operator.
template<typename T1, typename Policy1, typename T2, typename Policy2>
bool operator>= (const Checked_Number< T1, Policy1 > &x, const Checked_Number< T2, Policy2 > &y)
 Greater than or equal to operator.
template<typename T1, typename Policy1, typename T2, typename Policy2>
bool operator> (const Checked_Number< T1, Policy1 > &x, const Checked_Number< T2, Policy2 > &y)
 Greater than operator.
template<typename T1, typename Policy1, typename T2, typename Policy2>
bool operator<= (const Checked_Number< T1, Policy1 > &x, const Checked_Number< T2, Policy2 > &y)
 Less than or equal to operator.
template<typename T1, typename Policy1, typename T2, typename Policy2>
bool operator< (const Checked_Number< T1, Policy1 > &x, const Checked_Number< T2, Policy2 > &y)
 Less than operator.
template<typename T, typename Policy>
int sgn (const Checked_Number< T, Policy > &x)
 Returns $-1$, $0$ or $1$ depending on whether the value of x is negative, zero or positive, respectively.
template<typename T1, typename Policy1, typename T2, typename Policy2>
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
template<typename T, typename Policy>
Result output (std::ostream &os, const Checked_Number< T, Policy > &x, const Numeric_Format &fmt, Rounding_Dir dir)
template<typename T, typename Policy>
std::ostream & operator<< (std::ostream &os, const Checked_Number< T, Policy > &x)
 Output operator.
template<typename T, typename Policy>
Result input (std::istream &is, Checked_Number< T, Policy > &x, Rounding_Dir dir)
 Input function.
template<typename T, typename Policy>
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 swap ( Checked_Number< T, Policy > &  x,
Checked_Number< T, Policy > &  y 
) [related]

Swaps *this with y.

template<typename T, typename Policy>
const T & raw_value ( const Checked_Number< T, Policy > &  x  )  [related]

Returns a const reference to the underlying native integer value.

template<typename T, typename Policy>
T & raw_value ( Checked_Number< T, Policy > &  x  )  [related]

Returns a reference to the underlying native integer value.

template<typename T, typename Policy>
memory_size_type total_memory_in_bytes ( const Checked_Number< T, Policy > &  x  )  [related]

Returns the total size in bytes of the memory occupied by x.

template<typename T, typename Policy>
memory_size_type external_memory_in_bytes ( const Checked_Number< T, Policy > &  x  )  [related]

Returns the size in bytes of the memory managed by x.

template<typename T, typename Policy>
Checked_Number< T, Policy > operator+ ( const Checked_Number< T, Policy > &  x  )  [related]

Unary plus operator.

template<typename T, typename Policy>
Checked_Number< T, Policy > operator- ( const Checked_Number< T, Policy > &  x  )  [related]

Unary minus operator.

template<typename T, typename Policy>
void neg_assign ( Checked_Number< T, Policy > &  x  )  [related]

Assigns to x its negation.

template<typename T, typename Policy>
void add_mul_assign ( Checked_Number< T, Policy > &  x,
const Checked_Number< T, Policy > &  y,
const Checked_Number< T, Policy > &  z 
) [related]

Assigns to x the value x + y * z.

template<typename T, typename Policy>
void sub_mul_assign ( Checked_Number< T, Policy > &  x,
const Checked_Number< T, Policy > &  y,
const Checked_Number< T, Policy > &  z 
) [related]

Assigns to x the value x - y * z.

template<typename T, typename Policy>
void gcd_assign ( Checked_Number< T, Policy > &  x,
const Checked_Number< T, Policy > &  y,
const Checked_Number< T, Policy > &  z 
) [related]

Assigns to x the greatest common divisor of y and z.

template<typename T, typename Policy>
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 
) [related]

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).

template<typename T, typename Policy>
void lcm_assign ( Checked_Number< T, Policy > &  x,
const Checked_Number< T, Policy > &  y,
const Checked_Number< T, Policy > &  z 
) [related]

Assigns to x the least common multiple of y and z.

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>
void sqrt_assign ( Checked_Number< T, Policy > &  x,
const Checked_Number< T, Policy > &  y 
) [related]

Assigns to x the integer square root of y.

template<typename T1, typename Policy1, typename T2, typename Policy2>
bool operator== ( const Checked_Number< T1, Policy1 > &  x,
const Checked_Number< T2, Policy2 > &  y 
) [related]

Equality operator.

template<typename T1, typename Policy1, typename T2, typename Policy2>
bool operator!= ( const Checked_Number< T1, Policy1 > &  x,
const Checked_Number< T2, Policy2 > &  y 
) [related]

Disequality operator.

template<typename T1, typename Policy1, typename T2, typename Policy2>
bool operator>= ( const Checked_Number< T1, Policy1 > &  x,
const Checked_Number< T2, Policy2 > &  y 
) [related]

Greater than or equal to operator.

template<typename T1, typename Policy1, typename T2, typename Policy2>
bool operator> ( const Checked_Number< T1, Policy1 > &  x,
const Checked_Number< T2, Policy2 > &  y 
) [related]

Greater than operator.

template<typename T1, typename Policy1, typename T2, typename Policy2>
bool operator<= ( const Checked_Number< T1, Policy1 > &  x,
const Checked_Number< T2, Policy2 > &  y 
) [related]

Less than or equal to operator.

template<typename T1, typename Policy1, typename T2, typename Policy2>
bool operator< ( const Checked_Number< T1, Policy1 > &  x,
const Checked_Number< T2, Policy2 > &  y 
) [related]

Less than operator.

template<typename T, typename Policy>
int sgn ( const Checked_Number< T, Policy > &  x  )  [related]

Returns $-1$, $0$ or $1$ depending on whether the value of x is negative, zero or positive, respectively.

template<typename T1, typename Policy1, typename T2, typename Policy2>
int cmp ( const Checked_Number< T1, Policy1 > &  x,
const Checked_Number< T2, Policy2 > &  y 
) [related]

Returns a negative, zero or positive value depending on whether x is lower than, equal to or greater than y, respectively.

template<typename T, typename Policy>
Result output ( std::ostream &  os,
const Checked_Number< T, Policy > &  x,
const Numeric_Format &  fmt,
Rounding_Dir  dir 
) [related]

template<typename T, typename Policy>
std::ostream & operator<< ( std::ostream &  os,
const Checked_Number< T, Policy > &  x 
) [related]

Output operator.

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 $15 \cdot 10^2 = 1500$), 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 $5$) and 15*^-3/29e2 (meaning $3/580000$);
  • base-10 rational numbers in floating point notation as 71.3 (meaning $713/10$) and -0.123456 (meaning $-1929/15625$);
  • base-10 rational numbers in floating point scientific notation as 2.2e-1 (meaning $11/50$) and -2.20001*^+3 (meaning $-220001/100$);
  • 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 $3$), 36^^z (meaning $35$), 36^^xyz (meaning $44027$), 2^^11.1 (meaning $7/2$), 10^^2e3 (meaning $2000$), 8^^2e3 (meaning $1024$), 8^^2.1e3 (meaning $1088$), 8^^20402543.120347e7 (meaning $9073863231288$), 8^^2.1 (meaning $17/8$); 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 $482$) is different from 16^^1*^2 (meaning $256$);
  • the C-style hexadecimal prefix 0x is interpreted as the Mathematica-style prefix 16^^;
  • special values like inf and +inf (meaning $+\infty$), -inf (meaning $-\infty$), 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'
                                                        ;

template<typename T, typename Policy>
std::istream & operator>> ( std::istream &  is,
Checked_Number< T, Policy > &  x 
) [related]

Input operator.

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


Generated on Wed Jul 16 22:51:11 2008 for PPL by  doxygen 1.5.6