Navigation: Up, Table of Contents, Bibliography, Index, Title Page

Quotient (CGAL_Quotient)

Definition

An object of the class CGAL_Quotient<NT> is an element of the ring of quotients of the integral domain type NT. If NT behaves like an integer, CGAL_Quotient<NT> behaves like the rational numbers. LEDA's class rational (see Section reference arrow) has been the basis for CGAL_Quotient<NT>. A CGAL_Quotient<NT> q is represented as a pair of NTs, representing numerator and denominator.

#include <CGAL/Quotient.h>

Creation

CGAL_Quotient<NT> q;
introduces an uninitialized variable q.

CGAL_Quotient<NT> q ( int i);
introduces the quotient i/1.

CGAL_Quotient<NT> q ( NT n);
introduces the quotient n/1.

CGAL_Quotient<NT> q ( NT n, NT d);
introduces the quotient n/d.

Operations

The arithmetic operations +, -, *, /, +=, -=, *=, /=, -(unary), and the comparison operations < and == are all available. If CGAL_PROVIDE_STL_PROVIDED_REL_OPS is defined, the comparison operations <=, >, >=, != are provided, too.

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.

NT q.numerator () returns a numerator of q.
NT q.denominator () returns a denominator of q.

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

ostream& ostream& out << q writes q to ostream out in format ``n/d'', where n==q.numerator() and d ==q.denominator().
istream& istream& in >> & q
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.

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

double CGAL_to_double ( q)
returns some double approximation to q.
bool CGAL_is_valid ( q)
returns true, if numerator and denominator are valid.
bool CGAL_is_finite ( q)
returns true, if numerator and denominator are finite.


Next: Class declaration of CGAL_Fixed_precision_nt
Navigation: Up, Table of Contents, Bibliography, Index, Title Page
The CGAL Project. 22 January 1999.