13 #ifndef INCLUDED_FROM_NUMBERS_H
14 static_assert(
false,
"This file may only be included indirectly by numbers.h");
32 template<
typename Number>
35 template<
typename FloatType>
44 template<
typename T1,
typename T2>
68 if ((errno == ERANGE && l == LDBL_MAX) || l > DBL_MAX) {
71 if ((errno == ERANGE && l == LDBL_MIN) || l < DBL_MIN) {
74 if (*s ==
'\0' || *end !=
'\0') {
82 template<
typename Number>
93 assert(maxUlps > 0 && maxUlps < 4 * 1024 * 1024);
94 sint aInt = *
reinterpret_cast<const sint*
>(&
A);
97 aInt =
static_cast<sint>(0x8000000000000000) - aInt;
99 sint bInt = *
reinterpret_cast<const sint*
>(&B);
101 bInt =
static_cast<sint>(0x8000000000000000) - bInt;
102 auto intDiff =
static_cast<uint>(
std::abs(aInt - bInt));
103 return intDiff <= maxUlps;
112 template<
typename FloatType>
185 template<
typename F = FloatType, DisableIf< std::is_same<F,
double> > = dummy>
191 template<
typename F = FloatType, EnableIf< carl::is_rational_type<F> > = dummy>
197 template<
typename F = FloatType, EnableIf< std::is_same<F,
double> > = dummy>
199 mValue(std::stod(_string))
508 assert(
false &&
"not implemented");
524 assert(
false &&
"not implemented");
978 explicit operator int()
const
990 explicit operator long()
const
992 return carl::to_int<long>(
mValue);
999 explicit operator double()
const
1004 explicit operator mpq_class()
const {
1008 #ifdef USE_CLN_NUMBERS
1009 explicit operator cln::cl_RA()
const {
1010 return carl::rationalize<cln::cl_RA>(
mValue);
1161 x.
pow(res,
unsigned(y));
1353 template<
typename FloatType>
1364 template<
typename FloatType>
1369 result = _lhs / _rhs;
1379 template<
typename FloatType>
1384 result = _lhs / _rhs;
1394 template<
typename Integer,
typename FloatType>
1397 return carl::to_int<Integer>(_float.
value());
1400 template<
typename FloatType>
1403 return double(_float);
1411 template<
typename FloatType>
1424 template<
typename FloatType>
1437 template<
typename FloatType>
1445 template<
typename FloatType>
1451 template<
typename FloatType>
1455 _in.
pow(result, _exp);
1459 template<
typename FloatType>
1467 template<
typename FloatType>
1475 template<
typename FloatType>
1483 template<
typename FloatType>
1491 template<
typename FloatType>
1505 template<
typename FloatType>
1519 template<
typename FloatType>
1528 inline FLOAT_T<double> rationalize<FLOAT_T<double>>(
double n)
1530 return FLOAT_T<double>(n);
1534 inline FLOAT_T<float> rationalize<FLOAT_T<float>>(
float n)
1536 return FLOAT_T<float>(n);
1540 inline FLOAT_T<mpq_class> rationalize<FLOAT_T<mpq_class>>(
double n)
1545 #ifdef USE_CLN_NUMBERS
1548 inline FLOAT_T<cln::cl_RA> rationalize<FLOAT_T<cln::cl_RA>>(
double n)
1550 return FLOAT_T<cln::cl_RA>(carl::rationalize<cln::cl_RA>(n));
1558 inline cln::cl_I
get_denom(
const FLOAT_T<cln::cl_RA>& _in)
1568 inline cln::cl_I
get_num(
const FLOAT_T<cln::cl_RA>& _in)
1593 template<
typename FloatType>
1598 template<
typename FloatType>
1600 return _in.
value() == std::numeric_limits<FloatType>::infinity();
1603 template<
typename FloatType>
1605 return _in.
value() == std::numeric_limits<FloatType>::quiet_NaN();
1618 template<
typename Number>
1619 struct hash<
carl::FLOAT_T<Number>> {
1621 return hasher(_in.
value());
1627 template<
typename Number>
1628 class numeric_limits<
carl::FLOAT_T<Number>>
1631 static const bool is_specialized =
true;
1632 static const bool is_signed =
true;
1634 static const bool is_exact =
false;
1635 static const int radix = 2;
1637 static const bool has_infinity =
true;
1638 static const bool has_quiet_NaN =
true;
1639 static const bool has_signaling_NaN =
true;
1641 static const bool is_iec559 =
true;
1642 static const bool is_bounded =
true;
1643 static const bool is_modulo =
false;
1644 static const bool traps =
true;
1645 static const bool tinyness_before =
true;
1661 static const int min_exponent = std::numeric_limits<Number>::min_exponent;
1662 static const int max_exponent = std::numeric_limits<Number>::max_exponent;
1663 static const int min_exponent10 = std::numeric_limits<Number>::min_exponent10;
1664 static const int max_exponent10 = std::numeric_limits<Number>::max_exponent10;
1666 inline static float_round_style
round_style() {
return std::numeric_limits<Number>::round_style; }
1668 inline static int digits() {
return std::numeric_limits<Number>::digits; }
1669 inline static int digits10() {
return std::numeric_limits<Number>::digits10; }
1670 inline static int max_digits10() {
return std::numeric_limits<Number>::max_digits10; }
States if a type represents a subset of all integers.
carl is the main namespace for the library.
bool is_integer(const FLOAT_T< FloatType > &in)
Interval< Number > acos(const Interval< Number > &i)
FLOAT_T< FloatType > atan(const FLOAT_T< FloatType > &_in)
Interval< Number > ceil(const Interval< Number > &_in)
Method which returns the next larger integer of the passed number or the number itself,...
FLOAT_T< FloatType > pow(const FLOAT_T< FloatType > &_in, size_t _exp)
bool AlmostEqual2sComplement(const Number &A, const Number &B, unsigned=128)
std::string toString(Relation r)
Interval< Number > abs(const Interval< Number > &_in)
Method which returns the absolute value of the passed number.
Interval< Number > floor(const Interval< Number > &_in)
Method which returns the next smaller integer of this number or the number itself,...
Interval< Number > quotient(const Interval< Number > &_lhs, const Interval< Number > &_rhs)
Implements the division with remainder.
mpq_class rationalize< mpq_class >(float n)
Interval< Number > tan(const Interval< Number > &i)
FLOAT_T< FloatType > log(const FLOAT_T< FloatType > &_in)
Method which returns the logarithm of the passed number.
Interval< Number > exp(const Interval< Number > &i)
FLOAT_T< FloatType > acos(const FLOAT_T< FloatType > &_in)
Interval< Number > atanh(const Interval< Number > &i)
bool is_zero(const Interval< Number > &i)
Check if this interval is a point-interval containing 0.
Integer to_int(const Interval< Number > &_floatInterval)
Casts the Interval to an arbitrary integer type which has a constructor for a native int.
cln::cl_I get_num(const cln::cl_RA &n)
Extract the numerator from a fraction.
Interval< Number > atan(const Interval< Number > &i)
Interval< Number > cos(const Interval< Number > &i)
Interval< Number > sqrt(const Interval< Number > &i)
bool AlmostEqual2sComplement< double >(const double &A, const double &B, unsigned maxUlps)
T parse(const std::string &n)
FLOAT_T< FloatType > asin(const FLOAT_T< FloatType > &_in)
BasicConstraint< ToPoly > convert(const typename ToPoly::ContextType &context, const BasicConstraint< FromPoly > &c)
Interval< Number > asin(const Interval< Number > &i)
FLOAT_T< FloatType > abs(const FLOAT_T< FloatType > &_in)
Method which returns the absolute value of the passed number.
Interval< Number > div(const Interval< Number > &_lhs, const Interval< Number > &_rhs)
Implements the division which assumes that there is no remainder.
Interval< Number > log(const Interval< Number > &i)
FLOAT_T< FloatType > sqrt(const FLOAT_T< FloatType > &_in)
Method which returns the square root of the passed number.
FLOAT_T< FloatType > ceil(const FLOAT_T< FloatType > &_in)
Method which returns the next larger integer of the passed number or the number itself,...
bool is_integer(const Interval< Number > &n)
cln::cl_I get_denom(const cln::cl_RA &n)
Extract the denominator from a fraction.
double to_double(const cln::cl_RA &n)
Converts the given fraction to a double.
bool isNan(const FLOAT_T< FloatType > &_in)
Interval< Number > sin(const Interval< Number > &i)
Interval< Number > sinh(const Interval< Number > &i)
Interval< Number > tanh(const Interval< Number > &i)
std::pair< cln::cl_RA, cln::cl_RA > sqrt_safe(const cln::cl_RA &a)
Calculate the square root of a fraction.
Interval< Number > acosh(const Interval< Number > &i)
Interval< Number > asinh(const Interval< Number > &i)
bool isInfinity(const FLOAT_T< FloatType > &_in)
Interval< Number > cosh(const Interval< Number > &i)
Str2Double_Error str2double(double &d, char const *s)
Interval< Number > pow(const Interval< Number > &i, Integer exp)
The class which contains the interval arithmetic including trigonometric functions.
Templated wrapper class which allows universal usage of different IEEE 754 implementations.
FLOAT_T & atanh(FLOAT_T &_result, CARL_RND=CARL_RND::N) const
Function which calculates the hyperbolic arcus tangent of this number and puts it into a passed resul...
FLOAT_T & sin_assign(CARL_RND=CARL_RND::N)
Assigns the number the sine of this number.
FLOAT_T & cos(FLOAT_T &_result, CARL_RND=CARL_RND::N) const
Function which calculates the cosine of this number and puts it into a passed result parameter.
FLOAT_T & floor(FLOAT_T &_result, CARL_RND=CARL_RND::N) const
Function which calculates the floor of this number and puts it into a passed result parameter.
FLOAT_T ei_log(const FLOAT_T &x)
Function required for extension of Eigen3 with FLOAT_T as a custom type which calculates the logarith...
bool operator==(const FLOAT_T &_rhs) const
Comparison operator for equality.
const FLOAT_T & ei_real(const FLOAT_T &x)
Function required for extension of Eigen3 with FLOAT_T as a custom type which calculates the real par...
bool operator>(int _rhs) const
FLOAT_T & cbrt(FLOAT_T &_result, CARL_RND=CARL_RND::N) const
Returns the cubic root of this number and puts it into a passed result parameter.
FLOAT_T & add_assign(const FLOAT_T &_op2, CARL_RND=CARL_RND::N)
Function for addition of two numbers, which assigns the result to the calling number.
FLOAT_T()
Default empty constructor, which initializes to zero.
bool operator!=(const FLOAT_T &_rhs) const
Comparison operator for inequality.
FLOAT_T & sinh_assign(CARL_RND=CARL_RND::N)
Assigns the number the hyperbolic sine of this number.
FLOAT_T & sinh(FLOAT_T &_result, CARL_RND=CARL_RND::N) const
Function which calculates the hyperbolic sine of this number and puts it into a passed result paramet...
FLOAT_T & operator*=(const FLOAT_T &_rhs)
Operator which multiplicates this number by the righthand side.
friend FLOAT_T operator*(const FLOAT_T &_lhs, const FLOAT_T &_rhs)
Operator for addition of two numbers.
FLOAT_T & ceil_assign(CARL_RND=CARL_RND::N)
Assigns the number the ceiling of this number.
FLOAT_T & log_assign(CARL_RND=CARL_RND::N)
Assigns the number the logarithm of this number.
FLOAT_T ei_imag(const FLOAT_T &)
Function required for extension of Eigen3 with FLOAT_T as a custom type which calculates the imaginar...
FLOAT_T & asinh(FLOAT_T &_result, CARL_RND=CARL_RND::N) const
Function which calculates the hyperbolic arcus sine of this number and puts it into a passed result p...
FLOAT_T ei_abs2(const FLOAT_T &x)
Function required for extension of Eigen3 with FLOAT_T as a custom type which calculates the absolute...
FLOAT_T & cosh(FLOAT_T &_result, CARL_RND=CARL_RND::N) const
Function which calculates the hyperbolic cosine of this number and puts it into a passed result param...
FLOAT_T & floor_assign(CARL_RND=CARL_RND::N)
Assigns the number the floor of this number.
FLOAT_T ei_pow(const FLOAT_T &x, FLOAT_T y)
Function required for extension of Eigen3 with FLOAT_T as a custom type which calculates the power.
FLOAT_T & cosh_assign(CARL_RND=CARL_RND::N)
Assigns the number the hyperbolic cosine of this number.
friend std::ostream & operator<<(std::ostream &ostr, const FLOAT_T &p)
Output stream operator for numbers of type FLOAT_T.
FLOAT_T & operator=(const FLOAT_T &_rhs)=default
Assignment operator.
bool operator>=(const FLOAT_T &_rhs) const
Comparison operator for larger or equal than.
FLOAT_T ei_sin(const FLOAT_T &x)
Function required for extension of Eigen3 with FLOAT_T as a custom type which calculates the sine.
FLOAT_T & abs(FLOAT_T &_result, CARL_RND=CARL_RND::N) const
Function which calculates the absolute value of this number and puts it into a passed result paramete...
FLOAT_T & acosh(FLOAT_T &_result, CARL_RND=CARL_RND::N) const
Function which calculates the hyperbolic arcus cosine of this number and puts it into a passed result...
FLOAT_T & cos_assign(CARL_RND=CARL_RND::N)
Assigns the number the cosine of this number.
double to_double(CARL_RND=CARL_RND::N) const
Function which converts the number to a double value.
FLOAT_T & cbrt_assign(CARL_RND=CARL_RND::N)
Function for the cubic root of the number, which assigns the result to the calling number.
FLOAT_T & root_assign(std::size_t, CARL_RND=CARL_RND::N)
Function for the nth root of the number, which assigns the result to the calling number.
FLOAT_T ei_cos(const FLOAT_T &x)
Function required for extension of Eigen3 with FLOAT_T as a custom type which calculates the cosine.
FLOAT_T(double _double, CARL_RND=CARL_RND::N)
Constructor, which takes a double as input and optional rounding, which can be used,...
FLOAT_T(const FLOAT_T &_float, CARL_RND=CARL_RND::N)
Copyconstructor which takes a FLOAT_T<FloatType> and optional rounding as input, which can be used,...
FLOAT_T & pow(FLOAT_T &_result, std::size_t _exp, CARL_RND=CARL_RND::N) const
Function which calculates the power of this number and puts it into a passed result parameter.
friend FLOAT_T operator+(const FLOAT_T &_lhs, const FLOAT_T &_rhs)
Operator for addition of two numbers.
FLOAT_T & mul(FLOAT_T &_result, const FLOAT_T &_op2, CARL_RND=CARL_RND::N) const
Function which multiplicates two numbers and puts the result in a third number passed as parameter.
FLOAT_T & sin(FLOAT_T &_result, CARL_RND=CARL_RND::N) const
Function which calculates the sine of this number and puts it into a passed result parameter.
FLOAT_T & ceil(FLOAT_T &_result, CARL_RND=CARL_RND::N) const
Function which calculates the ceiling of this number and puts it into a passed result parameter.
std::string toString() const
Method which converts this number to a string.
bool operator<(unsigned _rhs) const
FLOAT_T & log(FLOAT_T &_result, CARL_RND=CARL_RND::N) const
Function which calculates the logarithm of this number and puts it into a passed result parameter.
FLOAT_T operator-()
Operator for unary negation of this number.
FLOAT_T(sint _int, CARL_RND=CARL_RND::N)
Constructor, which takes an integer as input and optional rounding, which can be used,...
precision_t precision() const
If precision is used, this getter returns the acutal precision (default: 53 bit).
FLOAT_T & div(FLOAT_T &_result, const FLOAT_T &_op2, CARL_RND=CARL_RND::N) const
Function which divides this number by the righthand side and puts the result in a third number passed...
FLOAT_T & tan(FLOAT_T &_result, CARL_RND=CARL_RND::N) const
Function which calculates the tangent of this number and puts it into a passed result parameter.
FLOAT_T & acosh_assign(CARL_RND=CARL_RND::N)
Assigns the number the hyperbolic arcus cosine of this number.
FLOAT_T(unsigned _int, CARL_RND=CARL_RND::N)
Constructor, which takes an unsigned integer as input and optional rounding, which can be used,...
FLOAT_T & operator-=(const FLOAT_T &_rhs)
Operator which subtracts the righthand side from this.
friend FLOAT_T operator/(const FLOAT_T &_lhs, const FLOAT_T &_rhs)
Operator for addition of two numbers.
bool operator<=(const FLOAT_T &_rhs) const
Comparison operator for less or equal than.
bool operator<(int _rhs) const
FLOAT_T & sqrt_assign(CARL_RND=CARL_RND::N)
Function for the square root of the number, which assigns the result to the calling number.
FLOAT_T & pow_assign(std::size_t _exp, CARL_RND=CARL_RND::N)
Function for the nth power of the number, which assigns the result to the calling number.
FLOAT_T & atan(FLOAT_T &_result, CARL_RND=CARL_RND::N) const
Function which calculates the arcus tangent of this number and puts it into a passed result parameter...
FLOAT_T & div_assign(const FLOAT_T &_op2, CARL_RND=CARL_RND::N)
Function for division of two numbers, which assigns the result to the calling number.
FLOAT_T & sub_assign(const FLOAT_T &_op2, CARL_RND=CARL_RND::N)
Function for subtraction of two numbers, which assigns the result to the calling number.
FLOAT_T & operator/=(const FLOAT_T &_rhs)
Operator which divides this number by the righthand side.
FLOAT_T & operator+=(const FLOAT_T &_rhs)
Operator which adds the righthand side to this.
const FloatType & value() const
Getter for the raw value contained.
FLOAT_T & asin(FLOAT_T &_result, CARL_RND=CARL_RND::N) const
Function which calculates the arcus sine of this number and puts it into a passed result parameter.
FLOAT_T & tanh(FLOAT_T &_result, CARL_RND=CARL_RND::N) const
Function which calculates the hyperbolic tangent of this number and puts it into a passed result para...
FLOAT_T & tan_assign(CARL_RND=CARL_RND::N)
Assigns the number the tangent of this number.
bool operator>(const FLOAT_T &_rhs) const
Comparison operator for larger than.
FLOAT_T & exp_assign(CARL_RND=CARL_RND::N)
Assigns the number the exponential of this number.
FLOAT_T & tanh_assign(CARL_RND=CARL_RND::N)
Assigns the number the hyperbolic tangent of this number.
FLOAT_T & setPrecision(const precision_t &)
Allows to set the desired precision.
const FLOAT_T & ei_conj(const FLOAT_T &x)
Function required for extension of Eigen3 with FLOAT_T as a custom type which calculates the complex ...
FLOAT_T & acos_assign(CARL_RND=CARL_RND::N)
Assigns the number the arcus cosine of this number.
FLOAT_T & mul_assign(const FLOAT_T &_op2, CARL_RND=CARL_RND::N)
Function for multiplication of two numbers, which assigns the result to the calling number.
FLOAT_T & add(FLOAT_T &_result, const FLOAT_T &_op2, CARL_RND=CARL_RND::N) const
Function which adds two numbers and puts the result in a third number passed as parameter.
FLOAT_T & exp(FLOAT_T &_result, CARL_RND=CARL_RND::N) const
Function which calculates the exponential of this number and puts it into a passed result parameter.
FLOAT_T & asinh_assign(CARL_RND=CARL_RND::N)
Assigns the number the hyperbolic arcus sine of this number.
FLOAT_T & atanh_assign(CARL_RND=CARL_RND::N)
Assigns the number the hyperbolic arcus tangent of this number.
~FLOAT_T()=default
Destructor.
FLOAT_T & acos(FLOAT_T &_result, CARL_RND=CARL_RND::N) const
Function which calculates the arcus cosine of this number and puts it into a passed result parameter.
FLOAT_T(const std::string &_string, CARL_RND=CARL_RND::N)
FLOAT_T & asin_assign(CARL_RND=CARL_RND::N)
Assigns the number the arcus sine of this number.
friend FLOAT_T & operator--(FLOAT_T &_num)
Operator which decrements this number by one.
FLOAT_T ei_sqrt(const FLOAT_T &x)
Function required for extension of Eigen3 with FLOAT_T as a custom type which calculates the square r...
FLOAT_T & sub(FLOAT_T &_result, const FLOAT_T &_op2, CARL_RND=CARL_RND::N) const
Function which subtracts the righthand side from this number and puts the result in a third number pa...
FLOAT_T ei_abs(const FLOAT_T &x)
Function required for extension of Eigen3 with FLOAT_T as a custom type which calculates the absolute...
FLOAT_T & atan_assign(CARL_RND=CARL_RND::N)
Assigns the number the arcus tangent of this number.
bool operator>(unsigned _rhs) const
FLOAT_T & sqrt(FLOAT_T &_result, CARL_RND=CARL_RND::N) const
Returns the square root of this number and puts it into a passed result parameter.
bool operator<(const FLOAT_T &_rhs) const
Comparison operator for less than.
friend FLOAT_T & operator++(FLOAT_T &_num)
Operator which increments this number by one.
FLOAT_T & abs_assign(CARL_RND=CARL_RND::N)
Assigns the number the absolute value of this number.
FLOAT_T(int _int, CARL_RND=CARL_RND::N)
FLOAT_T ei_exp(const FLOAT_T &x)
Function required for extension of Eigen3 with FLOAT_T as a custom type which calculates the exponent...
FLOAT_T(FLOAT_T &&_float, CARL_RND=CARL_RND::N) noexcept
FLOAT_T & root(FLOAT_T &, std::size_t, CARL_RND=CARL_RND::N) const
Function which calculates the nth root of this number and puts it into a passed result parameter.
FLOAT_T(FloatType val, CARL_RND=CARL_RND::N)
Constructor, which takes an arbitrary fp type as input and optional rounding, which can be used,...
Struct which holds the conversion operator for any two instanciations of FLOAT_T with different under...
FLOAT_T< T1 > operator()(const FLOAT_T< T2 > &_op2) const
Conversion operator for conversion of two instanciations of FLOAT_T with different underlying floatin...
std::hash< Number > hasher
size_t operator()(const carl::FLOAT_T< Number > &_in) const
static int max_digits10()
static const carl::FLOAT_T< Number > denorm_min()
static const carl::FLOAT_T< Number > signaling_NaN()
static float_round_style round_style()
static carl::FLOAT_T< Number > round_error()
static carl::FLOAT_T< Number > epsilon()
static carl::FLOAT_T< Number > lowest()
static const carl::FLOAT_T< Number > quiet_NaN()
static const carl::FLOAT_T< Number > infinity()