Definition
Type residual::smod is a variant of class residual::mod that uses a signed representation. Here numbers modulo p are represented by integral doubles in (- p/2, + p/2). All functions have the common precondition that p is a prime between 3 and 2^{26}. The functions of type residual::mod are also provided for class residual::smod and have the same meaning, so we do not list them separately here.
#include < LEDA/numbers/residual.h >
Operations
double | residual::frac(double a) | returns a + z where z is the unique integer such that a + z [- 1/2, 1/2) |
Creation
residual | x | creates an instance x of type residual and initializes it with zero. |
residual | x(long a) | creates an instance x of type residual and initializes it with the value of a. |
residual | x(int a) | creates an instance x of type residual and initializes it with the value of a. |
residual | x(double a) | creates an instance x of type residual and initializes it with the integral part of x. |
residual | x(const integer& a) | creates an instance x of type residual and initializes it with the value of a. |
Operations
The following functions have the common precondition that the residual objects a, x are integral and do not overflow.
integer | x.to_integer() | returns the integer equal to x. |
long | x.length() | returns the length of the binary representation of the integer represented by x. |
bool | x.is_long() | returns true if and only if x fits in the data format long. |
long | x.to_long() | returns a long number which is initialized with the value of x. Precondition x.is_long() is true. |
double | x.to_double() | returns a double floating point approximation of x. |
double | x.to_float() | as above. |
bool | x.is_zero() | returns true if and only if x is equal to zero. |
bool | x.is_invertible() | returns true if and only if x is nonzero and the current modular representation of x allows to invert x without loss of information. |
int | x.sign() | returns the sign of x. |
int | x.lagrange_sign() | returns the sign of x using Lagrange's formula. |
int | x.garner_sign() | returns the sign of x using Garner's formula. |
string | x.to_string() | returns the decimal representation of x. |
residual | abs(const residual& a) | returns the absolute value of a |
void | x.absolute(const residual& a) | |
sets x to the absolute value of a. |
The remaining functions do not have implicit preconditions. Although not explicitly mentioned, the arithmetic operations +, -, *, /, +=, -=, *=, /=, + +, - -, the shift operations, the comparison operations <, <=, >, >=, ==, != and the stream operations are available.
The following functions provide direct read-only access to the internal representation of residual objects. They should only be used by the experienced user after reading the full documentation of type residual.