From 269867fa43c28b4872ae4e032c57a49ea30fc355 Mon Sep 17 00:00:00 2001 From: Anders Dalvander Date: Sun, 17 Nov 2024 16:17:35 +0100 Subject: [PATCH 1/5] spelling --- include/fast_float/parse_number.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/fast_float/parse_number.h b/include/fast_float/parse_number.h index 6d883fb9..5699bba7 100644 --- a/include/fast_float/parse_number.h +++ b/include/fast_float/parse_number.h @@ -93,7 +93,7 @@ fastfloat_really_inline bool rounds_to_nearest() noexcept { // However, it is expected to be much faster than the fegetround() // function call. // - // The volatile keywoard prevents the compiler from computing the function + // The volatile keyword prevents the compiler from computing the function // at compile-time. // There might be other ways to prevent compile-time optimizations (e.g., // asm). The value does not need to be std::numeric_limits::min(), any From 1df71f1e9d0b225e71bdb93d07ee72218175e876 Mon Sep 17 00:00:00 2001 From: Anders Dalvander Date: Sun, 17 Nov 2024 16:20:44 +0100 Subject: [PATCH 2/5] add failing test --- tests/rcppfastfloat_test.cpp | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/tests/rcppfastfloat_test.cpp b/tests/rcppfastfloat_test.cpp index 4017e109..fb6cfb7a 100644 --- a/tests/rcppfastfloat_test.cpp +++ b/tests/rcppfastfloat_test.cpp @@ -41,7 +41,10 @@ bool eddelbuettel() { "-.1", "+.1", "1e+1", - "+1e1"}; + "+1e1", + "-+0", + "-+inf", + "-+nan"}; std::vector> expected_results = { {true, std::numeric_limits::infinity()}, {true, 3.16227766016838}, @@ -75,6 +78,9 @@ bool eddelbuettel() { {true, 0.1}, {true, 10}, {true, 10}, + {false, -1}, + {false, -1}, + {false, -1}, }; for (size_t i = 0; i < inputs.size(); i++) { const std::string &input = inputs[i]; From 72b2a7382ad766d48a20190a6b1bbccecbd117f2 Mon Sep 17 00:00:00 2001 From: Anders Dalvander Date: Sun, 17 Nov 2024 16:22:05 +0100 Subject: [PATCH 3/5] const ness --- include/fast_float/ascii_number.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/fast_float/ascii_number.h b/include/fast_float/ascii_number.h index c027435e..a817b791 100644 --- a/include/fast_float/ascii_number.h +++ b/include/fast_float/ascii_number.h @@ -476,7 +476,7 @@ parse_int_string(UC const *p, UC const *pend, T &value, int base) { UC const *const first = p; - bool negative = (*p == UC('-')); + bool const negative = (*p == UC('-')); if (!std::is_signed::value && negative) { answer.ec = std::errc::invalid_argument; answer.ptr = first; From 23787fc71a9179e991c1bbeb0ca8f6448491d14f Mon Sep 17 00:00:00 2001 From: Anders Dalvander Date: Sun, 17 Nov 2024 16:23:01 +0100 Subject: [PATCH 4/5] fix #276: parse_infnan handles FASTFLOAT_ALLOWS_LEADING_PLUS correctly --- CONTRIBUTORS | 1 + include/fast_float/parse_number.h | 15 ++++++--------- 2 files changed, 7 insertions(+), 9 deletions(-) diff --git a/CONTRIBUTORS b/CONTRIBUTORS index da1e5d68..4b705554 100644 --- a/CONTRIBUTORS +++ b/CONTRIBUTORS @@ -8,3 +8,4 @@ Lénárd Szolnoki Jan Pharago Maya Warrier Taha Khokhar +Anders Dalvander diff --git a/include/fast_float/parse_number.h b/include/fast_float/parse_number.h index 5699bba7..8b9fb850 100644 --- a/include/fast_float/parse_number.h +++ b/include/fast_float/parse_number.h @@ -25,18 +25,15 @@ from_chars_result_t FASTFLOAT_CONSTEXPR14 parse_infnan(UC const *first, from_chars_result_t answer{}; answer.ptr = first; answer.ec = std::errc(); // be optimistic - bool minusSign = false; - if (*first == - UC('-')) { // assume first < last, so dereference without checks; - // C++17 20.19.3.(7.1) explicitly forbids '+' here - minusSign = true; - ++first; - } + bool const minusSign = (*first == UC('-')); // assume first < last, so dereference without checks; #ifdef FASTFLOAT_ALLOWS_LEADING_PLUS // disabled by default - if (*first == UC('+')) { + if ((*first == UC('-')) || (*first == UC('+'))) { +#else + // C++17 20.19.3.(7.1) explicitly forbids '+' sign here + if (*first == UC('-')) { +#endif ++first; } -#endif if (last - first >= 3) { if (fastfloat_strncasecmp(first, str_const_nan(), 3)) { answer.ptr = (first += 3); From b635dec11a40feb3160a19dc2f587669ba3a66e8 Mon Sep 17 00:00:00 2001 From: Anders Dalvander Date: Tue, 19 Nov 2024 10:32:37 +0100 Subject: [PATCH 5/5] clang format --- include/fast_float/parse_number.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/include/fast_float/parse_number.h b/include/fast_float/parse_number.h index 8b9fb850..34810234 100644 --- a/include/fast_float/parse_number.h +++ b/include/fast_float/parse_number.h @@ -25,7 +25,8 @@ from_chars_result_t FASTFLOAT_CONSTEXPR14 parse_infnan(UC const *first, from_chars_result_t answer{}; answer.ptr = first; answer.ec = std::errc(); // be optimistic - bool const minusSign = (*first == UC('-')); // assume first < last, so dereference without checks; + // assume first < last, so dereference without checks; + bool const minusSign = (*first == UC('-')); #ifdef FASTFLOAT_ALLOWS_LEADING_PLUS // disabled by default if ((*first == UC('-')) || (*first == UC('+'))) { #else