提交 9954d4f8 编写于 作者: M Mark VanderVoord 提交者: GitHub

Merge pull request #244 from jsalling/cleanup/promotion-warnings

Remove promotion warnings on float constants, Inline the isneg/ispos macros
......@@ -645,11 +645,11 @@ 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) && (isneg(expected) == isneg(actual))) return 1; \
if (isinf(expected) && isinf(actual) && ((expected < 0) == (actual < 0))) return 1; \
if (UNITY_NAN_CHECK) return 1; \
diff = actual - expected; \
if (diff < 0.0f) diff = 0.0f - diff; \
if (delta < 0.0f) delta = 0.0f - delta; \
if (diff < 0) diff = -diff; \
if (delta < 0) delta = -delta; \
return !(isnan(diff) || isinf(diff) || (diff > delta))
/* This first part of this condition will catch any NaN or Infinite values */
#ifndef UNITY_NAN_NOT_EQUAL_NAN
......@@ -749,11 +749,11 @@ void UnityAssertFloatSpecial(const UNITY_FLOAT actual,
{
case UNITY_FLOAT_IS_INF:
case UNITY_FLOAT_IS_NOT_INF:
is_trait = isinf(actual) & ispos(actual);
is_trait = isinf(actual) && (actual > 0);
break;
case UNITY_FLOAT_IS_NEG_INF:
case UNITY_FLOAT_IS_NOT_NEG_INF:
is_trait = isinf(actual) & isneg(actual);
is_trait = isinf(actual) && (actual < 0);
break;
case UNITY_FLOAT_IS_NAN:
......@@ -761,13 +761,9 @@ void UnityAssertFloatSpecial(const UNITY_FLOAT actual,
is_trait = isnan(actual) ? 1 : 0;
break;
/* A determinate number is non infinite and not NaN. (therefore the opposite of the two above) */
case UNITY_FLOAT_IS_DET:
case UNITY_FLOAT_IS_DET: /* A determinate number is non infinite and not NaN. */
case UNITY_FLOAT_IS_NOT_DET:
if (isinf(actual) || isnan(actual))
is_trait = 0;
else
is_trait = 1;
is_trait = !isinf(actual) && !isnan(actual);
break;
default:
......@@ -878,11 +874,11 @@ void UnityAssertDoubleSpecial(const UNITY_DOUBLE actual,
{
case UNITY_FLOAT_IS_INF:
case UNITY_FLOAT_IS_NOT_INF:
is_trait = isinf(actual) & ispos(actual);
is_trait = isinf(actual) && (actual > 0);
break;
case UNITY_FLOAT_IS_NEG_INF:
case UNITY_FLOAT_IS_NOT_NEG_INF:
is_trait = isinf(actual) & isneg(actual);
is_trait = isinf(actual) && (actual < 0);
break;
case UNITY_FLOAT_IS_NAN:
......@@ -890,13 +886,9 @@ void UnityAssertDoubleSpecial(const UNITY_DOUBLE actual,
is_trait = isnan(actual) ? 1 : 0;
break;
/* A determinate number is non infinite and not NaN. (therefore the opposite of the two above) */
case UNITY_FLOAT_IS_DET:
case UNITY_FLOAT_IS_DET: /* A determinate number is non infinite and not NaN. */
case UNITY_FLOAT_IS_NOT_DET:
if (isinf(actual) || isnan(actual))
is_trait = 0;
else
is_trait = 1;
is_trait = !isinf(actual) && !isnan(actual);
break;
default:
......
......@@ -182,6 +182,7 @@
#endif
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))
......@@ -193,14 +194,6 @@ typedef UNITY_FLOAT_TYPE UNITY_FLOAT;
#define isnan(n) ((n != n) ? 1 : 0)
#endif
#ifndef isneg
#define isneg(n) ((n < 0.0f) ? 1 : 0)
#endif
#ifndef ispos
#define ispos(n) ((n > 0.0f) ? 1 : 0)
#endif
#endif
/*-------------------------------------------------------
......@@ -229,7 +222,7 @@ typedef UNITY_FLOAT_TYPE UNITY_FLOAT;
/* Double Floating Point Support */
#ifndef UNITY_DOUBLE_PRECISION
#define UNITY_DOUBLE_PRECISION (1e-12f)
#define UNITY_DOUBLE_PRECISION (1e-12)
#endif
#ifndef UNITY_DOUBLE_TYPE
......
......@@ -3281,8 +3281,9 @@ void testFloatPrinting(void)
TEST_ASSERT_EQUAL_PRINT_FLOATING("8.3099991e+09", 8309999104.0f);
TEST_ASSERT_EQUAL_PRINT_FLOATING("1.0e+10", 1.0e+10f);
TEST_ASSERT_EQUAL_PRINT_FLOATING("1.0e+10", 10000000000.0f);
TEST_ASSERT_EQUAL_PRINT_FLOATING("1.00005499e+10", 1.000055e+10f);
TEST_ASSERT_EQUAL_PRINT_FLOATING("1.10000006e+38", 1.10000005e+38f);
/* Some compilers have trouble with inexact float constants, a float cast works generally */
TEST_ASSERT_EQUAL_PRINT_FLOATING("1.00005499e+10", (float)1.000055e+10f);
TEST_ASSERT_EQUAL_PRINT_FLOATING("1.10000006e+38", (float)1.10000005e+38f);
TEST_ASSERT_EQUAL_PRINT_FLOATING("1.63529943e+10", 1.63529943e+10f);
TEST_ASSERT_EQUAL_PRINT_FLOATING("3.40282347e+38", 3.40282346638e38f);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册