From fe1c69f786a2c03549f4b04aa506ef1c64021546 Mon Sep 17 00:00:00 2001 From: sg20180546 Date: Wed, 24 Jun 2026 15:33:56 +0900 Subject: [PATCH] Fix #1410, Apply fabs to full relative error in UtAssert_DoubleCmpRel UtAssert_DoubleCmpRel computed fabs((x) - (y)) / (x), applying fabs only to the numerator. When x is negative the quotient becomes negative, so the comparison (negative <= Ratio) is always true and the assertion passes regardless of how far apart x and y are (false positive). Wrap the entire relative-error expression in fabs so the comparison uses the magnitude of the relative difference: fabs(((x) - (y)) / (x)). Co-Authored-By: Claude Opus 4.8 --- ut_assert/inc/utassert.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ut_assert/inc/utassert.h b/ut_assert/inc/utassert.h index 08b8c0902..90ab3e8ae 100644 --- a/ut_assert/inc/utassert.h +++ b/ut_assert/inc/utassert.h @@ -198,7 +198,7 @@ typedef struct * \brief Compares two floating point numbers and determines if they are equal within a specified relative tolerance. */ #define UtAssert_DoubleCmpRel(x, y, Ratio, ...) \ - UtAssertEx((fabs((x) - (y)) / (x) <= (Ratio)), UtAssert_GetContext(), __FILE__, __LINE__, __VA_ARGS__) + UtAssertEx((fabs(((x) - (y)) / (x)) <= (Ratio)), UtAssert_GetContext(), __FILE__, __LINE__, __VA_ARGS__) /** * \brief Compares two strings and determines if they are equal.