Skip to content

Commit

Permalink
<charconv>: Fix from_chars() float tiebreaking (#2366)
Browse files Browse the repository at this point in the history
  • Loading branch information
StephanTLavavej authored Feb 23, 2022
1 parent 7b2c54b commit 89d50c5
Show file tree
Hide file tree
Showing 2 changed files with 533 additions and 27 deletions.
36 changes: 9 additions & 27 deletions stl/inc/charconv
Original file line number Diff line number Diff line change
Expand Up @@ -436,32 +436,6 @@ _NODISCARD inline _Big_integer_flt _Make_big_integer_flt_one() noexcept {
return _Xval;
}

_NODISCARD inline _Big_integer_flt _Make_big_integer_flt_u32(const uint32_t _Value) noexcept {
_Big_integer_flt _Xval{};
_Xval._Mydata[0] = _Value;
_Xval._Myused = 1;
return _Xval;
}

_NODISCARD inline _Big_integer_flt _Make_big_integer_flt_u64(const uint64_t _Value) noexcept {
_Big_integer_flt _Xval{};
_Xval._Mydata[0] = static_cast<uint32_t>(_Value);
_Xval._Mydata[1] = static_cast<uint32_t>(_Value >> 32);
_Xval._Myused = _Xval._Mydata[1] == 0 ? 1u : 2u;
return _Xval;
}

_NODISCARD inline _Big_integer_flt _Make_big_integer_flt_power_of_two(const uint32_t _Power) noexcept {
const uint32_t _Element_index = _Power / _Big_integer_flt::_Element_bits;
const uint32_t _Bit_index = _Power % _Big_integer_flt::_Element_bits;

_Big_integer_flt _Xval{};
_CSTD memset(_Xval._Mydata, 0, _Element_index * sizeof(uint32_t));
_Xval._Mydata[_Element_index] = 1u << _Bit_index;
_Xval._Myused = _Element_index + 1;
return _Xval;
}

_NODISCARD inline uint32_t _Bit_scan_reverse(const _Big_integer_flt& _Xval) noexcept {
if (_Xval._Myused == 0) {
return 0;
Expand Down Expand Up @@ -932,7 +906,15 @@ _NODISCARD inline uint64_t _Divide(_Big_integer_flt& _Numerator, const _Big_inte

_Numerator._Mydata[1] = static_cast<uint32_t>(_Uu >> 32);
_Numerator._Mydata[0] = static_cast<uint32_t>(_Uu);
_Numerator._Myused = _Numerator._Mydata[1] > 0 ? 2u : 1u;

if (_Numerator._Mydata[1] > 0) {
_Numerator._Myused = 2u;
} else if (_Numerator._Mydata[0] > 0) {
_Numerator._Myused = 1u;
} else {
_Numerator._Myused = 0u;
}

return _Quotient;
}

Expand Down
Loading

0 comments on commit 89d50c5

Please sign in to comment.