-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Closed
Labels
bugSomething isn't workingSomething isn't workingfixedSomething works now, yay!Something works now, yay!performanceMust go fasterMust go faster
Description
This file was previously overhauled to call strtod() and strtof(), fixing long-standing correctness and performance issues:
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; | |
| } |
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:
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:
- Eliminate the
_ENABLE_V2_BEHAVIORsentinel value and make it unconditional. - Eliminate lots of dead code (whole functions and source files).
- Eliminate other
deadlogic; e.g._Val *= _CSTD pow(10.0, static_cast<double>(_Pten));isalmost 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.
0xprefixes) - 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
Labels
bugSomething isn't workingSomething isn't workingfixedSomething works now, yay!Something works now, yay!performanceMust go fasterMust go faster