33#ifndef SVF_NUMERICVALUE_H
34#define SVF_NUMERICVALUE_H
44#define epsilon std::numeric_limits<double>::epsilon();
154 return expr.
_iVal == 0;
224 return lhs.
equal(rhs);
230 return !lhs.
equal(rhs);
236 return !lhs.
leq(rhs);
242 return !lhs.
geq(rhs);
289 if (value.
_iVal == std::numeric_limits<s64_t>::min())
299 assert(
false &&
"invalid add");
307 const s64_t min = std::numeric_limits<s64_t>::min();
308 const s64_t max = std::numeric_limits<s64_t>::max();
321 assert(
false &&
"invalid subtract");
329 const s64_t min = std::numeric_limits<s64_t>::min();
330 const s64_t max = std::numeric_limits<s64_t>::max();
345 const bool negative = (lhs.
_iVal < 0) != (rhs.
_iVal < 0);
349 const s64_t min = std::numeric_limits<s64_t>::min();
350 const s64_t max = std::numeric_limits<s64_t>::max();
372 assert(
false &&
"divide by zero");
377 if (lhs.
_iVal == std::numeric_limits<s64_t>::min() &&
385 const bool negative = (lhs.
_iVal < 0) != (rhs.
_iVal < 0);
393 assert(
false &&
"divide by zero");
398 if (lhs.
_iVal == std::numeric_limits<s64_t>::min() &&
491 assert(rhs.
geq(0) &&
"rhs should be greater or equal than 0");
497 return lhs.
geq(0) ? 0 : -1;
509 assert(rhs.
geq(0) &&
"rhs should be greater or equal than 0");
526 return cond.
_iVal != 0 ? lhs : rhs;
584 for (
const auto& it : _l)
586 if (it.is_minus_infinity())
588 else if (!it.geq(ret))
602 for (
const auto& it : _l)
604 if (it.is_plus_infinity())
606 else if (!it.leq(ret))
619 return lhs.
leq(0) ? -lhs : lhs;
647 return std::numeric_limits<s64_t>::min();
653 return std::numeric_limits<s64_t>::max();
673 return std::to_string(
_iVal);
690 assert(
false &&
"cannot get real number for integer!");
696 assert(
false &&
"cannot get real number for integer!");
725 _fVal = std::move(rhs._fVal);
733 if (std::isinf(
a) && std::isinf(
b))
745 return _fVal == std::numeric_limits<double>::infinity();
750 return _fVal == -std::numeric_limits<double>::infinity();
770 return std::numeric_limits<double>::infinity();
775 return -std::numeric_limits<double>::infinity();
846 return lhs.
equal(rhs);
852 return !lhs.
equal(rhs);
858 return !lhs.
leq(rhs);
864 return !lhs.
geq(rhs);
890 if ((lhs == std::numeric_limits<double>::infinity() &&
891 rhs == -std::numeric_limits<double>::infinity()) ||
892 (lhs == -std::numeric_limits<double>::infinity() &&
893 rhs == std::numeric_limits<double>::infinity()))
895 assert(
false &&
"invalid add");
901 if (res == std::numeric_limits<double>::infinity())
909 if (res == -std::numeric_limits<double>::infinity())
917 if (lhs > 0 && rhs > 0 &&
918 (std::numeric_limits<double>::max() - lhs) < rhs)
920 res = std::numeric_limits<double>::infinity();
928 if (lhs < 0 && rhs < 0 &&
929 (-std::numeric_limits<double>::max() - lhs) > rhs)
931 res = -std::numeric_limits<
972 double res = lhs * rhs;
974 if (res == std::numeric_limits<double>::infinity())
982 if (res == -std::numeric_limits<double>::infinity())
988 if (lhs > 0 && rhs > 0 &&
989 lhs > std::numeric_limits<double>::max() / rhs)
991 return std::numeric_limits<double>::infinity();
993 if (lhs < 0 && rhs < 0 &&
994 lhs < std::numeric_limits<double>::max() / rhs)
996 return std::numeric_limits<double>::infinity();
1000 if (lhs > 0 && rhs < 0 &&
1001 rhs < std::numeric_limits<double>::lowest() / lhs)
1003 return -std::numeric_limits<double>::infinity();
1005 if (lhs < 0 && rhs > 0 &&
1006 lhs < std::numeric_limits<double>::lowest() / rhs)
1008 return -std::numeric_limits<double>::infinity();
1034 return (lhs >= 0.0f) ? std::numeric_limits<double>::infinity()
1035 : -std::numeric_limits<double>::infinity();
1037 double res = lhs / rhs;
1039 if (res == std::numeric_limits<double>::infinity())
1047 if (res == -std::numeric_limits<double>::infinity())
1054 if (rhs > 0 && rhs < std::numeric_limits<double>::min() &&
1055 lhs > std::numeric_limits<double>::max() * rhs)
1057 return std::numeric_limits<double>::infinity();
1059 if (rhs < 0 && rhs > -std::numeric_limits<double>::min() &&
1060 lhs > std::numeric_limits<double>::max() * rhs)
1062 return -std::numeric_limits<double>::infinity();
1078 assert(
false &&
"divide by zero");
1085 return ite(rhs.
_fVal > 0.0f, lhs, -lhs);
1104 int lInt = std::round(lhs.
_fVal), rInt = std::round(rhs.
_fVal);
1111 int lInt = std::round(lhs.
_fVal), rInt = std::round(rhs.
_fVal);
1118 int lInt = std::round(lhs.
_fVal), rInt = std::round(rhs.
_fVal);
1142 assert(rhs.
geq(0) &&
"rhs should be greater or equal than 0");
1148 return lhs.
geq(0) ? 0 : -1;
1156 assert(rhs.
geq(0) &&
"rhs should be greater or equal than 0");
1198 for (
const auto& it : _l)
1200 if (it.is_minus_infinity())
1202 else if (!it.geq(ret))
1213 for (
const auto& it : _l)
1215 if (it.is_plus_infinity())
1217 else if (!it.leq(ret))
1227 return lhs.
leq(0) ? -lhs : lhs;
1232 return _fVal != 0.0f;
1248 return std::round(
_fVal);
1264 return std::to_string(
_fVal);
BoundedDouble & operator=(const BoundedDouble &rhs)
friend BoundedDouble max(const BoundedDouble &lhs, const BoundedDouble &rhs)
friend bool operator!=(const BoundedDouble &lhs, const BoundedDouble &rhs)
friend bool operator<=(const BoundedDouble &lhs, const BoundedDouble &rhs)
friend BoundedDouble operator%(const BoundedDouble &lhs, const BoundedDouble &rhs)
friend bool operator<(const BoundedDouble &lhs, const BoundedDouble &rhs)
const double getFVal() const
friend BoundedDouble operator>>(const BoundedDouble &lhs, const BoundedDouble &rhs)
static double safeDiv(double lhs, double rhs)
friend BoundedDouble operator*(const BoundedDouble &lhs, const BoundedDouble &rhs)
static double safeMul(double lhs, double rhs)
static BoundedDouble minus_infinity()
friend BoundedDouble operator!(const BoundedDouble &lhs)
friend BoundedDouble ite(const BoundedDouble &cond, const BoundedDouble &lhs, const BoundedDouble &rhs)
static BoundedDouble plus_infinity()
friend BoundedDouble operator&&(const BoundedDouble &lhs, const BoundedDouble &rhs)
bool equal(const BoundedDouble &rhs) const
BoundedDouble & operator=(BoundedDouble &&rhs)
void set_minus_infinity()
s64_t getIntNumeral() const
static bool isZero(const BoundedDouble &expr)
static bool doubleEqual(double a, double b)
bool geq(const BoundedDouble &rhs) const
friend BoundedDouble operator-(const BoundedDouble &lhs)
friend BoundedDouble operator-(const BoundedDouble &lhs, const BoundedDouble &rhs)
s64_t getNumeral() const
Return Numeral.
friend BoundedDouble operator|(const BoundedDouble &lhs, const BoundedDouble &rhs)
friend BoundedDouble min(const BoundedDouble &lhs, const BoundedDouble &rhs)
friend BoundedDouble operator^(const BoundedDouble &lhs, const BoundedDouble &rhs)
static double safeAdd(double lhs, double rhs)
friend BoundedDouble abs(const BoundedDouble &lhs)
friend BoundedDouble operator<<(const BoundedDouble &lhs, const BoundedDouble &rhs)
friend BoundedDouble operator/(const BoundedDouble &lhs, const BoundedDouble &rhs)
friend bool eq(const BoundedDouble &lhs, const BoundedDouble &rhs)
static BoundedDouble min(std::vector< BoundedDouble > &_l)
friend BoundedDouble operator+(const BoundedDouble &lhs, const BoundedDouble &rhs)
BoundedDouble(const BoundedDouble &rhs)
bool is_minus_infinity() const
BoundedDouble(BoundedDouble &&rhs)
bool leq(const BoundedDouble &rhs) const
bool is_plus_infinity() const
virtual const std::string to_string() const
static BoundedDouble max(std::vector< BoundedDouble > &_l)
friend BoundedDouble operator&(const BoundedDouble &lhs, const BoundedDouble &rhs)
double getRealNumeral() const
friend bool operator>=(const BoundedDouble &lhs, const BoundedDouble &rhs)
BoundedDouble(double fVal)
friend BoundedDouble operator||(const BoundedDouble &lhs, const BoundedDouble &rhs)
friend bool operator==(const BoundedDouble &lhs, const BoundedDouble &rhs)
Reload operator.
friend std::ostream & operator<<(std::ostream &out, const BoundedDouble &expr)
friend bool operator>(const BoundedDouble &lhs, const BoundedDouble &rhs)
static BoundedInt plus_infinity()
friend BoundedInt operator||(const BoundedInt &lhs, const BoundedInt &rhs)
friend BoundedInt ite(const BoundedInt &cond, const BoundedInt &lhs, const BoundedInt &rhs)
friend bool operator<=(const BoundedInt &lhs, const BoundedInt &rhs)
bool is_minus_infinity() const
friend bool operator<(const BoundedInt &lhs, const BoundedInt &rhs)
s64_t getNumeral() const
Retrieves the numeral value of the BoundedInt object.
friend BoundedInt operator-(const BoundedInt &value)
bool is_plus_infinity() const
friend BoundedInt operator%(const BoundedInt &lhs, const BoundedInt &rhs)
static BoundedInt safeNeg(const BoundedInt &value)
friend BoundedInt operator<<(const BoundedInt &lhs, const BoundedInt &rhs)
static BoundedInt min(std::vector< BoundedInt > &_l)
friend BoundedInt operator&(const BoundedInt &lhs, const BoundedInt &rhs)
static BoundedInt safeMul(const BoundedInt &lhs, const BoundedInt &rhs)
const double getFVal() const
friend BoundedInt operator*(const BoundedInt &lhs, const BoundedInt &rhs)
static BoundedInt safeRem(const BoundedInt &lhs, const BoundedInt &rhs)
friend BoundedInt abs(const BoundedInt &lhs)
BoundedInt(BoundedInt &&rhs)
friend BoundedInt operator|(const BoundedInt &lhs, const BoundedInt &rhs)
friend BoundedInt operator/(const BoundedInt &lhs, const BoundedInt &rhs)
friend bool operator!=(const BoundedInt &lhs, const BoundedInt &rhs)
friend BoundedInt max(const BoundedInt &lhs, const BoundedInt &rhs)
s64_t getIntNumeral() const
friend bool operator>(const BoundedInt &lhs, const BoundedInt &rhs)
friend BoundedInt operator+(const BoundedInt &lhs, const BoundedInt &rhs)
friend BoundedInt operator>>(const BoundedInt &lhs, const BoundedInt &rhs)
friend BoundedInt operator!(const BoundedInt &lhs)
friend BoundedInt operator^(const BoundedInt &lhs, const BoundedInt &rhs)
static BoundedInt safeDiv(const BoundedInt &lhs, const BoundedInt &rhs)
friend BoundedInt operator&&(const BoundedInt &lhs, const BoundedInt &rhs)
BoundedInt & operator=(const BoundedInt &rhs)
friend std::ostream & operator<<(std::ostream &out, const BoundedInt &expr)
static BoundedInt max(std::vector< BoundedInt > &_l)
friend bool eq(const BoundedInt &lhs, const BoundedInt &rhs)
static BoundedInt safeSub(const BoundedInt &lhs, const BoundedInt &rhs)
static BoundedInt safeAdd(const BoundedInt &lhs, const BoundedInt &rhs)
static BoundedInt minus_infinity()
friend BoundedInt min(const BoundedInt &lhs, const BoundedInt &rhs)
bool geq(const BoundedInt &rhs) const
bool equal(const BoundedInt &rhs) const
BoundedInt & operator=(BoundedInt &&rhs)
bool leq(const BoundedInt &rhs) const
static bool isZero(const BoundedInt &expr)
double getRealNumeral() const
BoundedInt(s64_t fVal, bool isInf)
void set_minus_infinity()
friend BoundedInt operator-(const BoundedInt &lhs, const BoundedInt &rhs)
friend bool operator>=(const BoundedInt &lhs, const BoundedInt &rhs)
BoundedInt(const BoundedInt &rhs)
virtual const std::string to_string() const
friend bool operator==(const BoundedInt &lhs, const BoundedInt &rhs)
Reload operator.