|
BoundedInt | operator== (const BoundedInt &lhs, const BoundedInt &rhs) |
| Reload operator. More...
|
|
BoundedInt | operator!= (const BoundedInt &lhs, const BoundedInt &rhs) |
|
BoundedInt | operator> (const BoundedInt &lhs, const BoundedInt &rhs) |
|
BoundedInt | operator< (const BoundedInt &lhs, const BoundedInt &rhs) |
|
BoundedInt | operator<= (const BoundedInt &lhs, const BoundedInt &rhs) |
|
BoundedInt | operator>= (const BoundedInt &lhs, const BoundedInt &rhs) |
|
BoundedInt | operator+ (const BoundedInt &lhs, const BoundedInt &rhs) |
|
BoundedInt | operator- (const BoundedInt &lhs) |
|
BoundedInt | operator- (const BoundedInt &lhs, const BoundedInt &rhs) |
|
BoundedInt | operator% (const BoundedInt &lhs, const BoundedInt &rhs) |
|
BoundedInt | operator* (const BoundedInt &lhs, const BoundedInt &rhs) |
|
BoundedInt | operator/ (const BoundedInt &lhs, const BoundedInt &rhs) |
|
BoundedInt | operator^ (const BoundedInt &lhs, const BoundedInt &rhs) |
|
BoundedInt | operator& (const BoundedInt &lhs, const BoundedInt &rhs) |
|
BoundedInt | operator| (const BoundedInt &lhs, const BoundedInt &rhs) |
|
BoundedInt | operator&& (const BoundedInt &lhs, const BoundedInt &rhs) |
|
BoundedInt | operator|| (const BoundedInt &lhs, const BoundedInt &rhs) |
|
BoundedInt | operator! (const BoundedInt &lhs) |
|
BoundedInt | operator>> (const BoundedInt &lhs, const BoundedInt &rhs) |
|
BoundedInt | operator<< (const BoundedInt &lhs, const BoundedInt &rhs) |
|
BoundedInt | ite (const BoundedInt &cond, const BoundedInt &lhs, const BoundedInt &rhs) |
|
std::ostream & | operator<< (std::ostream &out, const BoundedInt &expr) |
|
bool | eq (const BoundedInt &lhs, const BoundedInt &rhs) |
|
BoundedInt | min (const BoundedInt &lhs, const BoundedInt &rhs) |
|
BoundedInt | max (const BoundedInt &lhs, const BoundedInt &rhs) |
|
BoundedInt | abs (const BoundedInt &lhs) |
|
A class representing a bounded 64-bit integer.
BoundedInt is a class that represents a 64-bit integer that can also represent positive and negative infinity. It includes a 64-bit integer value and a boolean flag indicating whether the value is infinite. If the value is infinite, the integer value is used to represent the sign of infinity (1 for positive infinity and 0 for negative infinity).
Definition at line 54 of file NumericValue.h.
Safely adds two BoundedInt objects.
This function adds two BoundedInt objects in a way that respects the bounds of the underlying s64_t type. It checks for conditions that would result in overflow or underflow and returns a representation of positive or negative infinity in those cases. If addition of the two numbers would result in a value that is within the representable range of s64_t, it performs the addition and returns the result. If the addition is not defined (e.g., positive infinity plus negative infinity), it asserts false to indicate an error.
- Parameters
-
lhs | The first BoundedInt to add. This can be any valid BoundedInt, including positive and negative infinity. |
rhs | The second BoundedInt to add. This can be any valid BoundedInt, including positive and negative infinity. |
- Returns
- A BoundedInt that represents the result of the addition. If the addition would result in overflow, the function returns a BoundedInt representing positive infinity. If the addition would result in underflow, the function returns a BoundedInt representing negative infinity. If the addition is not defined (e.g., positive infinity plus negative infinity), the function asserts false and does not return a value.
Definition at line 280 of file NumericValue.h.
284 if ((lhs.is_plus_infinity() && rhs.is_minus_infinity()) ||
285 (lhs.is_minus_infinity() && rhs.is_plus_infinity()))
287 assert(
false &&
"invalid add");
292 if (lhs.is_plus_infinity() || rhs.is_plus_infinity())
299 if (lhs.is_minus_infinity() || rhs.is_minus_infinity())
306 if (lhs._iVal > 0 && rhs._iVal > 0 &&
307 (std::numeric_limits<s64_t>::max() - lhs._iVal) < rhs._iVal)
314 if (lhs._iVal < 0 && rhs._iVal < 0 &&
315 (-std::numeric_limits<s64_t>::max() - lhs._iVal) > rhs._iVal)
322 return lhs._iVal + rhs._iVal;
Performs safe multiplication of two BoundedInt objects.
This function ensures that the multiplication of two BoundedInt objects doesn't result in overflow or underflow. It returns the multiplication result if it can be represented within the range of a 64-bit integer. If the result would be larger than the maximum representable positive number, it returns positive infinity. If the result would be less than the minimum representable negative number, it returns negative infinity. If either of the inputs is zero, the result is zero. If either of the inputs is infinity, the result is determined by the signs of the inputs.
- Parameters
-
- Returns
- The result of the multiplication, or positive/negative infinity if the result would be outside the range of a 64-bit integer.
Definition at line 364 of file NumericValue.h.
367 if (lhs._iVal == 0 || rhs._iVal == 0)
372 if (lhs.is_infinity() || rhs.is_infinity())
377 if (lhs._iVal * rhs._iVal > 0)
389 if (lhs._iVal > 0 && rhs._iVal > 0 &&
390 (std::numeric_limits<s64_t>::max() / lhs._iVal) < rhs._iVal)
397 if (lhs._iVal < 0 && rhs._iVal < 0 &&
398 (std::numeric_limits<s64_t>::max() / lhs._iVal) > rhs._iVal)
406 if ((lhs._iVal > 0 && rhs._iVal < 0 &&
407 (-std::numeric_limits<s64_t>::max() / lhs._iVal) > rhs._iVal) ||
408 (lhs._iVal < 0 && rhs._iVal > 0 &&
409 (-std::numeric_limits<s64_t>::max() / rhs._iVal) > lhs._iVal))
416 return lhs._iVal * rhs._iVal;