CGAL 4.7 - Number Types: CGAL::Quotient< NT > Class Template Reference

\( \newcommand{\E}{\mathrm{E}} \) \( \newcommand{\A}{\mathrm{A}} \) \( \newcommand{\R}{\mathrm{R}} \) \( \newcommand{\N}{\mathrm{N}} \) \( \newcommand{\Q}{\mathrm{Q}} \) \( \newcommand{\Z}{\mathrm{Z}} \) \( \def\ccSum #1#2#3{ \sum_{#1}^{#2}{#3} } \def\ccProd #1#2#3{ \sum_{#1}^{#2}{#3} }\)

CGAL 4.7 - Number Types

All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Groups Pages
List of all members | Related Functions
CGAL::Quotient< NT > Class Template Reference
CGAL Number Types

`#include <CGAL/Quotient.h>`

## Definition

An object of the class `Quotient<NT>` is an element of the field of quotients of the integral domain type `NT`.

If `NT` behaves like an integer, `Quotient<NT>` behaves like a rational number. LEDA's class `rational` (see Section ledant) has been the basis for `Quotient<NT>`. A `Quotient<NT>` `q` is represented as a pair of `NT`s, representing numerator and denominator.

Template Parameters

  NT | must be at least model of concept `IntegralDomainWithoutDivision` and a model of concept `RealEmbeddable`.

Is Model Of:

  `Field`

  `RealEmbeddable`

  `Fraction`

Operations

There are two access functions, namely to the numerator and the denominator of a quotient. Note that these values are not uniquely defined. It is guaranteed that `q.numerator()` and `q.denominator()` return values `nt_num` and `nt_den` such that `q = nt_num/nt_den`, only if `q.numerator()` and `q.denominator()` are called consecutively wrt `q`, i.e. `q` is not involved in any other operation between these calls.

The stream operations are available as well. They assume that corresponding stream operators for type `NT` exist.

The following functions are added to fulfill the CGAL requirements on number types.

## Related Functions

(Note that these are not member functions.)
std::ostream & | operator<< (std::ostream &out, const Quotient< NT > &q)
| writes `q` to ostream `out` in format `n/d`, where `n` \( ==\)`q.numerator()` and `d` \( ==\)`q.denominator()`.
std::istream & | operator>> (std::istream &in, Quotient< NT > &q)
| reads `q` from istream `in`. More...
double | to_double (const Quotient< NT > &q)
| returns some double approximation to `q`.
bool | is_valid (const Quotient< NT > &q)
| returns true, if numerator and denominator are valid.
bool | is_finite (const Quotient< NT > &q)
| returns true, if numerator and denominator are finite.
Quotient< NT > | sqrt (const Quotient< NT > &q)
| returns the square root of `q`. More...

## Creation

| Quotient ()
| introduces an uninitialized variable `q`.
template<class T >
| Quotient (const T &t)
| introduces the quotient `t/1`. More...
template<class T >
| Quotient (const Quotient< T > &t)
| introduces the quotient `NT(t.numerator())/NT(t.denominator())`. More...
| Quotient (const NT &n, const NT &d)
| introduces the quotient `n/d`. More...

## Operations

NT | numerator () const
| returns a numerator of `q`.
NT | denominator () const
| returns a denominator of `q`.

## Constructor & Destructor Documentation

template<typename NT >
template<class T >

CGAL::Quotient< NT >::Quotient | ( | const T & | t) |  |

introduces the quotient `t/1`.

NT needs to have a constructor from T.

template<typename NT >
template<class T >

CGAL::Quotient< NT >::Quotient | ( | const Quotient< T > & | t) |  |

introduces the quotient `NT(t.numerator())/NT(t.denominator())`.

NT needs to have a constructor from T.

template<typename NT >

CGAL::Quotient< NT >::Quotient | ( | const NT & | n,
|  | const NT & | d
| ) |  |

introduces the quotient `n/d`.

Precondition
  \( d \neq0\).

## Friends And Related Function Documentation

template<typename NT >

std::istream & operator>> | ( | std::istream & | in,
|  | Quotient< NT > & | q
| ) |  |

related

reads `q` from istream `in`.

Expected format is `n/d`, where `n` and `d` are of type `NT`. A single `n` which is not followed by a `/` is also accepted and interpreted as `n/1`.

template<typename NT >

Quotient< NT > sqrt | ( | const Quotient< NT > & | q) |  |

related

returns the square root of `q`.

This is supported if and only if `NT` supports the square root as well.