Skip to content

Commit 4ce86fd

Browse files
authored
Merge pull request #226 from jsalling/feature/nan-not-eq-nan
Add option to set NaN not equal NaN for floating point assertions
2 parents 1129b18 + 933cc97 commit 4ce86fd

File tree

2 files changed

+8
-3
lines changed

2 files changed

+8
-3
lines changed

src/unity.c

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -619,12 +619,17 @@ void UnityAssertEqualIntArray(UNITY_INTERNAL_PTR expected,
619619
/* Wrap this define in a function with variable types as float or double */
620620
#define UNITY_FLOAT_OR_DOUBLE_WITHIN(delta, expected, actual, diff) \
621621
if (isinf(expected) && isinf(actual) && (isneg(expected) == isneg(actual))) return 1; \
622-
if (isnan(expected) && isnan(actual)) return 1; \
622+
if (UNITY_NAN_CHECK) return 1; \
623623
diff = actual - expected; \
624624
if (diff < 0.0f) diff = 0.0f - diff; \
625625
if (delta < 0.0f) delta = 0.0f - delta; \
626-
return !(isnan(diff) || isinf(diff) || (delta < diff));
626+
return !(isnan(diff) || isinf(diff) || (diff > delta))
627627
/* This first part of this condition will catch any NaN or Infinite values */
628+
#ifndef UNITY_NAN_NOT_EQUAL_NAN
629+
#define UNITY_NAN_CHECK isnan(expected) && isnan(actual)
630+
#else
631+
#define UNITY_NAN_CHECK 0
632+
#endif
628633

629634
#ifndef UNITY_EXCLUDE_FLOAT
630635
static int UnityFloatsWithin(_UF delta, _UF expected, _UF actual)

test/tests/testunity.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3713,7 +3713,7 @@ void testNotEqualDoubleArraysNegative3(void)
37133713
#endif
37143714
}
37153715

3716-
void testNotEqualDoubleArraysNaN(void)
3716+
void testEqualDoubleArraysNaN(void)
37173717
{
37183718
#ifdef UNITY_EXCLUDE_DOUBLE
37193719
TEST_IGNORE();

0 commit comments

Comments
 (0)