From 252a1c9dce56c519ebf11c26c19f451e9fe87726 Mon Sep 17 00:00:00 2001 From: Daniel Lemire Date: Mon, 6 Feb 2023 17:22:11 -0500 Subject: [PATCH] Minor fix. --- include/fast_float/parse_number.h | 4 ++++ tests/basictest.cpp | 2 ++ 2 files changed, 6 insertions(+) diff --git a/include/fast_float/parse_number.h b/include/fast_float/parse_number.h index 2493b02..3284443 100644 --- a/include/fast_float/parse_number.h +++ b/include/fast_float/parse_number.h @@ -66,6 +66,10 @@ from_chars_result parse_infnan(const char *first, const char *last, T &value) n * Credit : @mwalcott3 */ fastfloat_really_inline bool rounds_to_nearest() noexcept { + // https://lemire.me/blog/2020/06/26/gcc-not-nearest/ +#if (FLT_EVAL_METHOD != 1) && (FLT_EVAL_METHOD != 0) + return false; +#endif // See // A fast function to check your floating-point rounding mode // https://lemire.me/blog/2022/11/16/a-fast-function-to-check-your-floating-point-rounding-mode/ diff --git a/tests/basictest.cpp b/tests/basictest.cpp index 8bdd4df..433a9b5 100644 --- a/tests/basictest.cpp +++ b/tests/basictest.cpp @@ -132,7 +132,9 @@ TEST_CASE("rounds_to_nearest") { fesetround(FE_TONEAREST); std::cout << "FE_TONEAREST: fmin + 1.0f = " << iHexAndDec(fmin + 1.0f) << " 1.0f - fmin = " << iHexAndDec(1.0f - fmin) << std::endl; CHECK(fegetround() == FE_TONEAREST); +#if (FLT_EVAL_METHOD == 1) || (FLT_EVAL_METHOD == 0) CHECK(fast_float::detail::rounds_to_nearest() == true); +#endif } TEST_CASE("parse_zero") {