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

Skip to content

<xlocnum>: "multiply by power of 10" logic is imprecise #1582

@statementreply

Description

@statementreply

Describe the bug

_Stodx_v2 and _Stofx_v2 contains:

STL/stl/inc/xlocnum

Lines 58 to 60 in b1fbbdc

if (_Pten != 0) {
_Val *= _CSTD pow(10.0, static_cast<double>(_Pten));
}

Like almost all of our pre-charconv floating-point formatting, I believe that this is incorrect - dividing by a power of 10 isn't an exact operation.

I believe that this code path is only activated when the integral part of the significand is longer than 768 digits (which overflows without a negative exponent).

Command-line test case

D:\Temp>type long_num_get.cpp
#include <cassert>
#include <sstream>
#include <string>

using namespace std;

int main() {
    istringstream iss{"1" + string(2000, '0') + "e-2000"};
    double x;
    assert(iss >> x);
    assert(x == 1.0);
    return 0;
}
D:\Temp>cl /EHsc /W4 /WX long_num_get.cpp
Microsoft (R) C/C++ Optimizing Compiler Version 19.28.29812 for x64
Copyright (C) Microsoft Corporation.  All rights reserved.

long_num_get.cpp
Microsoft (R) Incremental Linker Version 14.28.29812.0
Copyright (C) Microsoft Corporation.  All rights reserved.

/out:long_num_get.exe
long_num_get.obj

D:\Temp>.\long_num_get.exe
Assertion failed: iss >> x, file long_num_get.cpp, line 10

STL version

Microsoft Visual Studio Community 2019 Preview
版本 16.9.0 Preview 3.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