File tree 2 files changed +17
-4
lines changed
2 files changed +17
-4
lines changed Original file line number Diff line number Diff line change @@ -337,10 +337,12 @@ void UnityPrintFloat(const UNITY_DOUBLE input_number)
337
337
static const int sig_digits = 9 ;
338
338
static const UNITY_INT32 min_scaled = 100000000 ;
339
339
static const UNITY_INT32 max_scaled = 1000000000 ;
340
+ static const UNITY_DOUBLE epsilon = UNITY_DOUBLE_PRECISION ;
340
341
#else
341
342
static const int sig_digits = 7 ;
342
343
static const UNITY_INT32 min_scaled = 1000000 ;
343
344
static const UNITY_INT32 max_scaled = 10000000 ;
345
+ static const UNITY_DOUBLE epsilon = UNITY_FLOAT_PRECISION ;
344
346
#endif
345
347
346
348
UNITY_DOUBLE number = input_number ;
@@ -353,7 +355,7 @@ void UnityPrintFloat(const UNITY_DOUBLE input_number)
353
355
}
354
356
355
357
/* handle zero, NaN, and +/- infinity */
356
- if (number == 0.0f )
358
+ if (UNITY_ABS ( number ) < epsilon )
357
359
{
358
360
UnityPrint ("0" );
359
361
}
@@ -420,7 +422,7 @@ void UnityPrintFloat(const UNITY_DOUBLE input_number)
420
422
421
423
#ifndef UNITY_ROUND_TIES_AWAY_FROM_ZERO
422
424
/* round to even if exactly between two integers */
423
- if ((n & 1 ) && (((UNITY_DOUBLE )n - number ) == 0.5f ))
425
+ if ((n & 1 ) && (UNITY_ABS ((UNITY_DOUBLE )n - number - 0.5f ) < epsilon ))
424
426
n -- ;
425
427
#endif
426
428
Original file line number Diff line number Diff line change @@ -259,8 +259,14 @@ typedef UNITY_FLOAT_TYPE UNITY_FLOAT;
259
259
#ifndef UNITY_IS_NAN
260
260
#ifndef isnan
261
261
/* NaN is the only floating point value that does NOT equal itself.
262
- * Therefore if n != n, then it is NaN. */
263
- #define UNITY_IS_NAN (n ) ((n != n) ? 1 : 0 )
262
+ * Therefore if n != n, then it is NaN.
263
+ *
264
+ * Another way to define NaN is to check whether the number belongs
265
+ * simultaneously to the set of negative and positive numbers, including 0.
266
+ * Therefore if ((n >= 0) == (n < 0)), then it is NaN.
267
+ * This implementation will not cause an error with the compilation flag:
268
+ * -Werror=float-equal */
269
+ #define UNITY_IS_NAN (n ) ((((n) >= 0 .0f ) == ((n) < 0 .0f )) ? 1 : 0 )
264
270
#else
265
271
#define UNITY_IS_NAN (n ) isnan(n)
266
272
#endif
@@ -276,6 +282,11 @@ typedef UNITY_FLOAT_TYPE UNITY_FLOAT;
276
282
#endif
277
283
#endif
278
284
285
+ /* Calculates the absolute value of the given number */
286
+ #ifndef UNITY_ABS
287
+ #define UNITY_ABS (n ) (((n) < 0 ) ? -(n) : (n))
288
+ #endif
289
+
279
290
#endif
280
291
281
292
/* -------------------------------------------------------
You can’t perform that action at this time.
0 commit comments