|
Geogram Version 1.8.5
A programming library of geometric algorithms
|
Rational_nt (rational Number Type) is used to compute the sign of rational fractions exactly. More...
#include <geogram/numerics/expansion_nt.h>
Public Types | |
| enum | UninitializedType { UNINITIALIZED } |
| This type is used to overload expression_nt constructors with a version that does not create an expansion. More... | |
Public Member Functions | |
| rational_nt (UninitializedType uninitialized) | |
| Constructs an uninitialized rational_nt. | |
| rational_nt (double x=0.0) | |
| Constructs a new rational_nt from a double. | |
| rational_nt (const expansion_nt &x) | |
| Constructs a new rational_nt from an expansion_nt. | |
| rational_nt (expansion_nt &&x) | |
| Constructs a new rational_nt from an expansion_nt with move semantics. | |
| rational_nt (double num, double denom) | |
| Constructs a new rational_nt from two doubles. | |
| rational_nt (const expansion_nt &num, const expansion_nt &denom) | |
| Constructs a new rational_nt from two expansion_nt. | |
| rational_nt (expansion_nt &&num, expansion_nt &&denom) | |
| Constructs a new rational_nt from two expansion_nt with move semantics. | |
| rational_nt (const rational_nt &rhs) | |
| Copy-constructor. | |
| rational_nt (rational_nt &&rhs) | |
| Move-constructor. | |
| rational_nt & | operator= (const rational_nt &rhs) |
| Assignment operator. | |
| rational_nt & | operator= (rational_nt &&rhs) |
| Assignment operator with move semantics. | |
| const expansion_nt & | num () const |
| gets the numerator. | |
| const expansion_nt & | denom () const |
| gets the denominator. | |
| expansion_nt & | num () |
| gets the numerator. | |
| expansion_nt & | denom () |
| gets the denominator. | |
| void | optimize () |
| Optimizes the internal representation without changing the represented value. | |
| rational_nt & | operator+= (const rational_nt &rhs) |
| Adds a rational_nt to this rational_nt. | |
| rational_nt & | operator-= (const rational_nt &rhs) |
| Subtracts a rational_nt to this rational_nt. | |
| rational_nt & | operator*= (const rational_nt &rhs) |
| Multiplies this rational_nt by a rational_nt. | |
| rational_nt & | operator/= (const rational_nt &rhs) |
| Divides this rational_nt by a rational_nt. | |
| rational_nt & | operator+= (double rhs) |
| Adds a double to this rational_nt. | |
| rational_nt & | operator-= (double rhs) |
| Subtracts a double from this rational_nt. | |
| rational_nt & | operator*= (double rhs) |
| Multiplies this rational_nt by a double. | |
| rational_nt & | operator/= (double rhs) |
| Divides this rational_nt by a double. | |
| rational_nt | operator+ (const rational_nt &rhs) const |
| Computes the sum of two rational_nts. | |
| rational_nt | operator- (const rational_nt &rhs) const |
| Computes the difference between two rational_nts. | |
| rational_nt | operator* (const rational_nt &rhs) const |
| Computes the product between two rational_nts. | |
| rational_nt | operator/ (const rational_nt &rhs) const |
| Computes the ratio between two rational_nts. | |
| rational_nt | operator+ (double rhs) const |
| Computes the sum of a rational_nt and a double. | |
| rational_nt | operator- (double rhs) const |
| Computes the difference between a rational_nt and a double. | |
| rational_nt | operator* (double rhs) const |
| Computes the product between a rational_nt and a double. | |
| rational_nt | operator/ (double rhs) const |
| Computes the ratio between a rational_nt and a double. | |
| rational_nt | operator- () const |
| Computes the opposite of this rational_nt. | |
| Sign | compare (const rational_nt &rhs) const |
| Compares two rational_nt. | |
| Sign | compare (double rhs) const |
| Compares a rational_nt with a double. | |
| bool | operator> (const rational_nt &rhs) const |
| Compares this rational_nt with another one. | |
| bool | operator>= (const rational_nt &rhs) const |
| Compares this rational_nt with another one. | |
| bool | operator< (const rational_nt &rhs) const |
| Compares this rational_nt with another one. | |
| bool | operator<= (const rational_nt &rhs) const |
| Compares this rational_nt with another one. | |
| bool | operator> (double rhs) const |
| Compares this rational_nt with another one. | |
| bool | operator>= (double rhs) const |
| Compares this rational_nt with another one. | |
| bool | operator< (double rhs) const |
| Compares this rational_nt with another one. | |
| bool | operator<= (double rhs) const |
| Compares this rational_nt with another one. | |
| double | estimate () const |
| Computes an approximation of the stored value in this rational. | |
| Sign | sign () const |
| Gets the sign of this rational_nt. | |
Protected Member Functions | |
| void | copy (const rational_nt &rhs) |
| Copies a rational into this one. | |
| bool | has_same_denom (const rational_nt &rhs) const |
| Tests whether a rational_nt has trivially the same denominator as this rational_nt. | |
Related Symbols | |
(Note that these are not member symbols.) | |
| rational_nt | operator+ (double a, const rational_nt &b) |
| Computes the sum of a double and a rational_nt. | |
| rational_nt | operator- (double a, const rational_nt &b) |
| Computes the difference between a double and a rational_nt. | |
| rational_nt | operator* (double a, const rational_nt &b) |
| Computes the product of a double and a rational_nt. | |
| rational_nt | operator/ (double a, const rational_nt &b) |
| Computes the ratio between a double and a rational_nt. | |
| bool | operator== (const rational_nt &a, const rational_nt &b) |
| Tests equality between two rational_nts. | |
| bool | operator== (const rational_nt &a, double b) |
| Tests equality between a rational_nt and a double. | |
| bool | operator== (double a, const rational_nt &b) |
| Tests equality between a double and a rational_nt. | |
| bool | operator!= (const rational_nt &a, const rational_nt &b) |
| Tests whether two rational_nts differ. | |
| bool | operator!= (const rational_nt &a, double b) |
| Tests whether a rational_nt differs from a double. | |
| bool | operator!= (double a, const rational_nt &b) |
| Tests whether a double differs from a rational_nt. | |
Rational_nt (rational Number Type) is used to compute the sign of rational fractions exactly.
Rational_nt can be used like float and double. It supports four arithmetic operations (+,-,*,/), comparisons (>,>=,<,<=,==,!=) and exact sign computation. When performance is a concern, the lower-level expansion class may be used instead.
Definition at line 1030 of file expansion_nt.h.
This type is used to overload expression_nt constructors with a version that does not create an expansion.
Definition at line 1038 of file expansion_nt.h.
|
inlineexplicit |
Constructs an uninitialized rational_nt.
Definition at line 1045 of file expansion_nt.h.
|
inlineexplicit |
Constructs a new rational_nt from a double.
| [in] | x | the value to initialize this rational_nt. |
Definition at line 1056 of file expansion_nt.h.
|
inlineexplicit |
Constructs a new rational_nt from an expansion_nt.
| [in] | x | the value to initialize this rational_nt. |
Definition at line 1063 of file expansion_nt.h.
|
inlineexplicit |
Constructs a new rational_nt from an expansion_nt with move semantics.
| [in] | x | the victim expansion_nt |
Definition at line 1071 of file expansion_nt.h.
|
inlineexplicit |
Constructs a new rational_nt from two doubles.
| [in] | num | the numerator |
| [in] | denom | the denominator |
Definition at line 1079 of file expansion_nt.h.
|
inlineexplicit |
Constructs a new rational_nt from two expansion_nt.
| [in] | num | the numerator |
| [in] | denom | the denominator |
Definition at line 1088 of file expansion_nt.h.
|
inlineexplicit |
Constructs a new rational_nt from two expansion_nt with move semantics.
| [in] | num | the numerator |
| [in] | denom | the denominator |
Definition at line 1098 of file expansion_nt.h.
|
inline |
Copy-constructor.
| [in] | rhs | the rational to be copied |
Definition at line 1107 of file expansion_nt.h.
|
inline |
Move-constructor.
| [in] | rhs | the rational to be copied |
Definition at line 1115 of file expansion_nt.h.
| Sign GEO::rational_nt::compare | ( | const rational_nt & | rhs | ) | const |
Compares two rational_nt.
| Sign GEO::rational_nt::compare | ( | double | rhs | ) | const |
Compares a rational_nt with a double.
|
inlineprotected |
Copies a rational into this one.
| [in] | rhs | a const reference to the rational to be copied |
Definition at line 1538 of file expansion_nt.h.
|
inline |
gets the denominator.
Definition at line 1170 of file expansion_nt.h.
|
inline |
gets the denominator.
Definition at line 1154 of file expansion_nt.h.
|
inline |
Computes an approximation of the stored value in this rational.
Definition at line 1520 of file expansion_nt.h.
|
inlineprotected |
Tests whether a rational_nt has trivially the same denominator as this rational_nt.
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 rational_nt. |
| false | otherwise. |
Definition at line 1553 of file expansion_nt.h.
|
inline |
gets the numerator.
Definition at line 1162 of file expansion_nt.h.
|
inline |
gets the numerator.
Definition at line 1146 of file expansion_nt.h.
|
inline |
Computes the product between two rational_nts.
| [in] | rhs | the rational_nt to be multiplied by this rational_nt |
rhs Definition at line 1329 of file expansion_nt.h.
|
inline |
Computes the product between a rational_nt and a double.
| [in] | rhs | the double to be multiplied by this rational_nt |
rhs Definition at line 1379 of file expansion_nt.h.
|
inline |
Multiplies this rational_nt by a rational_nt.
| [in] | rhs | the rational_nt to multiply this rational_nt by |
Definition at line 1221 of file expansion_nt.h.
|
inline |
Multiplies this rational_nt 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 rational_nt with |
Definition at line 1266 of file expansion_nt.h.
|
inline |
Computes the sum of two rational_nts.
| [in] | rhs | the rational_nt to be added to this rational_nt |
rhs Definition at line 1291 of file expansion_nt.h.
|
inline |
Computes the sum of a rational_nt and a double.
| [in] | rhs | the double to be added to this rational_nt |
rhs Definition at line 1355 of file expansion_nt.h.
|
inline |
Adds a rational_nt to this rational_nt.
| [in] | rhs | the rational_nt to be added to this rational_nt |
Definition at line 1191 of file expansion_nt.h.
|
inline |
Adds a double to this rational_nt.
| [in] | rhs | the double to be added to this rational_nt |
Definition at line 1243 of file expansion_nt.h.
|
inline |
Computes the opposite of this rational_nt.
Definition at line 1404 of file expansion_nt.h.
|
inline |
Computes the difference between two rational_nts.
| [in] | rhs | the rational_nt to be subtracted from this rational_nt |
rhs Definition at line 1310 of file expansion_nt.h.
|
inline |
Computes the difference between a rational_nt and a double.
| [in] | rhs | the double to be subtracted from this rational_nt |
rhs Definition at line 1367 of file expansion_nt.h.
|
inline |
Subtracts a rational_nt to this rational_nt.
| [in] | rhs | the rational_nt to be subtracted |
Definition at line 1206 of file expansion_nt.h.
|
inline |
Subtracts a double from this rational_nt.
| [in] | rhs | the double to be subtracted from this rational_nt |
Definition at line 1253 of file expansion_nt.h.
|
inline |
Computes the ratio between two rational_nts.
| [in] | rhs | the rational_nt to be multiplied by this rational_nt |
rhs Definition at line 1342 of file expansion_nt.h.
|
inline |
Computes the ratio between a rational_nt and a double.
| [in] | rhs | the double to be multiplied by this rational_nt |
rhs Definition at line 1391 of file expansion_nt.h.
|
inline |
Divides this rational_nt by a rational_nt.
| [in] | rhs | the rational_nt to divide this rational_nt by |
Definition at line 1232 of file expansion_nt.h.
|
inline |
Divides this rational_nt 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 rational_nt with |
Definition at line 1279 of file expansion_nt.h.
|
inline |
Compares this rational_nt with another one.
Internally computes the sign of the difference between this rational_nt and rhs.
rhs, false otherwise Definition at line 1454 of file expansion_nt.h.
|
inline |
Compares this rational_nt with another one.
Internally computes the sign of the difference between this rational_nt and rhs.
rhs, false otherwise Definition at line 1498 of file expansion_nt.h.
|
inline |
Compares this rational_nt with another one.
Internally computes the sign of the difference between this rational_nt and rhs.
rhs, false otherwise Definition at line 1465 of file expansion_nt.h.
|
inline |
Compares this rational_nt with another one.
Internally computes the sign of the difference between this rational_nt and rhs.
rhs, false otherwise Definition at line 1509 of file expansion_nt.h.
|
inline |
Assignment operator.
| [in] | rhs | the rational to be copied |
Definition at line 1125 of file expansion_nt.h.
|
inline |
Assignment operator with move semantics.
| [in] | rhs | the victim rational_nt |
Definition at line 1136 of file expansion_nt.h.
|
inline |
Compares this rational_nt with another one.
Internally computes the sign of the difference between this rational_nt and rhs.
rhs, false otherwise Definition at line 1432 of file expansion_nt.h.
|
inline |
Compares this rational_nt with another one.
Internally computes the sign of the difference between this rational_nt and rhs.
rhs, false otherwise Definition at line 1476 of file expansion_nt.h.
|
inline |
Compares this rational_nt with another one.
Internally computes the sign of the difference between this rational_nt and rhs.
rhs, false otherwise Definition at line 1443 of file expansion_nt.h.
|
inline |
Compares this rational_nt with another one.
Internally computes the sign of the difference between this rational_nt and rhs.
rhs, false otherwise Definition at line 1487 of file expansion_nt.h.
|
inline |
Optimizes the internal representation without changing the represented value.
this function can reduce the length of an expansion
Definition at line 1179 of file expansion_nt.h.
|
inline |
Gets the sign of this rational_nt.
Definition at line 1528 of file expansion_nt.h.
|
related |
Tests whether two rational_nts 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 1657 of file expansion_nt.h.
|
related |
Tests whether a rational_nt 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 1669 of file expansion_nt.h.
|
related |
Tests whether a double differs from a rational_nt.
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 1681 of file expansion_nt.h.
|
related |
Computes the product of a double and a rational_nt.
| [in] | a | the double |
| [in] | b | the rational_nt to be multiplied |
a * b Definition at line 1595 of file expansion_nt.h.
|
related |
Computes the sum of a double and a rational_nt.
| [in] | a | the double to be added |
| [in] | b | the rational_nt to be added |
a + b Definition at line 1571 of file expansion_nt.h.
|
related |
Computes the difference between a double and a rational_nt.
| [in] | a | the double |
| [in] | b | the rational_nt to be subtracted |
a - b Definition at line 1582 of file expansion_nt.h.
|
related |
Computes the ratio between a double and a rational_nt.
| [in] | a | the double |
| [in] | b | the rational_nt to be divided |
a / b Definition at line 1606 of file expansion_nt.h.
|
related |
Tests equality between two rational_nts.
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 1621 of file expansion_nt.h.
|
related |
Tests equality between a rational_nt 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 1633 of file expansion_nt.h.
|
related |
Tests equality between a double and a rational_nt.
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 1645 of file expansion_nt.h.