Merge pull request #277 from dalle/issue276-plus-minus-infnan

Issue276 plus/minus handling in parse_infnan
This commit is contained in:
Daniel Lemire 2024-11-19 10:39:49 -05:00 committed by GitHub
commit 8e5f76ce73
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 17 additions and 12 deletions

View File

@ -8,3 +8,4 @@ Lénárd Szolnoki
Jan Pharago
Maya Warrier
Taha Khokhar
Anders Dalvander

View File

@ -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;

View File

@ -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);
@ -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

View File

@ -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},
@ -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];