40#ifndef GEOGRAM_NUMERICS_EXPANSION_NT
41#define GEOGRAM_NUMERICS_EXPANSION_NT
103 rep_ = expansion::new_expansion_on_heap(1);
115 rep_ = expansion::new_expansion_on_heap(rhs.
length());
137 rep_ = expansion::new_expansion_on_heap(
138 expansion::sum_capacity(x,y)
140 rep_->assign_sum(x,y);
143 rep_ = expansion::new_expansion_on_heap(
144 expansion::diff_capacity(x,y)
146 rep_->assign_diff(x,y);
149 rep_ = expansion::new_expansion_on_heap(
150 expansion::product_capacity(x,y)
152 rep_->assign_product(x,y);
176 rep_ = expansion::new_expansion_on_heap(
177 expansion::sum_capacity(x,y,z)
179 rep_->assign_sum(x,y,z);
185 rep_ = expansion::new_expansion_on_heap(
186 expansion::product_capacity(x,y,z)
188 rep_->assign_product(x,y,z);
213 rep_ = expansion::new_expansion_on_heap(
214 expansion::sum_capacity(x,y,z,t)
216 rep_->assign_sum(x,y,z,t);
222 const expansion& p1 = expansion_product(x,y);
223 const expansion& p2 = expansion_product(z,t);
224 rep_ = expansion::new_expansion_on_heap(
225 expansion::product_capacity(p1,p2)
227 rep_->assign_sum(p1,p2);
248 rep_ = expansion::new_expansion_on_heap(
249 expansion::sum_capacity(x,y)
251 rep_->assign_sum(x,y);
254 rep_ = expansion::new_expansion_on_heap(
255 expansion::diff_capacity(x,y)
257 rep_->assign_diff(x,y);
260 rep_ = expansion::new_expansion_on_heap(
261 expansion::product_capacity(x,y)
263 rep_->assign_product(x,y);
283 std::swap(rep_, rhs.rep_);
307 std::swap(rep_, rhs.rep_);
438 return rep().compare(rhs.
rep());
446 return rep().compare(rhs);
457 return (
int(compare(rhs))>0);
468 return (
int(compare(rhs))>=0);
479 return (
int(compare(rhs))<0);
490 return (
int(compare(rhs))<=0);
500 bool operator> (
double rhs)
const {
501 return (
int(compare(rhs))>0);
511 bool operator>= (
double rhs)
const {
512 return (
int(compare(rhs))>=0);
522 bool operator< (
double rhs)
const {
523 return (
int(compare(rhs))<0);
533 bool operator<= (
double rhs)
const {
534 return (
int(compare(rhs))<=0);
545 return rep().estimate();
564 return rep().length();
622 return (rep_ ==
nullptr) ?
623 std::string(
"null") :
636 if(rhs.rep_ ==
nullptr) {
639 rep_ = expansion::new_expansion_on_heap(rhs.
rep().
capacity());
641 for(
index_t i=0; i<rep_->length(); ++i) {
642 (*rep_)[i] = rhs.
rep()[i];
651 if(rep_ !=
nullptr) {
652 expansion::delete_expansion_on_heap(rep_);
666 const double* a,
const double* b,
const double* c,
811 const double* a,
const double* b,
const double* c,
coord_index_t dim
1080 : num_(num), denom_(denom) {
1089 : num_(num), denom_(denom) {
1100 ) : num_(num), denom_(denom) {
1117 denom_(rhs.denom_) {
1127 denom_ = rhs.denom_;
1138 denom_ = rhs.denom_;
1192 if(has_same_denom(rhs)) {
1195 num_ = num_ * rhs.denom_ + rhs.num_ * denom_;
1196 denom_ *= rhs.denom_;
1207 if(has_same_denom(rhs)) {
1210 num_ = num_ * rhs.denom_ - rhs.num_ * denom_;
1211 denom_ *= rhs.denom_;
1223 denom_ *= rhs.denom_;
1244 num_ += denom_ * rhs;
1254 num_ -= denom_ * rhs;
1292 if(has_same_denom(rhs)) {
1299 num_ * rhs.denom_ + rhs.num_ * denom_,
1311 if(has_same_denom(rhs)) {
1318 num_ * rhs.denom_ - rhs.num_ * denom_,
1357 num_ + rhs * denom_,
1369 num_ - rhs * denom_,
1433 return (
int(compare(rhs))>0);
1444 return (
int(compare(rhs))>=0);
1455 return (
int(compare(rhs))<0);
1466 return (
int(compare(rhs))<=0);
1476 bool operator> (
double rhs)
const {
1477 return (
int(compare(rhs))>0);
1487 bool operator>= (
double rhs)
const {
1488 return (
int(compare(rhs))>=0);
1498 bool operator< (
double rhs)
const {
1499 return (
int(compare(rhs))<0);
1509 bool operator<= (
double rhs)
const {
1510 return (
int(compare(rhs))<=0);
1521 return num_.estimate() / denom_.estimate();
1530 return Sign(num_.sign() * denom_.sign());
1540 denom_ = rhs.denom_;
1554 return denom_ == rhs.denom_;
#define geo_assert_not_reached
Sets a non reachable point in the program.
#define geo_debug_assert(x)
Verifies that a condition is met.
Common include file, providing basic definitions. Should be included before anything else by all head...
Expansion_nt (expansion Number Type) is used to compute the sign of polynoms exactly.
expansion_nt(double x=0.0)
Constructs a new expansion_nt from a double.
const expansion & rep() const
Gets the internal expansion that represents this expansion_nt.
double estimate() const
Computes an approximation of the stored value in this expansion.
void copy(const expansion_nt &rhs)
Copies an expansion into this one.
Sign sign() const
Gets the sign of this expansion_nt.
expansion & rep()
Gets the internal expansion that represents this expansion_nt.
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.
double component(index_t i) const
Gets the i-th component of this expansion.
~expansion_nt()
Expansion_nt destructor.
std::string to_string() const
Gets a string representation of this expansion.
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.
expansion_nt(expansion_nt &&rhs)
Move-constructor.
expansion_nt(UninitializedType uninitialized)
Constructs an uninitialized expansion_nt.
expansion_nt(Operation op, const expansion &x, const expansion &y, const expansion &z)
Constructs a new expansion_nt from three expansions.
UninitializedType
This type is used to overload expression_nt constructors with a version that does not create an expan...
expansion_nt(const expansion &rhs)
Constructs a new expansion_nt from an expansion.
void cleanup()
Cleanups the memory associated with this expansion_nt.
index_t length() const
Gets the length of this expansion.
void optimize()
Optimizes the internal representation without changing the represented value.
expansion_nt(Operation op, const expansion &x, const expansion &y)
Constructs a new expansion_nt from two expansions.
Sign compare(const expansion_nt &rhs) const
Compares two expansion_nt.
expansion_nt(expansion *rep)
Constructs a new expansion_nt from an expansion.
expansion_nt(Operation op, double x, double y)
Constructs a new expansion_nt from two doubles.
expansion_nt(Operation op, const expansion &x, const expansion &y, const expansion &z, const expansion &t)
Constructs a new expansion_nt from four expansions.
Operation
This type is used by the constructor that takes two expansion.
expansion_nt(const expansion_nt &rhs)
Copy-constructor.
Sign compare(double rhs) const
Compares an expansion_nt with a double.
Represents numbers in arbitrary precision with a low-level API.
index_t length() const
Gets the length of this expansion.
bool equals(const expansion &rhs) const
Compares two expansions.
index_t capacity() const
Gets the capacity of this expansion.
expansion & assign_dot_at(const double *p1, const double *p2, const double *p0, coord_index_t dim)
Assigns the dot product of two vectors to this expansion (should not be used by client code).
static index_t sq_dist_capacity(coord_index_t dim)
Computes the required capacity of an expansion to store the exact squared distance between two points...
expansion & negate()
Changes the sign of an expansion.
static index_t square_capacity(double a)
Computes the required capacity of an expansion to store the exact square of a double.
static index_t dot_at_capacity(coord_index_t dim)
Computes the required capacity of an expansion to store the exact dot product between two vectors.
static expansion * new_expansion_on_heap(index_t capa)
Allocates an expansion on the heap.
expansion & assign_square(double a)
Assigns the square of a double to this expansion (should not be used by client code).
expansion & assign_sq_dist(const double *p1, const double *p2, coord_index_t dim)
Assigns the squared distance between two points to this expansion (should not be used by client code)...
Sign sign() const
Gets the sign of the expansion.
Rational_nt (rational Number Type) is used to compute the sign of rational fractions exactly.
expansion_nt & num()
gets the numerator.
Sign compare(const rational_nt &rhs) const
Compares two rational_nt.
rational_nt(double num, double denom)
Constructs a new rational_nt from two doubles.
rational_nt(const expansion_nt &x)
Constructs a new rational_nt from an expansion_nt.
void copy(const rational_nt &rhs)
Copies a rational into this one.
rational_nt(const rational_nt &rhs)
Copy-constructor.
rational_nt(expansion_nt &&x)
Constructs a new rational_nt from an expansion_nt with move semantics.
double estimate() const
Computes an approximation of the stored value in this rational.
rational_nt(rational_nt &&rhs)
Move-constructor.
expansion_nt & denom()
gets the denominator.
const expansion_nt & denom() const
gets the denominator.
const expansion_nt & num() const
gets the numerator.
UninitializedType
This type is used to overload expression_nt constructors with a version that does not create an expan...
void optimize()
Optimizes the internal representation without changing the represented value.
Sign sign() const
Gets the sign of this rational_nt.
rational_nt(UninitializedType uninitialized)
Constructs an uninitialized rational_nt.
Sign compare(double rhs) const
Compares a rational_nt with a double.
rational_nt(const expansion_nt &num, const expansion_nt &denom)
Constructs a new rational_nt from two expansion_nt.
bool has_same_denom(const rational_nt &rhs) const
Tests whether a rational_nt has trivially the same denominator as this rational_nt.
rational_nt(double x=0.0)
Constructs a new rational_nt from a double.
rational_nt(expansion_nt &&num, expansion_nt &&denom)
Constructs a new rational_nt from two expansion_nt with move semantics.
std::ostream & operator<<(std::ostream &os, const GEO::expansion_nt &a)
Displays the approximated value of an expansion_nt to a stream.
std::istream & operator>>(std::istream &is, GEO::expansion_nt &a)
Reads a double precision number from a stream and converts it to an approximation.
Implementation of multi-precision arithmetics.
Global Vorpaline namespace.
bool expansion_nt_is_zero(const expansion_nt &x)
Tests whether an expansion_nt is zero.
Quaternion operator-(const Quaternion &a, const Quaternion &b)
Computes the difference between two Quaternion.
void geo_argused(const T &)
Suppresses compiler warnings about unused parameters.
expansion_nt expansion_nt_determinant(const expansion_nt &a00, const expansion_nt &a01, const expansion_nt &a10, const expansion_nt &a11)
Computes a 2x2 determinant.
T det3x3(const T &a11, const T &a12, const T &a13, const T &a21, const T &a22, const T &a23, const T &a31, const T &a32, const T &a33)
Computes a three-by-three determinant.
T det4x4(const T &a11, const T &a12, const T &a13, const T &a14, const T &a21, const T &a22, const T &a23, const T &a24, const T &a31, const T &a32, const T &a33, const T &a34, const T &a41, const T &a42, const T &a43, const T &a44)
Computes a four-by-four determinant.
Sign geo_sgn(const T &x)
Gets the sign of a value.
expansion_nt expansion_nt_square(const expansion_nt &x)
Computes the square of an expansion_nt.
geo_index_t index_t
The type for storing and manipulating indices.
Sign expansion_nt_compare(const expansion_nt &x, const expansion_nt &y)
Compares two expansion_nt.
Sign
Integer constants that represent the sign of a value.
T det2x2(const T &a11, const T &a12, const T &a21, const T &a22)
Computes a two-by-two determinant.
bool expansion_nt_is_one(const expansion_nt &x)
Tests whether an expansion_nt is equal to one.
Quaternion operator+(const Quaternion &a, const Quaternion &b)
Computes the sum of two Quaternion.
vecng< DIM, FT > operator*(const Matrix< DIM, FT > &M, const vecng< DIM, FT > &x)
Computes a matrix vector product.
geo_coord_index_t coord_index_t
The type for storing coordinate indices, and iterating on the coordinates of a point.