Thanks to visit codestin.com
Credit goes to github.com

Skip to content

<xlocnum>: Incorrect rounding when parsing long hexadecimal floating point numbers just above midpoints #3375

@statementreply

Description

@statementreply

Describe the bug
The hexadecimal code path of num_get::do_get parses the initial 768 significant digits and discards the remaining. When the remaining digits could affect rounding, it returns an incorrect result.

Command-line test case

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

int main() {
    istringstream stream("0x1.00000000000008" + string(1000, '0') + "1p+0");
    stream >> hexfloat; // GH-1259
    double x;
    if (stream >> x) {
        cout << "actual:   " << hexfloat << x << "\n";
    } else {
        cout << "actual:   (failure)\n";
    }
    cout << "expected: 0x1.0000000000001p+0\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:   0x1.0000000000000p+0
expected: 0x1.0000000000001p+0

STL version

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

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