[ VIGRA Homepage |
Class Index |
Function Index |
File Index |
Main Page ]
|
Rational Class Template Reference
|
 |
#include "vigra/rational.hxx"
template<typename IntType>
class vigra::Rational< IntType >
Template for rational numbers.
This template can make use of arbitrary integer types, including user-defined (e.g. infinite precision) ones. Note, however, that overflow in either the numerator or denominator is not detected during calculations -- the standard behavior of the integer type (e.g. wrap around) applies.
The class can represent and handle positive and negative infinity resulting from division by zero. Indeterminate expressions such as 0/0 are signaled by a bad_rational
exception which is derived from std::domain_error
.
Rational
implements the required interface of an AlgebraicField and the required numeric and promotion traits". All arithmetic and comparison operators, as well as the relevant algebraic functions are supported .
See also:
#include "vigra/rational.hxx"
Namespace: vigra
Member Typedef Documentation
typedef If<typename TypeTraits<IntType>::isBuiltinType, IntType, IntType const &>::type param_type
|
|
|
Determine whether arguments should be passed as IntType or IntType const & . |
typedef IntType value_type
|
|
|
The type of numerator and denominator |
Constructor & Destructor Documentation
|
Default constructor: creates zero (0/1 ) |
Rational |
( |
Rational< U > const & |
r |
) |
[inline] |
|
|
Integer constructor: creates n/1 |
|
Ratio constructor: creates n/d .
The ratio will be normalized unless doNormalize = false . Since the internal representation is assumed to be normalized, doNormalize = false must only be used as an optimization if n and d are known to be already normalized (i.e. have 1 as their greatest common divisor). |
Rational |
( |
double |
v, |
|
|
double |
epsilon = 1e-4 |
|
) |
[inline, explicit] |
|
|
Construct as an approximation of a real number.
The maximal allowed relative error is given by epsilon . |
Member Function Documentation
|
Assignment from IntType pair. |
bool is_inf |
( |
|
) |
const [inline] |
|
|
Check whether we have positive or negative infinity. |
bool is_ninf |
( |
|
) |
const [inline] |
|
|
Check whether we have negative infinity. |
bool is_pinf |
( |
|
) |
const [inline] |
|
|
Check whether we have positive infinity. |
Rational< IntType > & operator *= |
( |
param_type |
i |
) |
|
|
|
Multiply-assignment from IntType
throws bad_rational if indeterminate expression. |
Rational< IntType > & operator *= |
( |
const Rational< IntType > & |
r |
) |
|
|
|
Multiply-assignment from Rational
throws bad_rational if indeterminate expression. |
bool operator! |
( |
|
) |
const [inline] |
|
Rational operator++ |
( |
int |
|
) |
[inline] |
|
Rational< IntType > & operator++ |
( |
|
) |
[inline] |
|
Rational< IntType > & operator+= |
( |
param_type |
i |
) |
[inline] |
|
|
Add-assignment from IntType
throws bad_rational if indeterminate expression. |
Rational< IntType > & operator+= |
( |
const Rational< IntType > & |
r |
) |
|
|
|
Add-assignment from Rational
throws bad_rational if indeterminate expression. |
Rational operator-- |
( |
int |
|
) |
[inline] |
|
Rational< IntType > & operator-- |
( |
|
) |
[inline] |
|
Rational< IntType > & operator-= |
( |
param_type |
i |
) |
[inline] |
|
|
Subtract-assignment from IntType
throws bad_rational if indeterminate expression. |
Rational< IntType > & operator-= |
( |
const Rational< IntType > & |
r |
) |
|
|
|
Subtract-assignment from Rational
throws bad_rational if indeterminate expression. |
|
Divide-assignment from IntType
throws bad_rational if indeterminate expression. |
Rational< IntType > & operator/= |
( |
const Rational< IntType > & |
r |
) |
|
|
|
Divide-assignment from Rational
throws bad_rational if indeterminate expression. |
int sign |
( |
|
) |
const [inline] |
|
|
Check the sign.
Gives 1 if the number is positive, -1 if negative, and 0 otherwise. |
The documentation for this class was generated from the following file: