Skip to content

Commit

Permalink
renamed isnan and isinf to UNITY_ISNAN and UNITY_ININF respectively
Browse files Browse the repository at this point in the history
  • Loading branch information
leomccormack committed Nov 21, 2023
1 parent 6280d2a commit f0e9949
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 20 deletions.
8 changes: 2 additions & 6 deletions test/include/resources/unity_internals.h
Original file line number Diff line number Diff line change
Expand Up @@ -200,16 +200,12 @@
typedef UNITY_FLOAT_TYPE UNITY_FLOAT;

/* isinf & isnan macros should be provided by math.h */
#ifndef isinf
/* The value of Inf - Inf is NaN */
#define isinf(n) (isnan((n) - (n)) && !isnan(n))
#endif
#define UNITY_ISINF(n) (UNITY_ISNAN((n) - (n)) && !UNITY_ISNAN(n))

#ifndef isnan
/* NaN is the only floating point value that does NOT equal itself.
* Therefore if n != n, then it is NaN. */
#define isnan(n) ((n != n) ? 1 : 0)
#endif
#define UNITY_ISNAN(n) ((n != n) ? 1 : 0)

#endif

Expand Down
28 changes: 14 additions & 14 deletions test/src/resources/unity.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
[Released under MIT License. Please refer to license.txt for details]
============================================================================ */

#include "saf_test.h"
#include "unity.h"
#include <stddef.h>

#ifdef AVR
Expand Down Expand Up @@ -358,11 +358,11 @@ void UnityPrintFloat(const UNITY_DOUBLE input_number)
{
UnityPrint("0");
}
else if (isnan(number))
else if (UNITY_ISNAN(number))
{
UnityPrint("nan");
}
else if (isinf(number))
else if (UNITY_ISINF(number))
{
UnityPrint("inf");
}
Expand Down Expand Up @@ -868,15 +868,15 @@ void UnityAssertEqualIntArray(UNITY_INTERNAL_PTR expected,
#ifndef UNITY_EXCLUDE_FLOAT
/* Wrap this define in a function with variable types as float or double */
#define UNITY_FLOAT_OR_DOUBLE_WITHIN(delta, expected, actual, diff) \
if (isinf(expected) && isinf(actual) && (((expected) < 0) == ((actual) < 0))) return 1; \
if (UNITY_ISINF(expected) && UNITY_ISINF(actual) && (((expected) < 0) == ((actual) < 0))) return 1; \
if (UNITY_NAN_CHECK) return 1; \
(diff) = (actual) - (expected); \
if ((diff) < 0) (diff) = -(diff); \
if ((delta) < 0) (delta) = -(delta); \
return !(isnan(diff) || isinf(diff) || ((diff) > (delta)))
return !(UNITY_ISNAN(diff) || UNITY_ISINF(diff) || ((diff) > (delta)))
/* This first part of this condition will catch any NaN or Infinite values */
#ifndef UNITY_NAN_NOT_EQUAL_NAN
#define UNITY_NAN_CHECK isnan(expected) && isnan(actual)
#define UNITY_NAN_CHECK UNITY_ISNAN(expected) && UNITY_ISNAN(actual)
#else
#define UNITY_NAN_CHECK 0
#endif
Expand Down Expand Up @@ -984,21 +984,21 @@ void UnityAssertFloatSpecial(const UNITY_FLOAT actual,
{
case UNITY_FLOAT_IS_INF:
case UNITY_FLOAT_IS_NOT_INF:
is_trait = isinf(actual) && (actual > 0);
is_trait = UNITY_ISINF(actual) && (actual > 0);
break;
case UNITY_FLOAT_IS_NEG_INF:
case UNITY_FLOAT_IS_NOT_NEG_INF:
is_trait = isinf(actual) && (actual < 0);
is_trait = UNITY_ISINF(actual) && (actual < 0);
break;

case UNITY_FLOAT_IS_NAN:
case UNITY_FLOAT_IS_NOT_NAN:
is_trait = isnan(actual) ? 1 : 0;
is_trait = UNITY_ISNAN(actual) ? 1 : 0;
break;

case UNITY_FLOAT_IS_DET: /* A determinate number is non infinite and not NaN. */
case UNITY_FLOAT_IS_NOT_DET:
is_trait = !isinf(actual) && !isnan(actual);
is_trait = !UNITY_ISINF(actual) && !UNITY_ISNAN(actual);
break;

default:
Expand Down Expand Up @@ -1124,21 +1124,21 @@ void UnityAssertDoubleSpecial(const UNITY_DOUBLE actual,
{
case UNITY_FLOAT_IS_INF:
case UNITY_FLOAT_IS_NOT_INF:
is_trait = isinf(actual) && (actual > 0);
is_trait = UNITY_ISINF(actual) && (actual > 0);
break;
case UNITY_FLOAT_IS_NEG_INF:
case UNITY_FLOAT_IS_NOT_NEG_INF:
is_trait = isinf(actual) && (actual < 0);
is_trait = UNITY_ISINF(actual) && (actual < 0);
break;

case UNITY_FLOAT_IS_NAN:
case UNITY_FLOAT_IS_NOT_NAN:
is_trait = isnan(actual) ? 1 : 0;
is_trait = UNITY_ISNAN(actual) ? 1 : 0;
break;

case UNITY_FLOAT_IS_DET: /* A determinate number is non infinite and not NaN. */
case UNITY_FLOAT_IS_NOT_DET:
is_trait = !isinf(actual) && !isnan(actual);
is_trait = !UNITY_ISINF(actual) && !UNITY_ISNAN(actual);
break;

default:
Expand Down

0 comments on commit f0e9949

Please sign in to comment.