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

Skip to content

<xlocnum>: Finish overhauling num_get #264

@StephanTLavavej

Description

@StephanTLavavej

This file was previously overhauled to call strtod() and strtof(), fixing long-standing correctness and performance issues:

STL/stl/inc/xlocnum

Lines 48 to 62 in 58c5c4d

inline double _Stodx_v2(const char* _Str, char** _Endptr, int _Pten, int* _Perr) { // convert string to double
int& _Errno_ref = errno; // Nonzero cost, pay it once
const int _Orig = _Errno_ref;
_Errno_ref = 0;
double _Val = _CSTD strtod(_Str, _Endptr);
*_Perr = _Errno_ref;
_Errno_ref = _Orig;
if (_Pten != 0) {
_Val *= _CSTD pow(10.0, static_cast<double>(_Pten));
}
return _Val;
}

STL/stl/inc/xlocnum

Lines 65 to 79 in 58c5c4d

inline float _Stofx_v2(const char* _Str, char** _Endptr, int _Pten, int* _Perr) { // convert string to float
int& _Errno_ref = errno; // Nonzero cost, pay it once
const int _Orig = _Errno_ref;
_Errno_ref = 0;
float _Val = _CSTD strtof(_Str, _Endptr);
*_Perr = _Errno_ref;
_Errno_ref = _Orig;
if (_Pten != 0) {
_Val *= _CSTD powf(10.0f, static_cast<float>(_Pten));
}
return _Val;
}

For binary compatibility, the new-ish machinery is activated by a sentinel value:

STL/stl/inc/xlocnum

Lines 563 to 565 in 58c5c4d

// TRANSITION, ABI: Sentinel value used by num_get::do_get()
// to enable correct "V2" behavior in _Getffld() and _Getffldx()
#define _ENABLE_V2_BEHAVIOR 1000000000

In vNext, we need to:

  1. Eliminate the _ENABLE_V2_BEHAVIOR sentinel value and make it unconditional.
  2. Eliminate lots of dead code (whole functions and source files).
  3. Eliminate other dead logic; e.g. _Val *= _CSTD pow(10.0, static_cast<double>(_Pten)); is almost certainly dead (which is good, because it would be incorrect - anything that wants to multiply by a power of ten is highly suspicious) incorrect, see <xlocnum>: "multiply by power of 10" logic is imprecise #1582.

It may be possible to go further. Using charconv for iostreams floating-point would result in dramatic performance wins, but we'd have to solve issues like:

  • Locale sensitivity
  • Differing formats (e.g. 0x prefixes)
  • Runtime rounding modes

vNext note: Resolving this issue will require breaking binary compatibility. We won't be able to accept pull requests for this issue until the vNext branch is available. See #169 for more information.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingfixedSomething works now, yay!performanceMust go faster

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions