Class

CGAL::Residue

Definition

The class Residue represents a finite field /p, for some prime number p.

The prime number p is stored in a static member variable. The class provides static member functions to change this value. Note that changing the prime invalidates already existing objects of this type. However, already existing objects do not lose their value with respect to the old prime and can be reused after restoring the old prime. Since the type is based on double arithmetic the prime is restricted to values less than 226. The initial value of p is 67111067.

Please note that the implementation of class CGAL::Residue requires a mantissa precision according to the IEEE Standard for Floating-Point Arithmetic (IEEE 754). However, on some processors the traditional FPU uses an extended precision. Hence, it is indispensable that the proper mantissa length is enforced before performing any arithmetic operations. Moreover, it is required that numbers are rounded to the next nearest value. This can be ensured using CGAL::Protect_FPU_rounding with CGAL_FE_TONEAREST, which also enforces the required precision as a side effect.

In case the flag CGAL_HAS_THREADS is undefined the prime is just stored in a static member of the class, that is, Residue is not thread-safe in this case. In case CGAL_HAS_THREADS the implementation of the class is thread safe using boost::thread_specific_ptr. However, this may cause some performance penalty. Hence, it may be advisable to configure CGAL with CGAL_HAS_NO_THREADS.

#include <CGAL/Residue.h>

Is Model for the Concepts

Field

Creation

Residue x;
introduces a variable x, which is initialized with zero;

Residue x ( m);
copy constructor;

Residue x ( int i);
introduces a variable x, which is initialized with i % p;

Residue x ( long i);
introduces a variable x, which is initialized with i % p;

Operations

static int x.set_current_prime ( int p) Static member function;
sets current prime to the given value and returns the old prime.
static int x.get_current_prime () Static member function;
returns the value of the current prime.
int x.get_value () const Returns the unique representative of xwithin the range [-p/2,p/2], where p is the current prime.

Residue + a
Residue - a
Residue a + b
Residue a - b
Residue a * b
Residue a / b
Residue & x += a
Residue & x -= a
Residue & x *= a
Residue & x /= a
Residue a == b
Residue a != b