From a16b253331f48ececae033b38cedbc042631e18d Mon Sep 17 00:00:00 2001 From: Alexander Borsuk Date: Sun, 30 Jan 2022 08:38:04 +0100 Subject: [PATCH] Fixed unit tests for faster float parsing Signed-off-by: Alexander Borsuk --- base/string_utils.cpp | 2 +- base/string_utils.hpp | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/base/string_utils.cpp b/base/string_utils.cpp index b12348431d..9468e26da9 100644 --- a/base/string_utils.cpp +++ b/base/string_utils.cpp @@ -53,7 +53,7 @@ bool ToReal(char const * start, T & result) if (*stop == 0 && start != stop && IsFinite(result)) return true; } - else if (*endptr == 0) + else if (*endptr == 0 && IsFinite(d)) { result = static_cast(d); return true; diff --git a/base/string_utils.hpp b/base/string_utils.hpp index 635dd01646..76545a3664 100644 --- a/base/string_utils.hpp +++ b/base/string_utils.hpp @@ -475,6 +475,7 @@ WARN_UNUSED_RESULT inline bool to_int32(char const * s, int32_t & i) } WARN_UNUSED_RESULT bool to_size_t(char const * s, size_t & i, int base = 10); +// Both functions return false for INF, NAN, numbers like "1." and "0.4 ". WARN_UNUSED_RESULT bool to_float(char const * s, float & f); WARN_UNUSED_RESULT bool to_double(char const * s, double & d); WARN_UNUSED_RESULT bool is_finite(double d);