Skip to content

LWG-2381 Inconsistency in parsing floating point numbers #2388

@StephanTLavavej

Description

@StephanTLavavej

LWG-2381 Inconsistency in parsing floating point numbers

C:\Temp>type meow.cpp
#include <cassert>
#include <cstdlib>
#include <sstream>

bool test(const char* const str, const double correct) {
    const double dbl1 = std::strtod(str, nullptr);
    assert(dbl1 == correct);

    std::istringstream iss(str);
    double dbl2 = 0.0;
    iss >> dbl2;
    return dbl2 == correct;
}

int main() {
    assert(test("1.0123456789e+5", 0x1.8b7291613d31cp+16));
    assert(test("0x1.01234567p+5", 0x1.01234567p+5));
    assert(test("0x1.89abcdefp-5", 0x1.89abcdefp-5));
}
C:\Temp>cl /EHsc /nologo /W4 /MTd meow.cpp && meow
meow.cpp
Assertion failed: test("0x1.01234567p+5", 0x1.01234567p+5), file meow.cpp, line 17

This was voted into the Working Paper in October 2021, see #2236.

Metadata

Metadata

Assignees

No one assigned

    Labels

    LWGLibrary Working Group issuefixedSomething works now, yay!

    Type

    No type

    Projects

    Status

    Done

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions