From 60b23dc8a4c90215407fda2fba8b7c1b4872b4e0 Mon Sep 17 00:00:00 2001 From: mvandervoord Date: Mon, 28 Oct 2019 13:43:32 -0400 Subject: [PATCH] Stopped supported -0 as a float output because (a) it is non-portable, only existing on some architectures and (b) relies on the undefined behavior of 1.0/0.0 --- src/unity.c | 4 ++-- test/tests/testunity.c | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/unity.c b/src/unity.c index 9b80605..1b55791 100644 --- a/src/unity.c +++ b/src/unity.c @@ -429,14 +429,14 @@ void UnityPrintFloat(const UNITY_DOUBLE input_number) UNITY_DOUBLE number = input_number; /* print minus sign (including for negative zero) */ - if ((number < 0.0f) || ((number == 0.0f) && ((1.0f / number) < 0.0f))) + if (number < 0.0f) { UNITY_OUTPUT_CHAR('-'); number = -number; } /* handle zero, NaN, and +/- infinity */ - if (number == 0.0f) + if (number == 0.0f) { UnityPrint("0"); } diff --git a/test/tests/testunity.c b/test/tests/testunity.c index 2771a99..c9712ed 100644 --- a/test/tests/testunity.c +++ b/test/tests/testunity.c @@ -7722,7 +7722,7 @@ void testDoublePrinting(void) TEST_ASSERT_EQUAL_PRINT_FLOATING("16.0000006", 16.0000006); TEST_ASSERT_EQUAL_PRINT_FLOATING("999999999", 999999999.0); /*Last full print integer*/ - TEST_ASSERT_EQUAL_PRINT_FLOATING("-0", -0.0); + TEST_ASSERT_EQUAL_PRINT_FLOATING("0", -0.0); /* -0 no supported on all targets */ TEST_ASSERT_EQUAL_PRINT_FLOATING("-4.99e-07", -0.000000499); TEST_ASSERT_EQUAL_PRINT_FLOATING("-5.0000005e-07", -0.00000050000005); TEST_ASSERT_EQUAL_PRINT_FLOATING("-0.100469499", -0.100469499); -- GitLab