From bb5ce007e6502f0a37b1cd9d948c32def8be6926 Mon Sep 17 00:00:00 2001 From: Daniel Lemire Date: Fri, 26 Jun 2020 19:03:28 -0400 Subject: [PATCH] Something better. --- src/generic/stage2/numberparsing.h | 9 ++++++--- tests/numberparsingcheck.cpp | 6 ------ 2 files changed, 6 insertions(+), 9 deletions(-) diff --git a/src/generic/stage2/numberparsing.h b/src/generic/stage2/numberparsing.h index 07aaa908c..9a9e4bef6 100644 --- a/src/generic/stage2/numberparsing.h +++ b/src/generic/stage2/numberparsing.h @@ -1,8 +1,6 @@ namespace stage2 { namespace numberparsing { -#if (FLT_EVAL_METHOD != 1) && (FLT_EVAL_METHOD != 0) -#warning "Your floating-point rounding default is inadequate and may lead to inexact parsing." -#endif + // Attempts to compute i * 10^(power) exactly; and if "negative" is // true, negate the result. // This function will only work in some cases, when it does not work, success is @@ -15,7 +13,12 @@ really_inline double compute_float_64(int64_t power, uint64_t i, bool negative, // It was described in // Clinger WD. How to read floating point numbers accurately. // ACM SIGPLAN Notices. 1990 +#if (FLT_EVAL_METHOD != 1) && (FLT_EVAL_METHOD != 0) + // We cannot be certain that x/y is rounded to nearest. + if (0 <= power && power <= 22 && i <= 9007199254740991) { +#else if (-22 <= power && power <= 22 && i <= 9007199254740991) { +#endif // convert the integer into a double. This is lossless since // 0 <= i <= 2^53 - 1. double d = double(i); diff --git a/tests/numberparsingcheck.cpp b/tests/numberparsingcheck.cpp index bcd88f329..dbcc30477 100644 --- a/tests/numberparsingcheck.cpp +++ b/tests/numberparsingcheck.cpp @@ -208,12 +208,6 @@ bool validate(const char *dirname) { } int main(int argc, char *argv[]) { -#if (FLT_EVAL_METHOD != 1) && (FLT_EVAL_METHOD != 0) - std::cout << "Your floating-point rounding default is inadequate and may lead to inexact parsing." << std::endl; - std::cout << "We are not going to check number parsing precision." << std::endl; - std::cout << "We are returning with a success condition nevertheless (to avoid noisy failing tests)." << std::endl; - return EXIT_SUCCESS; -#endif if (argc != 2) { std::cerr << "Usage: " << argv[0] << " " << std::endl;