Geogram  Version 1.9.1-rc
A programming library of geometric algorithms
GEO::expansion_nt Class Reference

Expansion_nt (expansion Number Type) is used to compute the sign of polynoms exactly. More...

#include <geogram/numerics/expansion_nt.h>

Public Types

enum  Operation { SUM , DIFF , PRODUCT }
 This type is used by the constructor that takes two expansions.
 

Public Member Functions

 expansion_nt ()
 Constructs an uninitialized expansion_nt.
 
 expansion_nt (double x)
 Constructs a new expansion_nt from a double. More...
 
 expansion_nt (const expansion &rhs)
 Constructs a new expansion_nt from an expansion. More...
 
 expansion_nt (Operation op, const expansion &x, const expansion &y)
 Constructs a new expansion_nt from two expansions. More...
 
 expansion_nt (Operation op, const expansion &x, const expansion &y, const expansion &z)
 Constructs a new expansion_nt from three expansions. More...
 
 expansion_nt (Operation op, const expansion &x, const expansion &y, const expansion &z, const expansion &t)
 Constructs a new expansion_nt from four expansions. More...
 
 expansion_nt (Operation op, double x, double y)
 Constructs a new expansion_nt from two doubles. More...
 
 expansion_nt (const expansion_nt &rhs)
 Copy-constructor. More...
 
 expansion_nt (expansion_nt &&rhs)
 Move-constructor. More...
 
expansion_ntoperator= (const expansion_nt &rhs)
 Assignment operator. More...
 
expansion_ntoperator= (expansion_nt &&rhs)
 Assignment operator with move semantics. More...
 
 ~expansion_nt ()
 Expansion_nt destructor. More...
 
void optimize ()
 Optimizes the internal representation without changing the represented value. More...
 
void negate ()
 Flips the sign of an expansion.
 
expansion_ntoperator+= (const expansion_nt &rhs)
 Adds an expansion_nt to this expansion_nt. More...
 
expansion_ntoperator-= (const expansion_nt &rhs)
 Subtracts an expansion_nt to this expansion_nt. More...
 
expansion_ntoperator*= (const expansion_nt &rhs)
 Multiplies this expansion_nt by an expansion_nt. More...
 
expansion_ntoperator+= (double rhs)
 Adds a double to this expansion_nt. More...
 
expansion_ntoperator-= (double rhs)
 Subtracts a double from this expansion_nt. More...
 
expansion_ntoperator*= (double rhs)
 Multiplies this expansion_nt by a double. More...
 
expansion_nt operator+ (const expansion_nt &rhs) const
 Computes the sum of two expansion_nts. More...
 
expansion_nt operator- (const expansion_nt &rhs) const
 Computes the difference between two expansion_nts. More...
 
expansion_nt operator* (const expansion_nt &rhs) const
 Computes the product between two expansion_nts. More...
 
expansion_nt operator+ (double rhs) const
 Computes the sum of an expansion_nt and a double. More...
 
expansion_nt operator- (double rhs) const
 Computes the difference between an expansion_nt and a double. More...
 
expansion_nt operator* (double rhs) const
 Computes the product between an expansion_nt and a double. More...
 
expansion_nt operator- () const
 Computes the opposite of this expansion_nt. More...
 
Sign compare (const expansion_nt &rhs) const
 Compares two expansion_nt. More...
 
Sign compare (double rhs) const
 Compares an expansion_nt with a double. More...
 
bool operator> (const expansion_nt &rhs) const
 Compares this expansion_nt with another one. More...
 
bool operator>= (const expansion_nt &rhs) const
 Compares this expansion_nt with another one. More...
 
bool operator< (const expansion_nt &rhs) const
 Compares this expansion_nt with another one. More...
 
bool operator<= (const expansion_nt &rhs) const
 Compares this expansion_nt with another one. More...
 
bool operator> (double rhs) const
 Compares this expansion_nt with another one. More...
 
bool operator>= (double rhs) const
 Compares this expansion_nt with another one. More...
 
bool operator< (double rhs) const
 Compares this expansion_nt with another one. More...
 
bool operator<= (double rhs) const
 Compares this expansion_nt with another one. More...
 
double estimate () const
 Computes an approximation of the stored value in this expansion. More...
 
Sign sign () const
 Gets the sign of this expansion_nt. More...
 
index_t length () const
 Gets the length of this expansion. More...
 
double component (index_t i) const
 Gets the i-th component of this expansion. More...
 
 expansion_nt (expansion *rep)
 Constructs a new expansion_nt from an expansion. More...
 
expansionrep ()
 Gets the internal expansion that represents this expansion_nt. More...
 
const expansionrep () const
 Gets the internal expansion that represents this expansion_nt. More...
 
std::string to_string () const
 Gets a string representation of this expansion. More...
 

Protected Member Functions

void copy (const expansion_nt &rhs)
 Copies an expansion into this one. More...
 
void cleanup ()
 Cleanups the memory associated with this expansion_nt.
 

Friends

expansion_nt operator- (double a, const expansion_nt &b)
 
expansion_nt expansion_nt_sq_dist (const double *a, const double *b, coord_index_t dim)
 
expansion_nt expansion_nt_dot_at (const double *a, const double *b, const double *c, coord_index_t dim)
 

Related Functions

(Note that these are not member functions.)

expansion_nt operator+ (double a, const expansion_nt &b)
 Computes the sum of a double and an expansion_nt. More...
 
expansion_nt operator- (double a, const expansion_nt &b)
 Computes the difference between a double and an expansion_nt. More...
 
expansion_nt operator* (double a, const expansion_nt &b)
 Computes the product of a double and an expansion_nt. More...
 
bool operator== (const expansion_nt &a, const expansion_nt &b)
 Tests equality between two expansion_nts. More...
 
bool operator== (const expansion_nt &a, double b)
 Tests equality between an expansion_nt and a double. More...
 
bool operator== (double a, const expansion_nt &b)
 Tests equality between a double and an expansion_nt. More...
 
bool operator!= (const expansion_nt &a, const expansion_nt &b)
 Tests whether two expansion_nts differ. More...
 
bool operator!= (const expansion_nt &a, double b)
 Tests whether an expansion_nt differs from a double. More...
 
bool operator!= (double a, const expansion_nt &b)
 Tests whether a double differs from an expansion_nt. More...
 
expansion_nt expansion_nt_sq_dist (const double *a, const double *b, coord_index_t dim)
 Computes an expansion that represents the square distance between two points. More...
 
expansion_nt expansion_nt_dot_at (const double *a, const double *b, const double *c, coord_index_t dim)
 Computes an expansion that represents the dot product of two vectors determined by three points. More...
 

Detailed Description

Expansion_nt (expansion Number Type) is used to compute the sign of polynoms exactly.

Expansion_nt can be used like float and double. It supports three arithmetic operations (+,-,*), comparisons (>,>=,<,<=,==,!=) and exact sign computation. expansion_nt is a wrapper around an expansion allocated on the heap. When performance is a concern, the lower-level expansion class may be used instead.

Definition at line 70 of file expansion_nt.h.

Constructor & Destructor Documentation

◆ expansion_nt() [1/9]

GEO::expansion_nt::expansion_nt ( double  x)
inlineexplicit

Constructs a new expansion_nt from a double.

Parameters
[in]xthe value to initialize this expansion.

Definition at line 91 of file expansion_nt.h.

◆ expansion_nt() [2/9]

GEO::expansion_nt::expansion_nt ( const expansion rhs)
inlineexplicit

Constructs a new expansion_nt from an expansion.

A new expansion is created on the heap and its content is initialized from rhs

Parameters
[in]rhsthe expansion to be copied

Definition at line 103 of file expansion_nt.h.

◆ expansion_nt() [3/9]

GEO::expansion_nt::expansion_nt ( Operation  op,
const expansion x,
const expansion y 
)
inlineexplicit

Constructs a new expansion_nt from two expansions.

A new expansion is created on the heap and its content is initialized from x op y. This function is used by code that combines the low-level API (expansion) with the high-level number type (expansion_nt). When returning the result of operations that combine expansion as an expansion_nt, it makes it possible to avoid copying the result of the last operation by directly assigning it to an expansion_nt.

Parameters
[in]x,ythe two operands
[in]opone of expansion_nt::SUM, expansion_nt::DIFF, expansion_nt::PRODUCT

Definition at line 121 of file expansion_nt.h.

◆ expansion_nt() [4/9]

GEO::expansion_nt::expansion_nt ( Operation  op,
const expansion x,
const expansion y,
const expansion z 
)
inlineexplicit

Constructs a new expansion_nt from three expansions.

A new expansion is created on the heap and its content is initialized from x op y op z. This function is used by code that combines the low-level API (expansion) with the high-level number type (expansion_nt). When returning the result of operations that combine expansion as an expansion_nt, it makes it possible to avoid copying the result of the last operation by directly assigning it to an expansion_nt.

Parameters
[in]x,y,zthe three operands
[in]opone of expansion_nt::SUM, expansion_nt::PRODUCT

Definition at line 159 of file expansion_nt.h.

◆ expansion_nt() [5/9]

GEO::expansion_nt::expansion_nt ( Operation  op,
const expansion x,
const expansion y,
const expansion z,
const expansion t 
)
inlineexplicit

Constructs a new expansion_nt from four expansions.

A new expansion is created on the heap and its content is initialized from x op y op z op t. This function is used by code that combines the low-level API (expansion) with the high-level number type (expansion_nt). When returning the result of operations that combine expansion as an expansion_nt, it makes it possible to avoid copying the result of the last operation by directly assigning it to an expansion_nt.

Parameters
[in]x,y,z,tthe four operands
[in]opone of expansion_nt::SUM, expansion_nt::PRODUCT

Definition at line 195 of file expansion_nt.h.

◆ expansion_nt() [6/9]

GEO::expansion_nt::expansion_nt ( Operation  op,
double  x,
double  y 
)
inlineexplicit

Constructs a new expansion_nt from two doubles.

A new expansion is created on the heap and its content is initialized from x op y. This function is used by code that combines the low-level API (expansion) with the high-level number type (expansion_nt). When returning the result of operations that combine expansion as an expansion_nt, it makes it possible to avoid copying the result of the last operation by directly assigning it to an expansion_nt.

Parameters
[in]x,ythe two operands
[in]opone of expansion_nt::SUM, expansion_nt::DIFF, expansion_nt::PRODUCT

Definition at line 235 of file expansion_nt.h.

◆ expansion_nt() [7/9]

GEO::expansion_nt::expansion_nt ( const expansion_nt rhs)
inline

Copy-constructor.

Parameters
[in]rhsthe expansion to be copied

Definition at line 262 of file expansion_nt.h.

◆ expansion_nt() [8/9]

GEO::expansion_nt::expansion_nt ( expansion_nt &&  rhs)
inline

Move-constructor.

Steals the expansion from rhs

Parameters
[in]rhsthe victim expansion_nt

Definition at line 271 of file expansion_nt.h.

◆ ~expansion_nt()

GEO::expansion_nt::~expansion_nt ( )
inline

Expansion_nt destructor.

The stored expansion is deallocated whenever reference counting reaches 0.

Definition at line 307 of file expansion_nt.h.

◆ expansion_nt() [9/9]

GEO::expansion_nt::expansion_nt ( expansion rep)
inline

Constructs a new expansion_nt from an expansion.

Used internally

Parameters
[in]repshould be a reference-counted expansion, created by new_expansion_on_heap(). Its reference counter is incremented.
Note
most client code will not need to use this (advanced use only).

Definition at line 585 of file expansion_nt.h.

Member Function Documentation

◆ compare() [1/2]

Sign GEO::expansion_nt::compare ( const expansion_nt rhs) const
inline

Compares two expansion_nt.

Returns
the sign of this expansion minus rhs

Definition at line 434 of file expansion_nt.h.

◆ compare() [2/2]

Sign GEO::expansion_nt::compare ( double  rhs) const
inline

Compares an expansion_nt with a double.

Returns
the sign of this expansion minus rhs

Definition at line 442 of file expansion_nt.h.

◆ component()

double GEO::expansion_nt::component ( index_t  i) const
inline

Gets the i-th component of this expansion.

Parameters
iindex of the component
Returns
the i-th component of this expansion
Precondition
i < length()
Note
most client code will not need to use this (advanced use only).

Definition at line 572 of file expansion_nt.h.

◆ copy()

void GEO::expansion_nt::copy ( const expansion_nt rhs)
inlineprotected

Copies an expansion into this one.

current rep_ pointer is supposed to be uninitialized or freed before calling this function.

Parameters
[in]rhsa const reference to the expansion to be copied

Definition at line 632 of file expansion_nt.h.

◆ estimate()

double GEO::expansion_nt::estimate ( ) const
inline

Computes an approximation of the stored value in this expansion.

Returns
an approximation of the stored value.

Definition at line 541 of file expansion_nt.h.

◆ length()

index_t GEO::expansion_nt::length ( ) const
inline

Gets the length of this expansion.

Returns
the number of components used internally to represend this expansion
Note
most client code will not need to use this (advanced use only).

Definition at line 560 of file expansion_nt.h.

◆ operator*() [1/2]

expansion_nt GEO::expansion_nt::operator* ( const expansion_nt rhs) const

Computes the product between two expansion_nts.

Parameters
[in]rhsthe expansion_nt to be multiplied by this expansion_nt
Returns
the product between this expansion_nt and rhs

◆ operator*() [2/2]

expansion_nt GEO::expansion_nt::operator* ( double  rhs) const

Computes the product between an expansion_nt and a double.

Parameters
[in]rhsthe double to be multiplied by this expansion_nt
Returns
the product between this expansion_nt and rhs

◆ operator*=() [1/2]

expansion_nt& GEO::expansion_nt::operator*= ( const expansion_nt rhs)

Multiplies this expansion_nt by an expansion_nt.

Parameters
[in]rhsthe expansion_nt to multiply this expansion_nt by
Returns
the new value of this expansion_nt

◆ operator*=() [2/2]

expansion_nt& GEO::expansion_nt::operator*= ( double  rhs)

Multiplies this expansion_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 scale_fast() instead.

Parameters
[in]rhsthe double to multiply this expansion_nt with
Returns
the new value of this expansion_nt

◆ operator+() [1/2]

expansion_nt GEO::expansion_nt::operator+ ( const expansion_nt rhs) const

Computes the sum of two expansion_nts.

Parameters
[in]rhsthe expansion_nt to be added to this expansion_nt
Returns
the sum of this expansion_nt and rhs

◆ operator+() [2/2]

expansion_nt GEO::expansion_nt::operator+ ( double  rhs) const

Computes the sum of an expansion_nt and a double.

Parameters
[in]rhsthe double to be added to this expansion_nt
Returns
the sum of this expansion_nt and rhs

◆ operator+=() [1/2]

expansion_nt& GEO::expansion_nt::operator+= ( const expansion_nt rhs)

Adds an expansion_nt to this expansion_nt.

Parameters
[in]rhsthe expansion_nt to be added to this expansion_nt
Returns
the new value of this expansion_nt

◆ operator+=() [2/2]

expansion_nt& GEO::expansion_nt::operator+= ( double  rhs)

Adds a double to this expansion_nt.

Parameters
[in]rhsthe double to be added to this expansion_nt
Returns
the new value of this expansion_nt

◆ operator-() [1/3]

expansion_nt GEO::expansion_nt::operator- ( ) const

Computes the opposite of this expansion_nt.

Returns
the opposite of this expansion_nt

◆ operator-() [2/3]

expansion_nt GEO::expansion_nt::operator- ( const expansion_nt rhs) const

Computes the difference between two expansion_nts.

Parameters
[in]rhsthe expansion_nt to be subtracted from this expansion_nt
Returns
the difference between this expansion_nt and rhs

◆ operator-() [3/3]

expansion_nt GEO::expansion_nt::operator- ( double  rhs) const

Computes the difference between an expansion_nt and a double.

Parameters
[in]rhsthe double to be subtracted from this expansion_nt
Returns
the difference between this expansion_nt and rhs

◆ operator-=() [1/2]

expansion_nt& GEO::expansion_nt::operator-= ( const expansion_nt rhs)

Subtracts an expansion_nt to this expansion_nt.

Parameters
[in]rhsthe expansion_nt to be subtracted
Returns
the new value of this expansion_nt

◆ operator-=() [2/2]

expansion_nt& GEO::expansion_nt::operator-= ( double  rhs)

Subtracts a double from this expansion_nt.

Parameters
[in]rhsthe double to be subtracted from this expansion_nt
Returns
the new value of this expansion_nt

◆ operator<() [1/2]

bool GEO::expansion_nt::operator< ( const expansion_nt rhs) const
inline

Compares this expansion_nt with another one.

Internally computes the sign of the difference between this expansion_nt and rhs.

Returns
true if this expansion_nt is smaller than rhs, false otherwise

Definition at line 475 of file expansion_nt.h.

◆ operator<() [2/2]

bool GEO::expansion_nt::operator< ( double  rhs) const
inline

Compares this expansion_nt with another one.

Internally computes the sign of the difference between this expansion_nt and rhs.

Returns
true if this expansion_nt is smaller than rhs, false otherwise

Definition at line 519 of file expansion_nt.h.

◆ operator<=() [1/2]

bool GEO::expansion_nt::operator<= ( const expansion_nt rhs) const
inline

Compares this expansion_nt with another one.

Internally computes the sign of the difference between this expansion_nt and rhs.

Returns
true if this expansion_nt is smaller or equal than rhs, false otherwise

Definition at line 486 of file expansion_nt.h.

◆ operator<=() [2/2]

bool GEO::expansion_nt::operator<= ( double  rhs) const
inline

Compares this expansion_nt with another one.

Internally computes the sign of the difference between this expansion_nt and rhs.

Returns
true if this expansion_nt is smaller or equal than rhs, false otherwise

Definition at line 530 of file expansion_nt.h.

◆ operator=() [1/2]

expansion_nt& GEO::expansion_nt::operator= ( const expansion_nt rhs)
inline

Assignment operator.

Parameters
[in]rhsthe expansion to be copied
Returns
the new value of this expansion (rhs)

Definition at line 281 of file expansion_nt.h.

◆ operator=() [2/2]

expansion_nt& GEO::expansion_nt::operator= ( expansion_nt &&  rhs)
inline

Assignment operator with move semantics.

Parameters
[in]rhsthe expansion to be copied
Returns
the new value of this expansion (rhs)

Definition at line 294 of file expansion_nt.h.

◆ operator>() [1/2]

bool GEO::expansion_nt::operator> ( const expansion_nt rhs) const
inline

Compares this expansion_nt with another one.

Internally computes the sign of the difference between this expansion_nt and rhs.

Returns
true if this expansion_nt is greater than rhs, false otherwise

Definition at line 453 of file expansion_nt.h.

◆ operator>() [2/2]

bool GEO::expansion_nt::operator> ( double  rhs) const
inline

Compares this expansion_nt with another one.

Internally computes the sign of the difference between this expansion_nt and rhs.

Returns
true if this expansion_nt is greater than rhs, false otherwise

Definition at line 497 of file expansion_nt.h.

◆ operator>=() [1/2]

bool GEO::expansion_nt::operator>= ( const expansion_nt rhs) const
inline

Compares this expansion_nt with another one.

Internally computes the sign of the difference between this expansion_nt and rhs.

Returns
true if this expansion_nt is greater or equal than rhs, false otherwise

Definition at line 464 of file expansion_nt.h.

◆ operator>=() [2/2]

bool GEO::expansion_nt::operator>= ( double  rhs) const
inline

Compares this expansion_nt with another one.

Internally computes the sign of the difference between this expansion_nt and rhs.

Returns
true if this expansion_nt is greater or equal than rhs, false otherwise

Definition at line 508 of file expansion_nt.h.

◆ optimize()

void GEO::expansion_nt::optimize ( )
inline

Optimizes the internal representation without changing the represented value.

this function can reduce the length of an expansion

Definition at line 316 of file expansion_nt.h.

◆ rep() [1/2]

expansion& GEO::expansion_nt::rep ( )
inline

Gets the internal expansion that represents this expansion_nt.

Returns
a reference to the expansion that represents this expansion_nt
Note
most client code will not need to use this (advanced use only).

Definition at line 597 of file expansion_nt.h.

◆ rep() [2/2]

const expansion& GEO::expansion_nt::rep ( ) const
inline

Gets the internal expansion that represents this expansion_nt.

Returns
a const reference to the expansion that represents this expansion_nt
Note
most client code will not need to use this (advanced use only).

Definition at line 609 of file expansion_nt.h.

◆ sign()

Sign GEO::expansion_nt::sign ( ) const
inline

Gets the sign of this expansion_nt.

Returns
the sign of this expansion_nt, computed exactly.

Definition at line 549 of file expansion_nt.h.

◆ to_string()

std::string GEO::expansion_nt::to_string ( ) const
inline

Gets a string representation of this expansion.

Returns
a string with the length and components or "null" if this expansion_nt was explicitely set to uninitialized.

Definition at line 618 of file expansion_nt.h.

Friends And Related Function Documentation

◆ expansion_nt_dot_at()

expansion_nt expansion_nt_dot_at ( const double *  a,
const double *  b,
const double *  c,
coord_index_t  dim 
)
related

Computes an expansion that represents the dot product of two vectors determined by three points.

Parameters
[in]aan array of dim doubles
[in]ban array of dim doubles
[in]can array of dim doubles
[in]dimthe dimension of the points
Returns
an expansion_nt that represents the exact dot product (a - c).(b - c)

Definition at line 807 of file expansion_nt.h.

◆ expansion_nt_sq_dist()

expansion_nt expansion_nt_sq_dist ( const double *  a,
const double *  b,
coord_index_t  dim 
)
related

Computes an expansion that represents the square distance between two points.

Parameters
[in]aan array of dim doubles
[in]ban array of dim doubles
[in]dimthe dimension of the points
Returns
an expansion_nt that represent the exact squared distance between a and b

Definition at line 786 of file expansion_nt.h.

◆ operator!=() [1/3]

bool operator!= ( const expansion_nt a,
const expansion_nt b 
)
related

Tests whether two expansion_nts differ.

Implemented by testing whether the difference between a and b is different from 0.

Returns
true if a and b do not represent the same exact value, false otherwise

Definition at line 748 of file expansion_nt.h.

◆ operator!=() [2/3]

bool operator!= ( const expansion_nt a,
double  b 
)
related

Tests whether an expansion_nt differs from a double.

Implemented by testing whether the difference between a and b is different from 0.

Returns
true if a and b do not represent the same exact value, false otherwise

Definition at line 760 of file expansion_nt.h.

◆ operator!=() [3/3]

bool operator!= ( double  a,
const expansion_nt b 
)
related

Tests whether a double differs from an expansion_nt.

Implemented by testing whether the difference between a and b is different from 0.

Returns
true if a and b do not represent the same exact value, false otherwise

Definition at line 772 of file expansion_nt.h.

◆ operator*()

expansion_nt operator* ( double  a,
const expansion_nt b 
)
related

Computes the product of a double and an expansion_nt.

Parameters
[in]athe double
[in]bthe expansion_nt to be multiplied
Returns
an expansion_nt that represents a * b

Definition at line 700 of file expansion_nt.h.

◆ operator+()

expansion_nt operator+ ( double  a,
const expansion_nt b 
)
related

Computes the sum of a double and an expansion_nt.

Parameters
[in]athe double to be added
[in]bthe expansion_nt to be added
Returns
an expansion_nt that represents a + b

Definition at line 676 of file expansion_nt.h.

◆ operator-()

expansion_nt operator- ( double  a,
const expansion_nt b 
)
related

Computes the difference between a double and an expansion_nt.

Parameters
[in]athe double
[in]bthe expansion_nt to be subtracted
Returns
an expansion_nt that represents a - b

Definition at line 687 of file expansion_nt.h.

◆ operator==() [1/3]

bool operator== ( const expansion_nt a,
const expansion_nt b 
)
related

Tests equality between two expansion_nts.

Implemented by testing whether the difference between a and b is 0.

Returns
true if a and b represent exactly the same value, false otherwise

Definition at line 712 of file expansion_nt.h.

◆ operator==() [2/3]

bool operator== ( const expansion_nt a,
double  b 
)
related

Tests equality between an expansion_nt and a double.

Implemented by testing whether the difference between a and b is 0.

Returns
true if a and b represent exactly the same value, false otherwise

Definition at line 724 of file expansion_nt.h.

◆ operator==() [3/3]

bool operator== ( double  a,
const expansion_nt b 
)
related

Tests equality between a double and an expansion_nt.

Implemented by testing whether the difference between a and b is 0.

Returns
true if a and b represent exactly the same value, false otherwise

Definition at line 736 of file expansion_nt.h.


The documentation for this class was generated from the following file: