Skip to content

<xlocnum>: Incorrect result when parsing 9.999999... #3376

Description

@statementreply

Command-line test case

D:\Temp>type test.cpp
#include <iostream>
#include <sstream>
#include <string>
using namespace std;

int main() {
    istringstream stream("9." + string(1000, '9'));
    cout.precision(17);
    double x;
    if (stream >> x) {
        cout << "actual:   " << x << "\n";
    } else {
        cout << "actual:   (failure)\n";
    }
    cout << "expected: 10\n";
    return 0;
}
D:\Temp>cl /EHsc /W4 test.cpp
用于 x64 的 Microsoft (R) C/C++ 优化编译器 19.35.32213 版
版权所有(C) Microsoft Corporation。保留所有权利。

test.cpp
Microsoft (R) Incremental Linker Version 14.35.32213.0
Copyright (C) Microsoft Corporation.  All rights reserved.

/out:test.exe
test.obj

D:\Temp>.\test
actual:   100
expected: 10

STL version

Microsoft Visual Studio Community 2022 (64 位) - Preview
版本 17.5.0 Preview 5.0

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingfixedSomething works now, yay!

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions