Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue276 plus/minus handling in parse_infnan #277

Merged
merged 5 commits into from
Nov 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
2 changes: 1 addition & 1 deletion include/fast_float/ascii_number.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<T>::value && negative) {
answer.ec = std::errc::invalid_argument;
answer.ptr = first;
Expand Down
18 changes: 8 additions & 10 deletions include/fast_float/parse_number.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,18 +25,16 @@ 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;
}
// assume first < last, so dereference without checks;
bool const minusSign = (*first == UC('-'));
#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 Expand Up @@ -93,7 +91,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<float>::min(), any
Expand Down
8 changes: 7 additions & 1 deletion tests/rcppfastfloat_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,10 @@ bool eddelbuettel() {
"-.1",
"+.1",
"1e+1",
"+1e1"};
"+1e1",
"-+0",
"-+inf",
"-+nan"};
std::vector<std::pair<bool, double>> expected_results = {
{true, std::numeric_limits<double>::infinity()},
{true, 3.16227766016838},
Expand Down Expand Up @@ -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];
Expand Down
Loading