40#ifndef GEOGRAM_BASIC_RATIONALG
41#define GEOGRAM_BASIC_RATIONALG
69 explicit rationalg(
double x) : num_(x), denom_(1.0) {
76 explicit rationalg(
const T& x) : num_(x), denom_(1.0) {
194 num_ = num_ * rhs.denom_ + rhs.num_ * denom_;
195 denom_ *= rhs.denom_;
209 num_ = num_ * rhs.denom_ - rhs.num_ * denom_;
210 denom_ *= rhs.denom_;
222 denom_ *= rhs.denom_;
243 num_ += denom_ * T(rhs);
253 num_ -= denom_ * T(rhs);
298 num_ * rhs.denom_ + rhs.num_ * denom_,
317 num_ * rhs.denom_ - rhs.num_ * denom_,
356 num_ + T(rhs) * denom_,
368 num_ - T(rhs) * denom_,
418 return Sign(num_.sign() * denom_.sign());
432 return Sign(num_.compare(rhs.num_) * denom_.sign());
435 (num_ * rhs.denom_).compare(rhs.num_ * denom_) *
436 denom_.sign() * rhs.denom_.sign()
446 num_.compare(T(rhs)*denom_) * denom_.sign()
546 return num_.estimate() / denom_.estimate();
570 return denom_ == rhs.denom_;
602 result.
num().negate();
#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...
rationalg (generic rational) is used to compute the sign of rational fractions exactly.
rationalg< T > operator-() const
Computes the opposite of this rationalg.
rationalg(const T &x)
Constructs a new rationalg from an T.
Sign sign() const
Gets the sign of a rationalg.
rationalg(const T &num, const T &denom)
Constructs a new rationalg from two T.
bool operator<=(const rationalg< T > &rhs) const
Compares this rationalg with another one.
bool operator>=(const rationalg< T > &rhs) const
Compares this rationalg with another one.
rationalg< T > operator*(const rationalg< T > &rhs) const
Computes the product between two rationalgs.
T & num()
gets the numerator.
rationalg< T > & operator/=(const rationalg< T > &rhs)
Divides this rationalg by a rationalg.
rationalg< T > & operator+=(const rationalg< T > &rhs)
Adds a rationalg to this rationalg.
rationalg< T > & operator*=(const rationalg< T > &rhs)
Multiplies this rationalg by a rationalg.
rationalg< T > operator/(const rationalg< T > &rhs) const
Computes the ratio between two rationalgs.
rationalg(T &&x)
Constructs a new rationalg from an T with move semantics.
const T & num() const
gets the numerator.
Sign compare(double rhs) const
Compares a rationalg with a double.
T & denom()
gets the denominator.
void copy(const rationalg< T > &rhs)
Copies a rational into this one.
rationalg< T > operator+(const rationalg< T > &rhs) const
Computes the sum of two rationalgs.
rationalg(double x)
Constructs a new rationalg from a double.
rationalg< T > & operator=(const rationalg< T > &rhs)=default
Assignment operator.
rationalg(T &&num, T &&denom)
Constructs a new rationalg from two T with move semantics.
bool has_same_denom(const rationalg< T > &rhs) const
Tests whether a rationalg has trivially the same denominator this rationalg.
rationalg< T > & operator-=(const rationalg< T > &rhs)
Subtracts a rationalg to this rationalg.
Sign compare(const rationalg< T > &rhs) const
Compares two rationalg.
double estimate() const
Computes an approximation of the stored value in this rational.
rationalg(rationalg< T > &&rhs)=default
Move-constructor.
rationalg(double num, double denom)
Constructs a new rationalg from two doubles.
bool operator>(const rationalg< T > &rhs) const
Compares this rationalg with another one.
const T & denom() const
gets the denominator.
rationalg(const rationalg< T > &rhs)=default
Copy-constructor.
void optimize()
Optimizes the internal representation without changing the represented value.
bool operator<(const rationalg< T > &rhs) const
Compares this rationalg with another one.
void optimize_number_representation(T &x)
place holder for optimizing internal number representation
Global Vorpaline namespace.
Quaternion operator-(const Quaternion &a, const Quaternion &b)
Computes the difference between two Quaternion.
Sign geo_sgn(const T &x)
Gets the sign of a value.
Sign
Integer constants that represent the sign of a value.
Sign geo_cmp(const T &a, const T &b)
Compares two values.
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.