PPL
1.0
|
A wrapper for numeric types implementing a given policy. More...
#include <ppl.hh>
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 (char y, Rounding_Dir dir) | |
Direct initialization from a plain char and rounding mode. | |
Checked_Number (signed char y, Rounding_Dir dir) | |
Direct initialization from a signed char and rounding mode. | |
Checked_Number (signed short y, Rounding_Dir dir) | |
Direct initialization from a signed short and rounding mode. | |
Checked_Number (signed int y, Rounding_Dir dir) | |
Direct initialization from a signed int and rounding mode. | |
Checked_Number (signed long y, Rounding_Dir dir) | |
Direct initialization from a signed long and rounding mode. | |
Checked_Number (signed long long y, Rounding_Dir dir) | |
Direct initialization from a signed long long and rounding mode. | |
Checked_Number (unsigned char y, Rounding_Dir dir) | |
Direct initialization from an unsigned char and rounding mode. | |
Checked_Number (unsigned short y, Rounding_Dir dir) | |
Direct initialization from an unsigned short and rounding mode. | |
Checked_Number (unsigned int y, Rounding_Dir dir) | |
Direct initialization from an unsigned int and rounding mode. | |
Checked_Number (unsigned long y, Rounding_Dir dir) | |
Direct initialization from an unsigned long and rounding mode. | |
Checked_Number (unsigned long long y, Rounding_Dir dir) | |
Direct initialization from an unsigned long long and rounding mode. | |
Checked_Number (float y, Rounding_Dir dir) | |
Direct initialization from a float and rounding mode. | |
Checked_Number (double y, Rounding_Dir dir) | |
Direct initialization from a double and rounding mode. | |
Checked_Number (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. | |
template<typename From > | |
Checked_Number (const From &, Rounding_Dir dir, typename Enable_If< Is_Special< From >::value, bool >::type ignored=false) | |
Direct initialization from special 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 (char y) | |
Direct initialization from a plain char, default rounding mode. | |
Checked_Number (signed char y) | |
Direct initialization from a signed char, default rounding mode. | |
Checked_Number (signed short y) | |
Direct initialization from a signed short, default rounding mode. | |
Checked_Number (signed int y) | |
Direct initialization from a signed int, default rounding mode. | |
Checked_Number (signed long y) | |
Direct initialization from a signed long, default rounding mode. | |
Checked_Number (signed long long y) | |
Direct initialization from a signed long long, default rounding mode. | |
Checked_Number (unsigned char y) | |
Direct initialization from an unsigned char, default rounding mode. | |
Checked_Number (unsigned short y) | |
Direct initialization from an unsigned short, default rounding mode. | |
Checked_Number (unsigned int y) | |
Direct initialization from an unsigned int, default rounding mode. | |
Checked_Number (unsigned long y) | |
Direct initialization from an unsigned long, default rounding mode. | |
Checked_Number (unsigned long long y) | |
Direct initialization from an unsigned long long, default rounding mode. | |
Checked_Number (float y) | |
Direct initialization from a float, default rounding mode. | |
Checked_Number (double y) | |
Direct initialization from a double, default rounding mode. | |
Checked_Number (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. | |
template<typename From > | |
Checked_Number (const From &, typename Enable_If< Is_Special< From >::value, bool >::type ignored=false) | |
Direct initialization from special, 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 > | |
Checked_Number & | operator= (const From &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 > | |
Enable_If < Is_Native_Or_Checked< From > ::value, Checked_Number< T, Policy > & >::type | operator+= (const From &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 > | |
Enable_If < Is_Native_Or_Checked< From > ::value, Checked_Number< T, Policy > & >::type | 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 > | |
Enable_If < Is_Native_Or_Checked< From > ::value, Checked_Number< T, Policy > & >::type | 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 > | |
Enable_If < Is_Native_Or_Checked< From > ::value, Checked_Number< T, Policy > & >::type | 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 > | |
Enable_If < Is_Native_Or_Checked< From > ::value, Checked_Number< T, Policy > & >::type | 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.) | |
template<typename T > | |
Enable_If < Is_Native_Or_Checked< T > ::value, bool >::type | is_not_a_number (const T &x) |
template<typename T > | |
Enable_If < Is_Native_Or_Checked< T > ::value, bool >::type | is_minus_infinity (const T &x) |
template<typename T > | |
Enable_If < Is_Native_Or_Checked< T > ::value, bool >::type | is_plus_infinity (const T &x) |
template<typename T > | |
Enable_If < Is_Native_Or_Checked< T > ::value, int >::type | infinity_sign (const T &x) |
template<typename T > | |
Enable_If < Is_Native_Or_Checked< T > ::value, bool >::type | is_integer (const T &x) |
template<typename To , typename From > | |
Enable_If < Is_Native_Or_Checked< To > ::value &&Is_Special< From > ::value, Result >::type | construct (To &to, const From &x, Rounding_Dir dir) |
template<typename To , typename From > | |
Enable_If < Is_Native_Or_Checked< To > ::value &&Is_Special< From > ::value, Result >::type | assign_r (To &to, const From &x, Rounding_Dir dir) |
template<typename To > | |
Enable_If < Is_Native_Or_Checked< To > ::value, Result >::type | assign_r (To &to, const char *x, Rounding_Dir dir) |
template<typename To , typename To_Policy > | |
Enable_If < Is_Native_Or_Checked< To > ::value, Result >::type | assign_r (To &to, char *x, Rounding_Dir dir) |
template<typename T , typename Policy > | |
void | swap (Checked_Number< T, Policy > &x, Checked_Number< T, Policy > &y) |
Swaps x with y . | |
template<typename T , typename Policy > | |
const T & | raw_value (const Checked_Number< T, Policy > &x) |
template<typename T , typename Policy > | |
T & | raw_value (Checked_Number< T, Policy > &x) |
template<typename T , typename Policy > | |
memory_size_type | total_memory_in_bytes (const Checked_Number< T, Policy > &x) |
template<typename T , typename Policy > | |
memory_size_type | external_memory_in_bytes (const Checked_Number< T, Policy > &x) |
template<typename To > | |
Enable_If < Is_Native_Or_Checked< To > ::value, Result >::type | assign_r (To &to, const char *x, Rounding_Dir dir) |
template<typename T , typename Policy > | |
Checked_Number< T, Policy > | operator+ (const Checked_Number< T, Policy > &x) |
template<typename T , typename Policy > | |
Checked_Number< T, Policy > | operator- (const Checked_Number< T, Policy > &x) |
template<typename From > | |
Enable_If < Is_Native_Or_Checked< From > ::value, int >::type | sgn (const From &x) |
template<typename From1 , typename From2 > | |
Enable_If < Is_Native_Or_Checked< From1 > ::value &&Is_Native_Or_Checked < From2 >::value, int >::type | cmp (const From1 &x, const From2 &y) |
template<typename T > | |
Enable_If < Is_Native_Or_Checked< T > ::value, Result >::type | output (std::ostream &os, const T &x, const Numeric_Format &format, Rounding_Dir dir) |
template<typename T , typename Policy > | |
std::ostream & | operator<< (std::ostream &os, const Checked_Number< T, Policy > &x) |
template<typename T > | |
Enable_If < Is_Native_Or_Checked< T > ::value, Result >::type | input (T &x, std::istream &is, Rounding_Dir dir) |
template<typename T , typename Policy > | |
std::istream & | operator>> (std::istream &is, Checked_Number< T, Policy > &x) |
template<typename T , typename Policy > | |
void | swap (Checked_Number< T, Policy > &x, Checked_Number< T, Policy > &y) |
Memory Size Inspection Functions | |
template<typename T , typename Policy > | |
memory_size_type | 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 > | |
memory_size_type | 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 | floor_assign (Checked_Number< T, Policy > &x) |
Assigns to x largest integral value not greater than x . | |
template<typename T , typename Policy > | |
void | floor_assign (Checked_Number< T, Policy > &x, const Checked_Number< T, Policy > &y) |
Assigns to x largest integral value not greater than y . | |
template<typename T , typename Policy > | |
void | ceil_assign (Checked_Number< T, Policy > &x) |
Assigns to x smallest integral value not less than x . | |
template<typename T , typename Policy > | |
void | ceil_assign (Checked_Number< T, Policy > &x, const Checked_Number< T, Policy > &y) |
Assigns to x smallest integral value not less than y . | |
template<typename T , typename Policy > | |
void | trunc_assign (Checked_Number< T, Policy > &x) |
Round x to the nearest integer not larger in absolute value. | |
template<typename T , typename Policy > | |
void | trunc_assign (Checked_Number< T, Policy > &x, const Checked_Number< T, Policy > &y) |
Assigns to x the value of y rounded to the nearest integer not larger in absolute value. | |
template<typename T , typename Policy > | |
void | neg_assign (Checked_Number< T, Policy > &x) |
Assigns to x its negation. | |
template<typename T , typename Policy > | |
void | neg_assign (Checked_Number< T, Policy > &x, const Checked_Number< T, Policy > &y) |
Assigns to x the negation of y . | |
template<typename T , typename Policy > | |
void | abs_assign (Checked_Number< T, Policy > &x) |
Assigns to x its absolute value. | |
template<typename T , typename Policy > | |
void | abs_assign (Checked_Number< T, Policy > &x, const Checked_Number< T, Policy > &y) |
Assigns to x the absolute value of y . | |
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, Checked_Number< T, Policy > &s, Checked_Number< T, Policy > &t, const Checked_Number< T, Policy > &y, const Checked_Number< T, Policy > &z) |
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 | mul_2exp_assign (Checked_Number< T, Policy > &x, const Checked_Number< T, Policy > &y, unsigned int exp) |
Assigns to x the value ![]() | |
template<typename T , typename Policy > | |
void | div_2exp_assign (Checked_Number< T, Policy > &x, const Checked_Number< T, Policy > &y, unsigned int exp) |
Assigns to x the value ![]() | |
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 T2 > | |
Enable_If < Is_Native_Or_Checked< T1 > ::value &&Is_Native_Or_Checked < T2 >::value &&(Is_Checked < T1 >::value||Is_Checked< T2 > ::value), bool >::type | operator== (const T1 &x, const T2 &y) |
Equality operator. | |
template<typename T1 , typename T2 > | |
Enable_If < Is_Native_Or_Checked< T1 > ::value &&Is_Native_Or_Checked < T2 >::value, bool >::type | equal (const T1 &x, const T2 &y) |
template<typename T1 , typename T2 > | |
Enable_If < Is_Native_Or_Checked< T1 > ::value &&Is_Native_Or_Checked < T2 >::value &&(Is_Checked < T1 >::value||Is_Checked< T2 > ::value), bool >::type | operator!= (const T1 &x, const T2 &y) |
Disequality operator. | |
template<typename T1 , typename T2 > | |
Enable_If < Is_Native_Or_Checked< T1 > ::value &&Is_Native_Or_Checked < T2 >::value, bool >::type | not_equal (const T1 &x, const T2 &y) |
template<typename T1 , typename T2 > | |
Enable_If < Is_Native_Or_Checked< T1 > ::value &&Is_Native_Or_Checked < T2 >::value &&(Is_Checked < T1 >::value||Is_Checked< T2 > ::value), bool >::type | operator>= (const T1 &x, const T2 &y) |
Greater than or equal to operator. | |
template<typename T1 , typename T2 > | |
Enable_If < Is_Native_Or_Checked< T1 > ::value &&Is_Native_Or_Checked < T2 >::value, bool >::type | greater_or_equal (const T1 &x, const T2 &y) |
template<typename T1 , typename T2 > | |
Enable_If < Is_Native_Or_Checked< T1 > ::value &&Is_Native_Or_Checked < T2 >::value &&(Is_Checked < T1 >::value||Is_Checked< T2 > ::value), bool >::type | operator> (const T1 &x, const T2 &y) |
Greater than operator. | |
template<typename T1 , typename T2 > | |
Enable_If < Is_Native_Or_Checked< T1 > ::value &&Is_Native_Or_Checked < T2 >::value, bool >::type | greater_than (const T1 &x, const T2 &y) |
template<typename T1 , typename T2 > | |
Enable_If < Is_Native_Or_Checked< T1 > ::value &&Is_Native_Or_Checked < T2 >::value &&(Is_Checked < T1 >::value||Is_Checked< T2 > ::value), bool >::type | operator<= (const T1 &x, const T2 &y) |
Less than or equal to operator. | |
template<typename T1 , typename T2 > | |
Enable_If < Is_Native_Or_Checked< T1 > ::value &&Is_Native_Or_Checked < T2 >::value, bool >::type | less_or_equal (const T1 &x, const T2 &y) |
template<typename T1 , typename T2 > | |
Enable_If < Is_Native_Or_Checked< T1 > ::value &&Is_Native_Or_Checked < T2 >::value &&(Is_Checked < T1 >::value||Is_Checked< T2 > ::value), bool >::type | operator< (const T1 &x, const T2 &y) |
Less than operator. | |
template<typename T1 , typename T2 > | |
Enable_If < Is_Native_Or_Checked< T1 > ::value &&Is_Native_Or_Checked < T2 >::value, bool >::type | less_than (const T1 &x, const T2 &y) |
template<typename From > | |
Enable_If < Is_Native_Or_Checked< From > ::value, int >::type | sgn (const From &x) |
Returns ![]() ![]() ![]() x is negative, zero or positive, respectively. | |
template<typename From1 , typename From2 > | |
Enable_If < Is_Native_Or_Checked< From1 > ::value &&Is_Native_Or_Checked < From2 >::value, int >::type | cmp (const From1 &x, const From2 &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 > | |
Enable_If < Is_Native_Or_Checked< T > ::value, Result >::type | output (std::ostream &os, const T &x, const Numeric_Format &format, 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 > | |
Enable_If < Is_Native_Or_Checked< T > ::value, void >::type | ascii_dump (std::ostream &s, const T &t) |
Ascii dump for native or checked. | |
template<typename T > | |
Enable_If < Is_Native_Or_Checked< T > ::value, Result >::type | input (T &x, std::istream &is, Rounding_Dir dir) |
Input function. | |
template<typename T , typename Policy > | |
std::istream & | operator>> (std::istream &is, Checked_Number< T, Policy > &x) |
Input operator. | |
template<typename T > | |
Enable_If < Is_Native_Or_Checked< T > ::value, bool >::type | ascii_load (std::ostream &s, T &t) |
Ascii load for native or checked. |
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.
|
inline |
Classifies *this.
Returns the appropriate Result characterizing:
*this
is NaN, if nan
is true
;*this
is a (positive or negative) infinity, if inf
is true
;*this
, if sign
is true
.
|
related |
|
related |
|
related |
|
related |
|
related |
|
related |
|
related |
|
related |
|
related |
|
related |
Returns the total size in bytes of the memory occupied by x
.
|
related |
Returns the size in bytes of the memory managed by x
.
|
related |
Unary plus operator.
|
related |
Unary minus operator.
|
related |
Assigns to x
largest integral value not greater than x
.
|
related |
Assigns to x
largest integral value not greater than y
.
|
related |
Assigns to x
smallest integral value not less than x
.
|
related |
Assigns to x
smallest integral value not less than y
.
|
related |
Round x
to the nearest integer not larger in absolute value.
|
related |
Assigns to x
the value of y
rounded to the nearest integer not larger in absolute value.
|
related |
Assigns to x
its negation.
|
related |
Assigns to x
the negation of y
.
|
related |
Assigns to x
its absolute value.
|
related |
Assigns to x
the absolute value of y
.
|
related |
Assigns to x
the value x + y * z
.
|
related |
Assigns to x
the value x - y * z
.
|
related |
Assigns to x
the greatest common divisor of y
and z
.
|
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).
|
related |
Assigns to x
the least common multiple of y
and z
.
|
related |
Assigns to x
the value .
|
related |
Assigns to x
the value .
|
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
.
|
related |
Assigns to x
the integer square root of y
.
|
related |
Equality operator.
|
related |
|
related |
Disequality operator.
|
related |
|
related |
Greater than or equal to operator.
|
related |
|
related |
Greater than operator.
|
related |
|
related |
Less than or equal to operator.
|
related |
|
related |
Less than operator.
|
related |
|
related |
|
related |
Output operator.
|
related |
Ascii dump for native or checked.
|
related |
Input function.
is | Input stream to read from; |
x | Number (possibly extended) to assign to in case of successful reading; |
dir | Rounding mode to be applied. |
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:
34976098
, -77
and +13
;15e2
and 15*^2
(both meaning 9200e-2
and -18*^+11111111111111111
;15/3
and 15/-3
;15/30e-1
(meaning 15*^-3/29e2
(meaning 71.3
(meaning -0.123456
(meaning 2.2e-1
(meaning -2.20001*^+3
(meaning 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 e
is interpreted as a digit, so that 16^^1e2
(meaning 16^^1*^2
(meaning 0x
is interpreted as the Mathematica-style prefix 16^^
;p
can only be used when base 16 has been specified; if used, the exponent will be applied to base 2 (instead of base 16, as is the case when the indicator e
is used);inf
and +inf
(meaning -inf
(meaning nan
(meaning "not a number").The rationale behind the accepted syntax can be summarized as follows:
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 *^
).
|
related |
Input operator.
|
related |
Ascii load for native or checked.
|
related |
Swaps x
with y
.
|
related |
|
related |
|
related |
|
related |
|
related |
|
related |
|
related |
|
related |
|
related |
|
related |
|
related |
|
related |
|
related |
|
related |