Skip to content

Commit fe1c69f

Browse files
sg20180546claude
andcommitted
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 <noreply@anthropic.com>
1 parent 790dc84 commit fe1c69f

1 file changed

Lines changed: 1 addition & 1 deletion

File tree

ut_assert/inc/utassert.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,7 @@ typedef struct
198198
* \brief Compares two floating point numbers and determines if they are equal within a specified relative tolerance.
199199
*/
200200
#define UtAssert_DoubleCmpRel(x, y, Ratio, ...) \
201-
UtAssertEx((fabs((x) - (y)) / (x) <= (Ratio)), UtAssert_GetContext(), __FILE__, __LINE__, __VA_ARGS__)
201+
UtAssertEx((fabs(((x) - (y)) / (x)) <= (Ratio)), UtAssert_GetContext(), __FILE__, __LINE__, __VA_ARGS__)
202202

203203
/**
204204
* \brief Compares two strings and determines if they are equal.

0 commit comments

Comments
 (0)