Skip to content

Commit

Permalink
Avoiding floating-point-promotion-related errors in the test suite:
Browse files Browse the repository at this point in the history
* Using casting for properly advancing a `float` float counter.
* Made all implicit double promotions explicit.
  • Loading branch information
Eyal Rozenberg committed Jun 28, 2021
1 parent 637e24b commit eda2fec
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions test/test_suite.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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());
Expand All @@ -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());
Expand Down

0 comments on commit eda2fec

Please sign in to comment.