33 #ifndef SVF_NUMERICVALUE_H
34 #define SVF_NUMERICVALUE_H
41 #define epsilon std::numeric_limits<double>::epsilon();
151 return expr.
_iVal == 0;
221 return lhs.
equal(rhs);
227 return !lhs.
equal(rhs);
233 return !lhs.
leq(rhs);
239 return !lhs.
geq(rhs);
287 assert(
false &&
"invalid add");
307 (std::numeric_limits<s64_t>::max() - lhs.
_iVal) < rhs.
_iVal)
315 (-std::numeric_limits<s64_t>::max() - lhs.
_iVal) > rhs.
_iVal)
390 (std::numeric_limits<s64_t>::max() / lhs.
_iVal) < rhs.
_iVal)
398 (std::numeric_limits<s64_t>::max() / lhs.
_iVal) > rhs.
_iVal)
407 (-std::numeric_limits<s64_t>::max() / lhs.
_iVal) > rhs.
_iVal) ||
409 (-std::numeric_limits<s64_t>::max() / rhs.
_iVal) > lhs.
_iVal))
423 assert(
false &&
"divide by zero");
430 return ite(rhs.
_iVal > 0, lhs, -lhs);
449 assert(
false &&
"divide by zero");
455 return ite(rhs.
_iVal >= 0, lhs, -lhs);
511 assert(rhs.
geq(0) &&
"rhs should be greater or equal than 0");
517 return lhs.
geq(0) ? 0 : -1;
529 assert(rhs.
geq(0) &&
"rhs should be greater or equal than 0");
546 return cond.
_iVal != 0 ? lhs : rhs;
604 for (
const auto& it : _l)
606 if (it.is_minus_infinity())
608 else if (!it.geq(ret))
622 for (
const auto& it : _l)
624 if (it.is_plus_infinity())
626 else if (!it.leq(ret))
639 return lhs.
leq(0) ? -lhs : lhs;
667 return std::numeric_limits<s64_t>::min();
673 return std::numeric_limits<s64_t>::max();
693 return std::to_string(
_iVal);
710 assert(
false &&
"cannot get real number for integer!");
716 assert(
false &&
"cannot get real number for integer!");
765 return _fVal == std::numeric_limits<double>::infinity();
770 return _fVal == -std::numeric_limits<double>::infinity();
790 return std::numeric_limits<double>::infinity();
795 return -std::numeric_limits<double>::infinity();
866 return lhs.
equal(rhs);
872 return !lhs.
equal(rhs);
878 return !lhs.
leq(rhs);
884 return !lhs.
geq(rhs);
910 if ((lhs == std::numeric_limits<double>::infinity() &&
911 rhs == -std::numeric_limits<double>::infinity()) ||
912 (lhs == -std::numeric_limits<double>::infinity() &&
913 rhs == std::numeric_limits<double>::infinity()))
915 assert(
false &&
"invalid add");
921 if (res == std::numeric_limits<double>::infinity())
929 if (res == -std::numeric_limits<double>::infinity())
937 if (lhs > 0 && rhs > 0 &&
938 (std::numeric_limits<double>::max() - lhs) < rhs)
940 res = std::numeric_limits<double>::infinity();
948 if (lhs < 0 && rhs < 0 &&
949 (-std::numeric_limits<double>::max() - lhs) > rhs)
951 res = -std::numeric_limits<
992 double res = lhs * rhs;
994 if (res == std::numeric_limits<double>::infinity())
1002 if (res == -std::numeric_limits<double>::infinity())
1008 if (lhs > 0 && rhs > 0 &&
1009 lhs > std::numeric_limits<double>::max() / rhs)
1011 return std::numeric_limits<double>::infinity();
1013 if (lhs < 0 && rhs < 0 &&
1014 lhs < std::numeric_limits<double>::max() / rhs)
1016 return std::numeric_limits<double>::infinity();
1020 if (lhs > 0 && rhs < 0 &&
1021 rhs < std::numeric_limits<double>::lowest() / lhs)
1023 return -std::numeric_limits<double>::infinity();
1025 if (lhs < 0 && rhs > 0 &&
1026 lhs < std::numeric_limits<double>::lowest() / rhs)
1028 return -std::numeric_limits<double>::infinity();
1054 return (lhs >= 0.0f) ? std::numeric_limits<double>::infinity()
1055 : -std::numeric_limits<double>::infinity();
1057 double res = lhs / rhs;
1059 if (res == std::numeric_limits<double>::infinity())
1067 if (res == -std::numeric_limits<double>::infinity())
1074 if (rhs > 0 && rhs < std::numeric_limits<double>::min() &&
1075 lhs > std::numeric_limits<double>::max() * rhs)
1077 return std::numeric_limits<double>::infinity();
1079 if (rhs < 0 && rhs > -std::numeric_limits<double>::min() &&
1080 lhs > std::numeric_limits<double>::max() * rhs)
1082 return -std::numeric_limits<double>::infinity();
1098 assert(
false &&
"divide by zero");
1105 return ite(rhs.
_fVal > 0.0f, lhs, -lhs);
1124 int lInt = std::round(lhs.
_fVal), rInt = std::round(rhs.
_fVal);
1131 int lInt = std::round(lhs.
_fVal), rInt = std::round(rhs.
_fVal);
1138 int lInt = std::round(lhs.
_fVal), rInt = std::round(rhs.
_fVal);
1162 assert(rhs.
geq(0) &&
"rhs should be greater or equal than 0");
1168 return lhs.
geq(0) ? 0 : -1;
1176 assert(rhs.
geq(0) &&
"rhs should be greater or equal than 0");
1218 for (
const auto& it : _l)
1220 if (it.is_minus_infinity())
1222 else if (!it.geq(ret))
1233 for (
const auto& it : _l)
1235 if (it.is_plus_infinity())
1237 else if (!it.leq(ret))
1247 return lhs.
leq(0) ? -lhs : lhs;
1252 return _fVal != 0.0f;
1268 return std::round(
_fVal);
1284 return std::to_string(
_fVal);
friend BoundedDouble max(const BoundedDouble &lhs, const BoundedDouble &rhs)
friend BoundedDouble operator<(const BoundedDouble &lhs, const BoundedDouble &rhs)
friend BoundedDouble 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)
friend BoundedDouble operator==(const BoundedDouble &lhs, const BoundedDouble &rhs)
Reload operator.
BoundedDouble & operator=(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)
friend BoundedDouble operator>(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
void set_minus_infinity()
s64_t getIntNumeral() const
friend BoundedDouble operator<=(const BoundedDouble &lhs, const BoundedDouble &rhs)
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)
friend BoundedDouble operator>=(const BoundedDouble &lhs, const BoundedDouble &rhs)
static double safeAdd(double lhs, double rhs)
BoundedDouble & operator=(BoundedDouble &&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 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)
friend std::ostream & operator<<(std::ostream &out, const BoundedDouble &expr)
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
BoundedDouble(double fVal)
friend BoundedDouble operator||(const BoundedDouble &lhs, const BoundedDouble &rhs)
A class representing a bounded 64-bit integer.
friend BoundedInt operator>=(const BoundedInt &lhs, const BoundedInt &rhs)
static BoundedInt plus_infinity()
friend BoundedInt operator||(const BoundedInt &lhs, const BoundedInt &rhs)
friend BoundedInt operator<=(const BoundedInt &lhs, const BoundedInt &rhs)
friend BoundedInt ite(const BoundedInt &cond, const BoundedInt &lhs, const BoundedInt &rhs)
friend std::ostream & operator<<(std::ostream &out, const BoundedInt &expr)
bool is_minus_infinity() const
friend BoundedInt operator!=(const BoundedInt &lhs, const BoundedInt &rhs)
s64_t getNumeral() const
Retrieves the numeral value of the BoundedInt object.
bool is_plus_infinity() const
friend BoundedInt operator%(const BoundedInt &lhs, const BoundedInt &rhs)
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)
Performs safe multiplication of two BoundedInt objects.
const double getFVal() const
friend BoundedInt operator*(const BoundedInt &lhs, const BoundedInt &rhs)
friend BoundedInt abs(const BoundedInt &lhs)
BoundedInt(BoundedInt &&rhs)
friend BoundedInt operator|(const BoundedInt &lhs, const BoundedInt &rhs)
BoundedInt & operator=(BoundedInt &&rhs)
friend BoundedInt operator/(const BoundedInt &lhs, const BoundedInt &rhs)
friend BoundedInt max(const BoundedInt &lhs, const BoundedInt &rhs)
s64_t getIntNumeral() const
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)
friend BoundedInt operator&&(const BoundedInt &lhs, const BoundedInt &rhs)
static BoundedInt max(std::vector< BoundedInt > &_l)
friend bool eq(const BoundedInt &lhs, const BoundedInt &rhs)
static BoundedInt safeAdd(const BoundedInt &lhs, const BoundedInt &rhs)
static BoundedInt minus_infinity()
BoundedInt & operator=(const BoundedInt &rhs)
friend BoundedInt min(const BoundedInt &lhs, const BoundedInt &rhs)
bool geq(const BoundedInt &rhs) const
friend BoundedInt operator<(const BoundedInt &lhs, const BoundedInt &rhs)
bool equal(const BoundedInt &rhs) const
friend BoundedInt operator==(const BoundedInt &lhs, const BoundedInt &rhs)
Reload operator.
bool leq(const BoundedInt &rhs) const
static bool isZero(const BoundedInt &expr)
double getRealNumeral() const
friend BoundedInt operator>(const BoundedInt &lhs, const BoundedInt &rhs)
BoundedInt(s64_t fVal, bool isInf)
void set_minus_infinity()
friend BoundedInt operator-(const BoundedInt &lhs)
friend BoundedInt operator-(const BoundedInt &lhs, const BoundedInt &rhs)
BoundedInt(const BoundedInt &rhs)
virtual const std::string to_string() const
constexpr std::remove_reference< T >::type && move(T &&t) noexcept