Skip to content

Commit

Permalink
fix #276: parse_infnan handles FASTFLOAT_ALLOWS_LEADING_PLUS correctly
Browse files Browse the repository at this point in the history
  • Loading branch information
dalle committed Nov 17, 2024
1 parent 72b2a73 commit 23787fc
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 9 deletions.
1 change: 1 addition & 0 deletions CONTRIBUTORS
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@ Lénárd Szolnoki
Jan Pharago
Maya Warrier
Taha Khokhar
Anders Dalvander
15 changes: 6 additions & 9 deletions include/fast_float/parse_number.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,18 +25,15 @@ from_chars_result_t<UC> FASTFLOAT_CONSTEXPR14 parse_infnan(UC const *first,
from_chars_result_t<UC> 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<UC>(), 3)) {
answer.ptr = (first += 3);
Expand Down

0 comments on commit 23787fc

Please sign in to comment.