[ VIGRA Homepage | Function Index | Class Index | Namespaces | File List | Main Page ]

| Rational |

`#include <vigra/rational.hxx>`

List of all members.

## Public Types

typedef If< typename TypeTraits< IntType > ::isBuiltinType, IntType, IntType const & >::type | param_type
typedef IntType | value_type

## Public Member Functions

Rational & | assign (param_type n, param_type d, bool doNormalize=true)
param_type | denominator () const
bool | is_inf () const
bool | is_ninf () const
bool | is_pinf () const
param_type | numerator () const
bool | operator! () const
Rational & | operator*= (param_type i)
Rational & | operator*= (const Rational &r)
Rational | operator++ (int)
Rational & | operator++ ()
Rational & | operator+= (param_type i)
Rational & | operator+= (const Rational &r)
Rational | operator-- (int)
Rational & | operator-- ()
Rational & | operator-= (param_type i)
Rational & | operator-= (const Rational &r)
Rational & | operator/= (param_type i)
Rational & | operator/= (const Rational &r)
Rational & | operator= (param_type n)
| Rational (double v, double epsilon=1e-4)
| Rational (param_type n, param_type d, bool doNormalize=true)
| Rational (param_type n)
template<class U>
| Rational (Rational< U > const &r)
| Rational ()
int | sign () const

## Detailed Description

### 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:

- Numeric and Promote Traits of Rational
- Functions for Rational

#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

Rational | ( |  | ) |

Default constructor: creates zero (`0/1`)

template<class U>
Rational | ( | Rational< U > const & | r | ) |

Copy constructor

Rational | ( | param_type | n | ) |

Integer constructor: creates `n/1`

Rational | ( | param_type | n,
|  | param_type | d,
|  | bool | doNormalize = `true` |
| ) |  |  |

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` |
| ) |  |  | `[explicit]`

Construct as an approximation of a real number.

The maximal allowed relative error is given by `epsilon`.

## Member Function Documentation

Rational< IntType > & assign | ( | param_type | n,
|  | param_type | d,
|  | bool | doNormalize = `true` |
| ) |  |  |

Assignment from `IntType` pair.

param_type denominator | ( |  | ) | const

Access denominator.

bool is_inf | ( |  | ) | const

Check whether we have positive or negative infinity.

bool is_ninf | ( |  | ) | const

Check whether we have negative infinity.

bool is_pinf | ( |  | ) | const

Check whether we have positive infinity.

param_type numerator | ( |  | ) | const

Access numerator.

bool operator! | ( |  | ) | const

Check for zero by calling `!numerator()`

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.

Rational operator++ | ( | int |  | ) |

Post-increment.

Rational< IntType > & operator++ | ( |  | ) |

Pre-increment.

Rational< IntType > & operator+= | ( | param_type | i | ) |

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

Post-decrement.

Rational< IntType > & operator-- | ( |  | ) |

Pre-decrement.

Rational< IntType > & operator-= | ( | param_type | i | ) |

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.

Rational< IntType > & operator/= | ( | param_type | i | ) |

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.

Rational& operator= | ( | param_type | n | ) |

Assignment from `IntType`.

int sign | ( |  | ) | const

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:

- vigra/rational.hxx

© Ullrich Köthe (ullrich.koethe@iwr.uni-heidelberg.de) Heidelberg Collaboratory for Image Processing, University of Heidelberg, Germany | html generated using doxygen and Python VIGRA 1.6.0 (13 Aug 2008)