mirror of
https://github.com/ThrowTheSwitch/Unity.git
synced 2026-10-07 01:07:23 +00:00
Merge pull request #770 from artem-sharipov/fix-werror-float-equal-build-fail
Fix failed build with compile flag: -Werror=float-equal (#741)
This commit is contained in:
+4
-2
@@ -358,16 +358,18 @@ void UnityPrintFloat(const UNITY_DOUBLE input_number)
|
||||
static const int sig_digits = 9;
|
||||
static const UNITY_INT32 min_scaled = 100000000;
|
||||
static const UNITY_INT32 max_scaled = 1000000000;
|
||||
static const UNITY_DOUBLE epsilon = UNITY_DOUBLE_PRECISION;
|
||||
#else
|
||||
static const int sig_digits = 7;
|
||||
static const UNITY_INT32 min_scaled = 1000000;
|
||||
static const UNITY_INT32 max_scaled = 10000000;
|
||||
static const UNITY_DOUBLE epsilon = UNITY_FLOAT_PRECISION;
|
||||
#endif
|
||||
|
||||
UNITY_DOUBLE number = input_number;
|
||||
|
||||
/* handle zero, NaN, and +/- infinity */
|
||||
if (number == 0.0f)
|
||||
if (UNITY_ABS(number) < epsilon)
|
||||
{
|
||||
UnityPrint("0");
|
||||
}
|
||||
@@ -446,7 +448,7 @@ void UnityPrintFloat(const UNITY_DOUBLE input_number)
|
||||
|
||||
#ifndef UNITY_ROUND_TIES_AWAY_FROM_ZERO
|
||||
/* round to even if exactly between two integers */
|
||||
if ((n & 1) && (((UNITY_DOUBLE)n - number) == 0.5f))
|
||||
if ((n & 1) && (UNITY_ABS((UNITY_DOUBLE)n - number - 0.5f) < epsilon))
|
||||
n--;
|
||||
#endif
|
||||
|
||||
|
||||
+13
-2
@@ -266,8 +266,14 @@ typedef UNITY_FLOAT_TYPE UNITY_FLOAT;
|
||||
#ifndef UNITY_IS_NAN
|
||||
#ifndef isnan
|
||||
/* NaN is the only floating point value that does NOT equal itself.
|
||||
* Therefore if n != n, then it is NaN. */
|
||||
#define UNITY_IS_NAN(n) ((n != n) ? 1 : 0)
|
||||
* Therefore if n != n, then it is NaN.
|
||||
*
|
||||
* Another way to define NaN is to check whether the number belongs
|
||||
* simultaneously to the set of negative and positive numbers, including 0.
|
||||
* Therefore if ((n >= 0) == (n < 0)), then it is NaN.
|
||||
* This implementation will not cause an error with the compilation flag:
|
||||
* -Werror=float-equal */
|
||||
#define UNITY_IS_NAN(n) ((((n) >= 0.0f) == ((n) < 0.0f)) ? 1 : 0)
|
||||
#else
|
||||
#define UNITY_IS_NAN(n) isnan(n)
|
||||
#endif
|
||||
@@ -283,6 +289,11 @@ typedef UNITY_FLOAT_TYPE UNITY_FLOAT;
|
||||
#endif
|
||||
#endif
|
||||
|
||||
/* Calculates the absolute value of the given number */
|
||||
#ifndef UNITY_ABS
|
||||
#define UNITY_ABS(n) (((n) < 0) ? -(n) : (n))
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
/*-------------------------------------------------------
|
||||
|
||||
Reference in New Issue
Block a user