From 74581c357e8d5b7fa99362ed46b55cac92bd3814 Mon Sep 17 00:00:00 2001 From: Rik van der Heijden Date: Wed, 27 Apr 2016 10:17:43 +0200 Subject: [PATCH 1/2] use isnan instead of comparing floats, fixes #188 --- src/unity.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/unity.c b/src/unity.c index 8fa0a1b..350343f 100644 --- a/src/unity.c +++ b/src/unity.c @@ -668,13 +668,13 @@ void UnityAssertEqualFloatArray(UNITY_PTR_ATTRIBUTE const _UF* expected, { diff = *ptr_expected - *ptr_actual; if (diff < 0.0f) - diff = 0.0f - diff; + diff = 0.0f - diff; tol = UNITY_FLOAT_PRECISION * *ptr_expected; if (tol < 0.0f) tol = 0.0f - tol; //This first part of this condition will catch any NaN or Infinite values - if ((diff * 0.0f != 0.0f) || (diff > tol)) + if (isnan(diff) || (diff > tol)) { UnityTestResultsFailBegin(lineNumber); UnityPrint(UnityStrElement); @@ -717,7 +717,7 @@ void UnityAssertFloatsWithin(const _UF delta, } //This first part of this condition will catch any NaN or Infinite values - if ((diff * 0.0f != 0.0f) || (pos_delta < diff)) + if (isnan(diff) || (pos_delta < diff)) { UnityTestResultsFailBegin(lineNumber); #ifdef UNITY_FLOAT_VERBOSE @@ -838,7 +838,7 @@ void UnityAssertEqualDoubleArray(UNITY_PTR_ATTRIBUTE const _UD* expected, tol = 0.0 - tol; //This first part of this condition will catch any NaN or Infinite values - if ((diff * 0.0 != 0.0) || (diff > tol)) + if (isnan(diff) || (diff > tol)) { UnityTestResultsFailBegin(lineNumber); UnityPrint(UnityStrElement); @@ -881,7 +881,7 @@ void UnityAssertDoublesWithin(const _UD delta, } //This first part of this condition will catch any NaN or Infinite values - if ((diff * 0.0 != 0.0) || (pos_delta < diff)) + if (isnan(diff) || (pos_delta < diff)) { UnityTestResultsFailBegin(lineNumber); #ifdef UNITY_DOUBLE_VERBOSE From 23271e81a6cfb68146ddf5814c8a3a47c98f8774 Mon Sep 17 00:00:00 2001 From: Rik van der Heijden Date: Wed, 27 Apr 2016 10:25:11 +0200 Subject: [PATCH 2/2] also check for isinf --- src/unity.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/unity.c b/src/unity.c index 350343f..c749779 100644 --- a/src/unity.c +++ b/src/unity.c @@ -674,7 +674,7 @@ void UnityAssertEqualFloatArray(UNITY_PTR_ATTRIBUTE const _UF* expected, tol = 0.0f - tol; //This first part of this condition will catch any NaN or Infinite values - if (isnan(diff) || (diff > tol)) + if (isnan(diff) || isinf(diff) || (diff > tol)) { UnityTestResultsFailBegin(lineNumber); UnityPrint(UnityStrElement); @@ -717,7 +717,7 @@ void UnityAssertFloatsWithin(const _UF delta, } //This first part of this condition will catch any NaN or Infinite values - if (isnan(diff) || (pos_delta < diff)) + if (isnan(diff) || isinf(diff) || (pos_delta < diff)) { UnityTestResultsFailBegin(lineNumber); #ifdef UNITY_FLOAT_VERBOSE @@ -838,7 +838,7 @@ void UnityAssertEqualDoubleArray(UNITY_PTR_ATTRIBUTE const _UD* expected, tol = 0.0 - tol; //This first part of this condition will catch any NaN or Infinite values - if (isnan(diff) || (diff > tol)) + if (isnan(diff) || isinf(diff) || (diff > tol)) { UnityTestResultsFailBegin(lineNumber); UnityPrint(UnityStrElement); @@ -881,7 +881,7 @@ void UnityAssertDoublesWithin(const _UD delta, } //This first part of this condition will catch any NaN or Infinite values - if (isnan(diff) || (pos_delta < diff)) + if (isnan(diff) || isinf(diff) || (pos_delta < diff)) { UnityTestResultsFailBegin(lineNumber); #ifdef UNITY_DOUBLE_VERBOSE