Geogram
Version 1.9.1-rc
A programming library of geometric algorithms
|
rationalg (generic rational) is used to compute the sign of rational fractions exactly. More...
#include <geogram/basic/rationalg.h>
Public Types | |
typedef T | value_type |
Public Member Functions | |
rationalg (double x) | |
Constructs a new rationalg from a double. More... | |
rationalg (const T &x) | |
Constructs a new rationalg from an T. More... | |
rationalg (T &&x) | |
Constructs a new rationalg from an T with move semantics. More... | |
rationalg (double num, double denom) | |
Constructs a new rationalg from two doubles. More... | |
rationalg (const T &num, const T &denom) | |
Constructs a new rationalg from two T. More... | |
rationalg (T &&num, T &&denom) | |
Constructs a new rationalg from two T with move semantics. More... | |
rationalg (const rationalg< T > &rhs)=default | |
Copy-constructor. More... | |
rationalg (rationalg< T > &&rhs)=default | |
Move-constructor. More... | |
rationalg< T > & | operator= (const rationalg< T > &rhs)=default |
Assignment operator. More... | |
rationalg< T > & | operator= (rationalg< T > &&rhs)=default |
Assignment operator with move semantics. More... | |
const T & | num () const |
gets the numerator. More... | |
const T & | denom () const |
gets the denominator. More... | |
T & | num () |
gets the numerator. More... | |
T & | denom () |
gets the denominator. More... | |
void | optimize () |
Optimizes the internal representation without changing the represented value. | |
rationalg< T > & | operator+= (const rationalg< T > &rhs) |
Adds a rationalg to this rationalg. More... | |
rationalg< T > & | operator-= (const rationalg< T > &rhs) |
Subtracts a rationalg to this rationalg. More... | |
rationalg< T > & | operator*= (const rationalg< T > &rhs) |
Multiplies this rationalg by a rationalg. More... | |
rationalg< T > & | operator/= (const rationalg< T > &rhs) |
Divides this rationalg by a rationalg. More... | |
rationalg< T > & | operator+= (double rhs) |
Adds a double to this rationalg. More... | |
rationalg< T > & | operator-= (double rhs) |
Subtracts a double from this rationalg. More... | |
rationalg< T > & | operator*= (double rhs) |
Multiplies this rationalg by a double. More... | |
rationalg< T > & | operator/= (double rhs) |
Divides this rationalg by a double. More... | |
rationalg< T > | operator+ (const rationalg< T > &rhs) const |
Computes the sum of two rationalgs. More... | |
rationalg< T > | operator- (const rationalg< T > &rhs) const |
Computes the difference between two rationalgs. More... | |
rationalg< T > | operator* (const rationalg< T > &rhs) const |
Computes the product between two rationalgs. More... | |
rationalg< T > | operator/ (const rationalg< T > &rhs) const |
Computes the ratio between two rationalgs. More... | |
rationalg< T > | operator+ (double rhs) const |
Computes the sum of a rationalg and a double. More... | |
rationalg< T > | operator- (double rhs) const |
Computes the difference between a rationalg and a double. More... | |
rationalg< T > | operator* (double rhs) const |
Computes the product between a rationalg and a double. More... | |
rationalg< T > | operator/ (double rhs) const |
Computes the ratio between a rationalg and a double. More... | |
rationalg< T > | operator- () const |
Computes the opposite of this rationalg. More... | |
Sign | sign () const |
Gets the sign of a rationalg. More... | |
Sign | compare (const rationalg< T > &rhs) const |
Compares two rationalg. More... | |
Sign | compare (double rhs) const |
Compares a rationalg with a double. More... | |
bool | operator> (const rationalg< T > &rhs) const |
Compares this rationalg with another one. More... | |
bool | operator>= (const rationalg< T > &rhs) const |
Compares this rationalg with another one. More... | |
bool | operator< (const rationalg< T > &rhs) const |
Compares this rationalg with another one. More... | |
bool | operator<= (const rationalg< T > &rhs) const |
Compares this rationalg with another one. More... | |
bool | operator> (double rhs) const |
Compares this rationalg with another one. More... | |
bool | operator>= (double rhs) const |
Compares this rationalg with another one. More... | |
bool | operator< (double rhs) const |
Compares this rationalg with another one. More... | |
bool | operator<= (double rhs) const |
Compares this rationalg with another one. More... | |
double | estimate () const |
Computes an approximation of the stored value in this rational. More... | |
Protected Member Functions | |
void | copy (const rationalg< T > &rhs) |
Copies a rational into this one. More... | |
bool | has_same_denom (const rationalg< T > &rhs) const |
Tests whether a rationalg has trivially the same denominator this rationalg. More... | |
Related Functions | |
(Note that these are not member functions.) | |
template<class T > | |
rationalg< T > | operator+ (double a, const rationalg< T > &b) |
Computes the sum of a double and a rationalg. More... | |
template<class T > | |
rationalg< T > | operator- (double a, const rationalg< T > &b) |
Computes the difference between a double and a rationalg. More... | |
template<class T > | |
rationalg< T > | operator* (double a, const rationalg< T > &b) |
Computes the product of a double and a rationalg. More... | |
template<class T > | |
rationalg< T > | operator/ (double a, const rationalg< T > &b) |
Computes the ratio between a double and a rationalg. More... | |
template<class T > | |
bool | operator== (const rationalg< T > &a, const rationalg< T > &b) |
Tests equality between two rationalgs. More... | |
template<class T > | |
bool | operator== (const rationalg< T > &a, double b) |
Tests equality between a rationalg and a double. More... | |
template<class T > | |
bool | operator== (double a, const rationalg< T > &b) |
Tests equality between a double and a rationalg. More... | |
template<class T > | |
bool | operator!= (const rationalg< T > &a, const rationalg< T > &b) |
Tests whether two rationalgs differ. More... | |
template<class T > | |
bool | operator!= (const rationalg< T > &a, double b) |
Tests whether a rationalg differs from a double. More... | |
template<class T > | |
bool | operator!= (double a, const rationalg< T > &b) |
Tests whether a double differs from a rationalg. More... | |
rationalg (generic rational) is used to compute the sign of rational fractions exactly.
rationalg can be used like float and double. It supports four arithmetic operations (+,-,*,/), comparisons (>,>=,<,<=,==,!=) and exact sign computation.
Definition at line 59 of file rationalg.h.
|
inlineexplicit |
Constructs a new rationalg from a double.
[in] | x | the value to initialize this rationalg. |
Definition at line 69 of file rationalg.h.
|
inlineexplicit |
Constructs a new rationalg from an T.
[in] | x | the value to initialize this rationalg. |
Definition at line 76 of file rationalg.h.
|
inlineexplicit |
Constructs a new rationalg from an T with move semantics.
[in] | x | the victim T |
Definition at line 84 of file rationalg.h.
|
inlineexplicit |
Constructs a new rationalg from two doubles.
[in] | num | the numerator |
[in] | denom | the denominator |
Definition at line 92 of file rationalg.h.
|
inlineexplicit |
Constructs a new rationalg from two T.
[in] | num | the numerator |
[in] | denom | the denominator |
Definition at line 101 of file rationalg.h.
|
inlineexplicit |
Constructs a new rationalg from two T with move semantics.
[in] | num | the numerator |
[in] | denom | the denominator |
Definition at line 111 of file rationalg.h.
|
default |
Copy-constructor.
[in] | rhs | the rational to be copied |
|
default |
Move-constructor.
[in] | rhs | the rational to be copied |
|
inline |
Compares two rationalg.
Definition at line 427 of file rationalg.h.
|
inline |
Compares a rationalg with a double.
Definition at line 444 of file rationalg.h.
|
inlineprotected |
Copies a rational into this one.
[in] | rhs | a const reference to the rational to be copied |
Definition at line 554 of file rationalg.h.
|
inline |
gets the denominator.
Definition at line 170 of file rationalg.h.
|
inline |
gets the denominator.
Definition at line 154 of file rationalg.h.
|
inline |
Computes an approximation of the stored value in this rational.
Definition at line 545 of file rationalg.h.
|
inlineprotected |
Tests whether a rationalg has trivially the same denominator this rationalg.
This function is used to implement faster addition, subtraction and tests when it can be quickly determined that both operands have the same denominator.
true | if it is trivial that rhs has the same denominator as this rationalg. |
false | otherwise. |
Definition at line 569 of file rationalg.h.
|
inline |
gets the numerator.
Definition at line 162 of file rationalg.h.
|
inline |
gets the numerator.
Definition at line 146 of file rationalg.h.
|
inline |
Computes the product between two rationalgs.
[in] | rhs | the rationalg to be multiplied by this rationalg |
rhs
Definition at line 328 of file rationalg.h.
|
inline |
Computes the product between a rationalg and a double.
[in] | rhs | the double to be multiplied by this rationalg |
rhs
Definition at line 378 of file rationalg.h.
|
inline |
Multiplies this rationalg by a rationalg.
[in] | rhs | the rationalg to multiply this rationalg by |
Definition at line 220 of file rationalg.h.
|
inline |
Multiplies this rationalg by a double.
If the double is a constant (possibly negative) power of two (e.g. 0.125, 0.5, 2.0, 4.0 ...), one may use num().scale_fast() / denom().scale_fast() instead.
[in] | rhs | the double to multiply this rationalg with |
Definition at line 265 of file rationalg.h.
|
inline |
Computes the sum of two rationalgs.
[in] | rhs | the rationalg to be added to this rationalg |
rhs
Definition at line 290 of file rationalg.h.
|
inline |
Computes the sum of a rationalg and a double.
[in] | rhs | the double to be added to this rationalg |
rhs
Definition at line 354 of file rationalg.h.
|
inline |
Adds a rationalg to this rationalg.
[in] | rhs | the rationalg to be added to this rationalg |
Definition at line 190 of file rationalg.h.
|
inline |
Adds a double to this rationalg.
[in] | rhs | the double to be added to this rationalg |
Definition at line 242 of file rationalg.h.
|
inline |
Computes the opposite of this rationalg.
Definition at line 403 of file rationalg.h.
|
inline |
Computes the difference between two rationalgs.
[in] | rhs | the rationalg to be subtracted from this rationalg |
rhs
Definition at line 309 of file rationalg.h.
|
inline |
Computes the difference between a rationalg and a double.
[in] | rhs | the double to be subtracted from this rationalg |
rhs
Definition at line 366 of file rationalg.h.
|
inline |
Subtracts a rationalg to this rationalg.
[in] | rhs | the rationalg to be subtracted |
Definition at line 205 of file rationalg.h.
|
inline |
Subtracts a double from this rationalg.
[in] | rhs | the double to be subtracted from this rationalg |
Definition at line 252 of file rationalg.h.
|
inline |
Computes the ratio between two rationalgs.
[in] | rhs | the rationalg to be multiplied by this rationalg |
rhs
Definition at line 341 of file rationalg.h.
|
inline |
Computes the ratio between a rationalg and a double.
[in] | rhs | the double to be multiplied by this rationalg |
rhs
Definition at line 390 of file rationalg.h.
|
inline |
Divides this rationalg by a rationalg.
[in] | rhs | the rationalg to divide this rationalg by |
Definition at line 231 of file rationalg.h.
|
inline |
Divides this rationalg by a double.
If the double is a constant (possibly negative) power of two (e.g. 0.125, 0.5, 2.0, 4.0 ...), one may use num().scale_fast() / denom().scale_fast() instead.
[in] | rhs | the double to multiply this rationalg with |
Definition at line 278 of file rationalg.h.
|
inline |
Compares this rationalg with another one.
Internally computes the sign of the difference between this rationalg and rhs
.
rhs
, false otherwise Definition at line 479 of file rationalg.h.
|
inline |
Compares this rationalg with another one.
Internally computes the sign of the difference between this rationalg and rhs
.
rhs
, false otherwise Definition at line 523 of file rationalg.h.
|
inline |
Compares this rationalg with another one.
Internally computes the sign of the difference between this rationalg and rhs
.
rhs
, false otherwise Definition at line 490 of file rationalg.h.
|
inline |
Compares this rationalg with another one.
Internally computes the sign of the difference between this rationalg and rhs
.
rhs
, false otherwise Definition at line 534 of file rationalg.h.
|
default |
Assignment operator.
[in] | rhs | the rational to be copied |
|
default |
Assignment operator with move semantics.
[in] | rhs | the victim rationalg |
|
inline |
Compares this rationalg with another one.
Internally computes the sign of the difference between this rationalg and rhs
.
rhs
, false otherwise Definition at line 457 of file rationalg.h.
|
inline |
Compares this rationalg with another one.
Internally computes the sign of the difference between this rationalg and rhs
.
rhs
, false otherwise Definition at line 501 of file rationalg.h.
|
inline |
Compares this rationalg with another one.
Internally computes the sign of the difference between this rationalg and rhs
.
rhs
, false otherwise Definition at line 468 of file rationalg.h.
|
inline |
Compares this rationalg with another one.
Internally computes the sign of the difference between this rationalg and rhs
.
rhs
, false otherwise Definition at line 512 of file rationalg.h.
|
inline |
Gets the sign of a rationalg.
Definition at line 416 of file rationalg.h.
Tests whether two rationalgs differ.
Implemented by testing whether the difference between a
and b
is different from 0.
a
and b
do not represent the same exact value, false otherwise Definition at line 681 of file rationalg.h.
|
related |
Tests whether a rationalg differs from a double.
Implemented by testing whether the difference between a
and b
is different from 0.
a
and b
do not represent the same exact value, false otherwise Definition at line 694 of file rationalg.h.
|
related |
Tests whether a double differs from a rationalg.
Implemented by testing whether the difference between a
and b
is different from 0.
a
and b
do not represent the same exact value, false otherwise Definition at line 707 of file rationalg.h.
Computes the product of a double and a rationalg.
[in] | a | the double |
[in] | b | the rationalg to be multiplied |
a
* b
Definition at line 614 of file rationalg.h.
Computes the sum of a double and a rationalg.
[in] | a | the double to be added |
[in] | b | the rationalg to be added |
a
+ b
Definition at line 588 of file rationalg.h.
Computes the difference between a double and a rationalg.
[in] | a | the double |
[in] | b | the rationalg to be subtracted |
a
- b
Definition at line 600 of file rationalg.h.
Computes the ratio between a double and a rationalg.
[in] | a | the double |
[in] | b | the rationalg to be divided |
a
/ b
Definition at line 626 of file rationalg.h.
Tests equality between two rationalgs.
Implemented by testing whether the difference between a
and b
is 0.
a
and b
represent exactly the same value, false otherwise Definition at line 642 of file rationalg.h.
|
related |
Tests equality between a rationalg and a double.
Implemented by testing whether the difference between a
and b
is 0.
a
and b
represent exactly the same value, false otherwise Definition at line 655 of file rationalg.h.
|
related |
Tests equality between a double and a rationalg.
Implemented by testing whether the difference between a
and b
is 0.
a
and b
represent exactly the same value, false otherwise Definition at line 668 of file rationalg.h.