From 7cefc3f3a7f1e2041a5a007d90a7c28d56592a33 Mon Sep 17 00:00:00 2001 From: Eyal Rozenberg Date: Mon, 28 Jun 2021 16:12:26 +0300 Subject: [PATCH 1/3] Avoid float-equal GCC warning - as `printf.c` does equality-compare floating-point values. --- Makefile | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/Makefile b/Makefile index 7b28a1a1..423cb183 100644 --- a/Makefile +++ b/Makefile @@ -131,8 +131,7 @@ GCCFLAGS = $(C_INCLUDES) \ -fdata-sections \ -fverbose-asm \ -Wextra \ - -Wunused-parameter \ - -Wfloat-equal + -Wunused-parameter CFLAGS = $(GCCFLAGS) \ -Wunsuffixed-float-constants \ From 637e24b7292aa350ad7c966a6383df8d62660517 Mon Sep 17 00:00:00 2001 From: Eyal Rozenberg Date: Mon, 28 Jun 2021 16:13:07 +0300 Subject: [PATCH 2/3] Avoid spurious warning regarding sign loss in conversion to `unsigned long`. --- printf.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/printf.c b/printf.c index 8a700add..a2ff1c74 100644 --- a/printf.c +++ b/printf.c @@ -561,7 +561,7 @@ static size_t _etoa(out_fct_type out, char* buffer, size_t idx, size_t maxlen, d // output the exponential symbol out((flags & FLAGS_UPPERCASE) ? 'E' : 'e', buffer, idx++, maxlen); // output the exponent value - idx = _ntoa_long(out, buffer, idx, maxlen, (expval < 0) ? -expval : expval, expval < 0, 10, 0, minwidth-1, FLAGS_ZEROPAD | FLAGS_PLUS); + idx = _ntoa_long(out, buffer, idx, maxlen, (unsigned long) ((expval < 0) ? -expval : expval), expval < 0, 10, 0, minwidth-1, FLAGS_ZEROPAD | FLAGS_PLUS); // might need to right-pad spaces if (flags & FLAGS_LEFT) { while (idx - start_idx < width) out(' ', buffer, idx++, maxlen); From eda2fec3d90fcf425a1f5ab8833d02374c7c1d83 Mon Sep 17 00:00:00 2001 From: Eyal Rozenberg Date: Mon, 28 Jun 2021 16:13:34 +0300 Subject: [PATCH 3/3] Avoiding floating-point-promotion-related errors in the test suite: * Using casting for properly advancing a `float` float counter. * Made all implicit double promotions explicit. --- test/test_suite.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/test/test_suite.cpp b/test/test_suite.cpp index 5507c3bd..05261713 100644 --- a/test/test_suite.cpp +++ b/test/test_suite.cpp @@ -1085,7 +1085,7 @@ TEST_CASE("float", "[]" ) { test::sprintf(buffer, "%8f", INFINITY); REQUIRE(!strcmp(buffer, " inf")); - test::sprintf(buffer, "%-8f", -INFINITY); + test::sprintf(buffer, "%-8f", (double) -INFINITY); REQUIRE(!strcmp(buffer, "-inf ")); #ifndef PRINTF_DISABLE_SUPPORT_EXPONENTIAL @@ -1217,7 +1217,7 @@ TEST_CASE("float", "[]" ) { std::stringstream str; str.precision(5); for (float i = -100000; i < 100000; i += 1) { - test::sprintf(buffer, "%.5f", i / 10000); + test::sprintf(buffer, "%.5f", (double)(i / 10000)); str.str(""); str << std::fixed << i / 10000; fail = fail || !!strcmp(buffer, str.str().c_str()); @@ -1228,8 +1228,8 @@ TEST_CASE("float", "[]" ) { #ifndef PRINTF_DISABLE_SUPPORT_EXPONENTIAL // brute force exp str.setf(std::ios::scientific, std::ios::floatfield); - for (float i = -1e20; i < 1e20; i += 1e15) { - test::sprintf(buffer, "%.5f", i); + for (float i = -1e20; i < (float) 1e20; i += (float) 1e15) { + test::sprintf(buffer, "%.5f", (double) i); str.str(""); str << i; fail = fail || !!strcmp(buffer, str.str().c_str());