mirror of
https://github.com/ThrowTheSwitch/Unity.git
synced 2025-07-15 00:52:46 +08:00
Finished fixing floating point comparisons. We have streamlined how floats and doubles are checked, but we still can't compare them for equality directly. So we're directly testing for infinite and NaN before checking diffs. Also, we've officially decided that for testing purposes NaN shall equal NaN, +Inf shall equal +Inf, and -Inf shall equal -Inf. It's what most people expect during a test.
This commit is contained in:
11
src/unity.c
11
src/unity.c
@ -617,11 +617,12 @@ void UnityAssertEqualIntArray(UNITY_INTERNAL_PTR expected,
|
||||
|
||||
/*-----------------------------------------------*/
|
||||
/* Wrap this define in a function with variable types as float or double */
|
||||
#define UNITY_FLOAT_OR_DOUBLE_WITHIN(delta, expected, actual, diff) \
|
||||
if (expected == actual) return 1; \
|
||||
diff = actual - expected; \
|
||||
if (diff < 0.0f) diff = 0.0f - diff; \
|
||||
if (delta < 0.0f) delta = 0.0f - delta; \
|
||||
#define UNITY_FLOAT_OR_DOUBLE_WITHIN(delta, expected, actual, diff) \
|
||||
if (isinf(expected) && isinf(actual) && (isneg(expected) == isneg(actual))) return 1; \
|
||||
if (isnan(expected) && isnan(actual)) return 1; \
|
||||
diff = actual - expected; \
|
||||
if (diff < 0.0f) diff = 0.0f - diff; \
|
||||
if (delta < 0.0f) delta = 0.0f - delta; \
|
||||
return !(isnan(diff) || isinf(diff) || (delta < diff));
|
||||
/* This first part of this condition will catch any NaN or Infinite values */
|
||||
|
||||
|
Reference in New Issue
Block a user