overflow

namespace overflow

Functions

bool isSumValid(const double &first, const double &second)

Checks if an overflow would occur in summation.

Parameters:
  • first – first value

  • second – second value

Returns:

true if sum is valid, false otherwise

bool isSumValid(const float &first, const float &second)
bool isSumValid(const uint32_t &first, const uint32_t &second)
bool isSumValid(const uint64_t &first, const uint64_t &second)
bool isSumValid(const int32_t &first, const int32_t &second)
bool isSumValid(const int64_t &first, const int64_t &second)
bool isProductValid(const double &first, const double &second)

Checks if an overflow would occur in multiplcation.

Parameters:
  • first – first value

  • second – second value

Returns:

true if product is valid, false otherwise

bool isProductValid(const float &first, const float &second)
bool isProductValid(const uint32_t &first, const uint32_t &second)
bool isProductValid(const uint64_t &first, const uint64_t &second)
bool isProductValid(const int32_t &first, const int32_t &second)
bool isProductValid(const int64_t &first, const int64_t &second)
bool closeToZero(const double &value, const double tolerance = 0.0001)

Checks if the value is close to zero.

Parameters:
  • value – value to check

  • tolerance – the accuracy to use, anything closer to 0 than this will be considered zero

Returns:

true if close to zero, false otherwise

bool closeToZero(const float &value, const float tolerance = 0.0001f)