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

Creation

NT ntvar;
Declaration of a variable.

NT ntvar ( ntval);
Declaration and initialization.

NT ntvar ( i);
Declaration and initialization with a small integer constant i, 0 <=i <=127. The neutral elements for addition (zero) and multiplication (one) are needed quite often, but sometimes other small constants are useful too. The value 127 was chosen such that even signed 8 bit number types can fulfill this condition.

Operations

NT & ntvar = ntval Assignment.
bool CGAL_is_valid ( ntval)
Not all values of a number type need be valid. The routine CGAL_is_valid checks this. For example, an expression like nt(0)/nt(0) can result in an invalid number. Routines often have as a precondition that all numerical values are valid.
bool CGAL_is_finite ( ntval)
When two large doubles are multiplied, the result may not fit in a NT. Some number types (the standard float and double type when they conform to standards) have a way to represent a too big value as infinity. CGAL_is_finite implies CGAL_is_valid.
bool ntvar == n
bool ntvar != n
bool ntvar < n
bool ntvar > n
bool ntvar <= n
bool ntvar >= n
NT ntval1 + ntval2
NT ntval1 - ntval2
NT ntval1 * ntval2
NT - ntval
NT ntvar += n
NT ntvar -= n
NT ntvar *= n
NT ntvar /= n
double CGAL_to_double ( ntval)
gives the double value for a number type. This is usually an approximation for the real (stored) value. It can be used to send numbers to a renderer or to store them in a file.
NT ntval1 / ntval2 Division by zero need not be defined. It may result in a runtime error, an invalid value, a valid value or anything else. This basically means that the library tests for zero whenever it does a division.

Utility Routines

The previous section listed all the required functionality. For the user of a number type it is handy to have a larger set of operations available.

Utility Functions

#include <CGAL/number_utils.h>

NT CGAL_min ( ntval1, ntval2)
returns the smaller of the two values.
NT CGAL_max ( ntval1, ntval2)
returns the larger of the two values.
NT CGAL_abs ( ntval) returns the absolute value.
int CGAL_sign ( ntval)
returns the sign: -1, 0, or +1.
bool CGAL_is_negative ( ntval)
bool CGAL_is_positive ( ntval)
bool CGAL_is_zero ( ntval)
bool CGAL_is_one ( ntval)
CGAL_Comparison_result
CGAL_compare ( n1, n2)

Those routines are implemented using the required operations from the previous section. They are defined by means of templates, so you do not have to supply all those operations when you write a new number type.

For the number types bool, int, and double there is the random numbers generator CGAL_Random.


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