From 9c5dac3705ce3ae83b7f23aed00fa3dc9a1634a2 Mon Sep 17 00:00:00 2001 From: Daniel Lemire Date: Wed, 11 Nov 2020 20:17:18 -0500 Subject: [PATCH] Build with pedantic flags under GNU GCC. --- include/fast_float/decimal_to_binary.h | 2 +- tests/CMakeLists.txt | 4 ++++ tests/basictest.cpp | 11 +++++------ tests/exhaustive32.cpp | 2 +- tests/exhaustive32_midpoint.cpp | 4 ++-- tests/random_string.cpp | 12 ++++++------ tests/short_random_string.cpp | 12 ++++++------ 7 files changed, 25 insertions(+), 22 deletions(-) diff --git a/include/fast_float/decimal_to_binary.h b/include/fast_float/decimal_to_binary.h index 655d37d..23cf169 100644 --- a/include/fast_float/decimal_to_binary.h +++ b/include/fast_float/decimal_to_binary.h @@ -108,7 +108,7 @@ adjusted_mantissa compute_float(int64_t q, uint64_t w) noexcept { answer.mantissa = product.high >> (upperbit + 64 - binary::mantissa_explicit_bits() - 3); - answer.power2 = power(int(q)) + upperbit - lz - binary::minimum_exponent(); + answer.power2 = int(power(int(q)) + upperbit - lz - binary::minimum_exponent()); if (answer.power2 <= 0) { // we have a subnormal? // Here have that answer.power2 <= 0 so -answer.power2 >= 0 if(-answer.power2 + 1 >= 64) { // if we have more than 64 bits below the minimum exponent, you have a zero for sure. diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index c653145..db02991 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -2,6 +2,10 @@ function(fast_float_add_cpp_test TEST_NAME) add_executable(${TEST_NAME} ${TEST_NAME}.cpp) add_test(${TEST_NAME} ${TEST_NAME}) + if(NOT WIN32) + target_compile_options(${TEST_NAME} PUBLIC -Werror -Wall -Wextra -Weffc++) + target_compile_options(${TEST_NAME} PUBLIC -Wsign-compare -Wshadow -Wwrite-strings -Wpointer-arith -Winit-self -Wconversion -Wno-sign-conversion) + endif() target_link_libraries(${TEST_NAME} PUBLIC fast_float) endfunction(fast_float_add_cpp_test) fast_float_add_cpp_test(short_random_string) diff --git a/tests/basictest.cpp b/tests/basictest.cpp index 2acf5bc..d01bd95 100644 --- a/tests/basictest.cpp +++ b/tests/basictest.cpp @@ -192,7 +192,6 @@ bool test_scientific_only() { return false; } input = "3.14e10"; - result; answer = fast_float::from_chars(input.data(), input.data()+input.size(), result, fast_float::chars_format::scientific); if(answer.ec != std::errc()) { std::cerr << "It is scientific!\n"; @@ -450,7 +449,7 @@ int main() { Assert(basic_test_32bit("0.0015924838953651488",0x1.a175cap-10f)); Assert(basic_test_32bit("0.0008602388261351734",0.0008602388261351734f)); Assert(basic_test_32bit("0.00036393293703440577",0x1.7d9c82p-12f)); - Assert(basic_test_32bit("0.00013746770127909258",0.00013746770127909258)); + Assert(basic_test_32bit("0.00013746770127909258",0.00013746770127909258f)); Assert(basic_test_32bit("16407.9462890625", 16407.9462890625f)); Assert(basic_test_32bit("1.1754947011469036e-38", 0x1.000006p-126f)); Assert(basic_test_32bit("7.0064923216240854e-46", 0x1p-149f)); @@ -458,7 +457,7 @@ int main() { Assert(basic_test_32bit("0e9999999999999999999999999999", 0)); Assert(basic_test_32bit("1234456789012345678901234567890e9999999999999999999999999999", std::numeric_limits::infinity())); Assert(basic_test_32bit("4.7019774032891500318749461488889827112746622270883500860350068251e-38",4.7019774032891500318749461488889827112746622270883500860350068251e-38f)); - Assert(basic_test_32bit("3.1415926535897932384626433832795028841971693993751058209749445923078164062862089986280348253421170679", 3.1415926535897932384626433832795028841971693993751058209749445923078164062862089986280348253421170679)); + Assert(basic_test_32bit("3.1415926535897932384626433832795028841971693993751058209749445923078164062862089986280348253421170679", 3.1415926535897932384626433832795028841971693993751058209749445923078164062862089986280348253421170679f)); Assert(basic_test_32bit("2.3509887016445750159374730744444913556373311135441750430175034126e-38", 2.3509887016445750159374730744444913556373311135441750430175034126e-38f)); Assert(basic_test_32bit("+1", 1)); Assert(basic_test_32bit("2e3000", std::numeric_limits::infinity())); @@ -472,9 +471,9 @@ int main() { Assert(basic_test_32bit("3.4028234665e38", 0x1.fffffep+127f)); Assert(basic_test_32bit("3.4028234666e38", 0x1.fffffep+127f)); Assert(basic_test_32bit("0.000000000000000000000000000000000000011754943508222875079687365372222456778186655567720875215087517062784172594547271728515625", 0.000000000000000000000000000000000000011754943508222875079687365372222456778186655567720875215087517062784172594547271728515625)); - Assert(basic_test_32bit("0.00000000000000000000000000000000000000000000140129846432481707092372958328991613128026194187651577175706828388979108268586060148663818836212158203125", 0.00000000000000000000000000000000000000000000140129846432481707092372958328991613128026194187651577175706828388979108268586060148663818836212158203125)); - Assert(basic_test_32bit("0.00000000000000000000000000000000000002350988561514728583455765982071533026645717985517980855365926236850006129930346077117064851336181163787841796875", 0.00000000000000000000000000000000000002350988561514728583455765982071533026645717985517980855365926236850006129930346077117064851336181163787841796875)); - Assert(basic_test_32bit("0.00000000000000000000000000000000000001175494210692441075487029444849287348827052428745893333857174530571588870475618904265502351336181163787841796875", 0.00000000000000000000000000000000000001175494210692441075487029444849287348827052428745893333857174530571588870475618904265502351336181163787841796875)); + Assert(basic_test_32bit("0.00000000000000000000000000000000000000000000140129846432481707092372958328991613128026194187651577175706828388979108268586060148663818836212158203125", 0.00000000000000000000000000000000000000000000140129846432481707092372958328991613128026194187651577175706828388979108268586060148663818836212158203125f)); + Assert(basic_test_32bit("0.00000000000000000000000000000000000002350988561514728583455765982071533026645717985517980855365926236850006129930346077117064851336181163787841796875", 0.00000000000000000000000000000000000002350988561514728583455765982071533026645717985517980855365926236850006129930346077117064851336181163787841796875f)); + Assert(basic_test_32bit("0.00000000000000000000000000000000000001175494210692441075487029444849287348827052428745893333857174530571588870475618904265502351336181163787841796875", 0.00000000000000000000000000000000000001175494210692441075487029444849287348827052428745893333857174530571588870475618904265502351336181163787841796875f)); std::cout << std::endl; Assert(powers_of_ten()); diff --git a/tests/exhaustive32.cpp b/tests/exhaustive32.cpp index 5116e07..dd354d9 100644 --- a/tests/exhaustive32.cpp +++ b/tests/exhaustive32.cpp @@ -19,7 +19,7 @@ void allvalues() { std::cout << "."; std::cout.flush(); } - uint32_t word = w; + uint32_t word = uint32_t(w); memcpy(&v, &word, sizeof(v)); { diff --git a/tests/exhaustive32_midpoint.cpp b/tests/exhaustive32_midpoint.cpp index 9e5b356..7c2080f 100644 --- a/tests/exhaustive32_midpoint.cpp +++ b/tests/exhaustive32_midpoint.cpp @@ -53,7 +53,7 @@ void allvalues() { std::cout << "."; std::cout.flush(); } - uint32_t word = w; + uint32_t word = uint32_t(w); memcpy(&v, &word, sizeof(v)); if(std::isfinite(v)) { float nextf = std::nextafterf(v, INFINITY); @@ -64,7 +64,7 @@ void allvalues() { double v2{nextf}; assert(float(v2) == nextf); double midv{v1 + (v2 - v1) / 2}; - float expected_midv(midv); + float expected_midv = float(midv); const char *string_end = to_string(midv, buffer); float str_answer; diff --git a/tests/random_string.cpp b/tests/random_string.cpp index 01c1f10..9f8732b 100644 --- a/tests/random_string.cpp +++ b/tests/random_string.cpp @@ -24,7 +24,7 @@ double cygwin_strtod_l(const char* start, char** end) { class RandomEngine { public: RandomEngine() = delete; - RandomEngine(int new_seed) { wyhash64_x_ = new_seed; }; + RandomEngine(int new_seed) : wyhash64_x_(new_seed) {}; uint64_t next() { // Adapted from https://github.com/wangyi-fudan/wyhash/blob/master/wyhash.h // Inspired from @@ -47,7 +47,7 @@ public: /* if (min == max) { return min; }*/ - int s = max - min + 1; + uint64_t s = uint64_t(max - min + 1); uint64_t x = next(); fast_float::value128 m = fast_float::full_multiplication(x, s); uint64_t l = m.low; @@ -59,7 +59,7 @@ public: l = m.low; } } - return (m.high) + min; + return int(m.high + min); } int next_digit() { return next_ranged_int(0, 9); } @@ -78,8 +78,8 @@ size_t build_random_string(RandomEngine &rand, char *buffer) { number_of_digits = rand.next_ranged_int(1, 2000); } int location_of_decimal_separator = rand.next_ranged_int(1, number_of_digits); - for (size_t i = 0; i < number_of_digits; i++) { - if (i == location_of_decimal_separator) { + for (size_t i = 0; i < size_t(number_of_digits); i++) { + if (i == size_t(location_of_decimal_separator)) { buffer[pos++] = '.'; } buffer[pos++] = char(rand.next_digit() + '0'); @@ -98,7 +98,7 @@ size_t build_random_string(RandomEngine &rand, char *buffer) { } } number_of_digits = rand.next_ranged_int(1, 3); - for (size_t i = 0; i < number_of_digits; i++) { + for (size_t i = 0; i < size_t(number_of_digits); i++) { buffer[pos++] = char(rand.next_digit() + '0'); } } diff --git a/tests/short_random_string.cpp b/tests/short_random_string.cpp index 1ced98f..42389bc 100644 --- a/tests/short_random_string.cpp +++ b/tests/short_random_string.cpp @@ -24,7 +24,7 @@ double cygwin_strtod_l(const char* start, char** end) { class RandomEngine { public: RandomEngine() = delete; - RandomEngine(int new_seed) { wyhash64_x_ = new_seed; }; + RandomEngine(int new_seed) : wyhash64_x_(new_seed) { }; uint64_t next() { // Adapted from https://github.com/wangyi-fudan/wyhash/blob/master/wyhash.h // Inspired from @@ -47,7 +47,7 @@ public: /* if (min == max) { return min; }*/ - int s = max - min + 1; + uint64_t s = uint64_t(max - min + 1); uint64_t x = next(); fast_float::value128 m = fast_float::full_multiplication(x, s); uint64_t l = m.low; @@ -59,7 +59,7 @@ public: l = m.low; } } - return (m.high) + min; + return int(m.high + min); } int next_digit() { return next_ranged_int(0, 9); } @@ -74,8 +74,8 @@ size_t build_random_string(RandomEngine &rand, char *buffer) { } int number_of_digits = rand.next_ranged_int(1, 19); int location_of_decimal_separator = rand.next_ranged_int(1, number_of_digits); - for (size_t i = 0; i < number_of_digits; i++) { - if (i == location_of_decimal_separator) { + for (size_t i = 0; i < size_t(number_of_digits); i++) { + if (i == size_t(location_of_decimal_separator)) { buffer[pos++] = '.'; } buffer[pos++] = char(rand.next_digit() + '0'); @@ -94,7 +94,7 @@ size_t build_random_string(RandomEngine &rand, char *buffer) { } } number_of_digits = rand.next_ranged_int(1, 3); - for (size_t i = 0; i < number_of_digits; i++) { + for (size_t i = 0; i < size_t(number_of_digits); i++) { buffer[pos++] = char(rand.next_digit() + '0'); } }