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:
Mark VanderVoord
2016-09-22 08:35:22 -04:00
parent 0f07adfa00
commit dce6d329ff
3 changed files with 20 additions and 21 deletions

View File

@ -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 */