A floating-point assumption/assertion deals with verifying the precision and correctness of floating-point values within a certain tolerance. This type of assumption is critical for numerical computations that involve real numbers, where small rounding errors may occur. Assertions check whether floating-point values fall within expected bounds, helping ensure accuracy and consistency in calculations, especially for applications like scientific computing or financial software.
Code reference for C, C++, or Python APIs for a respective Fossil Logic Project.
C, C++ REFERENCE #
// Double equality check with tolerance
/**
* @brief Assumes that the given double values are equal within a specified tolerance.
*
* @param actual The actual double value.
* @param expected The expected double value.
* @param tol The tolerance within which the values should be considered equal.
*/
#define ASSUME_ITS_EQUAL_F64(actual, expected, tol) \
FOSSIL_TEST_ASSUME(fabs((actual) - (expected)) <= (tol), "Expected " #actual " to be equal to " #expected " within tolerance " #tol)
/**
* @brief Assumes that the given double value is less than the expected value.
*
* @param actual The actual double value.
* @param expected The expected double value.
*/
#define ASSUME_ITS_LESS_THAN_F64(actual, expected) \
FOSSIL_TEST_ASSUME((actual) < (expected), "Expected " #actual " to be less than " #expected)
/**
* @brief Assumes that the given double value is more than the expected value.
*
* @param actual The actual double value.
* @param expected The expected double value.
*/
#define ASSUME_ITS_MORE_THAN_F64(actual, expected) \
FOSSIL_TEST_ASSUME((actual) > (expected), "Expected " #actual " to be more than " #expected)
/**
* @brief Assumes that the given double value is less than or equal to the expected value.
*
* @param actual The actual double value.
* @param expected The expected double value.
*/
#define ASSUME_ITS_LESS_OR_EQUAL_F64(actual, expected) \
FOSSIL_TEST_ASSUME((actual) <= (expected), "Expected " #actual " to be less than or equal to " #expected)
/**
* @brief Assumes that the given double value is more than or equal to the expected value.
*
* @param actual The actual double value.
* @param expected The expected double value.
*/
#define ASSUME_ITS_MORE_OR_EQUAL_F64(actual, expected) \
FOSSIL_TEST_ASSUME((actual) >= (expected), "Expected " #actual " to be more than or equal to " #expected)
/**
* @brief Assumes that the given double values are not equal within a specified tolerance.
*
* @param actual The actual double value.
* @param expected The expected double value.
* @param tol The tolerance within which the values should not be considered equal.
*/
#define ASSUME_NOT_EQUAL_F64(actual, expected, tol) \
FOSSIL_TEST_ASSUME(fabs((actual) - (expected)) > (tol), "Expected " #actual " to not be equal to " #expected " within tolerance " #tol)
/**
* @brief Assumes that the given double value is not less than the expected value.
*
* @param actual The actual double value.
* @param expected The expected double value.
*/
#define ASSUME_NOT_LESS_THAN_F64(actual, expected) \
FOSSIL_TEST_ASSUME((actual) >= (expected), "Expected " #actual " to not be less than " #expected)
/**
* @brief Assumes that the given double value is not more than the expected value.
*
* @param actual The actual double value.
* @param expected The expected double value.
*/
#define ASSUME_NOT_MORE_THAN_F64(actual, expected) \
FOSSIL_TEST_ASSUME((actual) <= (expected), "Expected " #actual " to not be more than " #expected)
/**
* @brief Assumes that the given double value is not less than or equal to the expected value.
*
* @param actual The actual double value.
* @param expected The expected double value.
*/
#define ASSUME_NOT_LESS_OR_EQUAL_F64(actual, expected) \
FOSSIL_TEST_ASSUME((actual) > (expected), "Expected " #actual " to not be less than or equal to " #expected)
/**
* @brief Assumes that the given double value is not more than or equal to the expected value.
*
* @param actual The actual double value.
* @param expected The expected double value.
*/
#define ASSUME_NOT_MORE_OR_EQUAL_F64(actual, expected) \
FOSSIL_TEST_ASSUME((actual) < (expected), "Expected " #actual " to not be more than or equal to " #expected)
// Float equality check with tolerance
/**
* @brief Assumes that the given float values are equal within a specified tolerance.
*
* @param actual The actual float value.
* @param expected The expected float value.
* @param tol The tolerance within which the values should be considered equal.
*/
#define ASSUME_ITS_EQUAL_F32(actual, expected, tol) \
FOSSIL_TEST_ASSUME(fabsf((actual) - (expected)) <= (tol), "Expected " #actual " to be equal to " #expected " within tolerance " #tol)
/**
* @brief Assumes that the given float value is less than the expected value.
*
* @param actual The actual float value.
* @param expected The expected float value.
*/
#define ASSUME_ITS_LESS_THAN_F32(actual, expected) \
FOSSIL_TEST_ASSUME((actual) < (expected), "Expected " #actual " to be less than " #expected)
/**
* @brief Assumes that the given float value is more than the expected value.
*
* @param actual The actual float value.
* @param expected The expected float value.
*/
#define ASSUME_ITS_MORE_THAN_F32(actual, expected) \
FOSSIL_TEST_ASSUME((actual) > (expected), "Expected " #actual " to be more than " #expected)
/**
* @brief Assumes that the given float value is less than or equal to the expected value.
*
* @param actual The actual float value.
* @param expected The expected float value.
*/
#define ASSUME_ITS_LESS_OR_EQUAL_F32(actual, expected) \
FOSSIL_TEST_ASSUME((actual) <= (expected), "Expected " #actual " to be less than or equal to " #expected)
/**
* @brief Assumes that the given float value is more than or equal to the expected value.
*
* @param actual The actual float value.
* @param expected The expected float value.
*/
#define ASSUME_ITS_MORE_OR_EQUAL_F32(actual, expected) \
FOSSIL_TEST_ASSUME((actual) >= (expected), "Expected " #actual " to be more than or equal to " #expected)
/**
* @brief Assumes that the given float values are not equal within a specified tolerance.
*
* @param actual The actual float value.
* @param expected The expected float value.
* @param tol The tolerance within which the values should not be considered equal.
*/
#define ASSUME_NOT_EQUAL_F32(actual, expected, tol) \
FOSSIL_TEST_ASSUME(fabsf((actual) - (expected)) > (tol), "Expected " #actual " to not be equal to " #expected " within tolerance " #tol)
/**
* @brief Assumes that the given float value is not less than the expected value.
*
* @param actual The actual float value.
* @param expected The expected float value.
*/
#define ASSUME_NOT_LESS_THAN_F32(actual, expected) \
FOSSIL_TEST_ASSUME((actual) >= (expected), "Expected " #actual " to not be less than " #expected)
/**
* @brief Assumes that the given float value is not more than the expected value.
*
* @param actual The actual float value.
* @param expected The expected float value.
*/
#define ASSUME_NOT_MORE_THAN_F32(actual, expected) \
FOSSIL_TEST_ASSUME((actual) <= (expected), "Expected " #actual " to not be more than " #expected)
/**
* @brief Assumes that the given float value is not less than or equal to the expected value.
*
* @param actual The actual float value.
* @param expected The expected float value.
*/
#define ASSUME_NOT_LESS_OR_EQUAL_F32(actual, expected) \
FOSSIL_TEST_ASSUME((actual) > (expected), "Expected " #actual " to not be less than or equal to " #expected)
/**
* @brief Assumes that the given float value is not more than or equal to the expected value.
*
* @param actual The actual float value.
* @param expected The expected float value.
*/
#define ASSUME_NOT_MORE_OR_EQUAL_F32(actual, expected) \
FOSSIL_TEST_ASSUME((actual) < (expected), "Expected " #actual " to not be more than or equal to " #expected)
// Float NaN and Infinity checks
/**
* @brief Assumes that the given float value is NaN (Not a Number).
*
* @param actual The actual float value.
*/
#define ASSUME_ITS_NAN_F32(actual) \
FOSSIL_TEST_ASSUME(isnan(actual), "Expected " #actual " to be NaN")
/**
* @brief Assumes that the given float value is infinity.
*
* @param actual The actual float value.
*/
#define ASSUME_ITS_INF_F32(actual) \
FOSSIL_TEST_ASSUME(isinf(actual), "Expected " #actual " to be infinity")
// Double NaN and Infinity checks
/**
* @brief Assumes that the given double value is NaN (Not a Number).
*
* @param actual The actual double value.
*/
#define ASSUME_ITS_NAN_F64(actual) \
FOSSIL_TEST_ASSUME(isnan(actual), "Expected " #actual " to be NaN")
/**
* @brief Assumes that the given double value is infinity.
*
* @param actual The actual double value.
*/
#define ASSUME_ITS_INF_F64(actual) \
FOSSIL_TEST_ASSUME(isinf(actual), "Expected " #actual " to be infinity")PYTHON REFERENCE #
# TODO: add code here