Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
achabense committed Aug 21, 2023
1 parent 60f1885 commit 766b41b
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 4 deletions.
4 changes: 0 additions & 4 deletions stl/inc/xlocnum
Original file line number Diff line number Diff line change
Expand Up @@ -1019,10 +1019,6 @@ private:
_Seendigit = true;
}

if (_Seendigit) {
*_Ptr++ = '0'; // put one back
}

for (size_t _Idx; _First != _Last && (_Idx = _STD _Find_elem(_Atoms, *_First)) < _Offset_dec_digit_end;
_Seendigit = true, (void) ++_First) {
if (_Exponent_part < PTRDIFF_MAX / 10
Expand Down
21 changes: 21 additions & 0 deletions tests/std/tests/LWG2381_num_get_floating_point/test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -532,6 +532,23 @@ void test_gh_3378() {
}
}

// Also test GH-3980 <iostream>: Wrong reading of float values
template <class Flt>
void test_gh_3980() {
auto test_case = [](const char* str, double expected) {
Flt val = 0;
istringstream{str} >> val;
assert((ostringstream{} << val).str() == (ostringstream{} << expected).str());
};

test_case("0x1p+07", 0x1p+07);
test_case("1e+07", 1e+07);
test_case("1e+0", 1);
test_case("1e-0", 1);
test_case("1e-07", 1e-07);
test_case("0x1p-07", 0x1p-07);
}

#if _HAS_CXX17
void test_float_from_char_cases() {
for (const auto& test_case : float_from_chars_test_cases) {
Expand Down Expand Up @@ -589,6 +606,10 @@ int main() {
test_gh_3378<double>();
test_gh_3378<long double>();

test_gh_3980<float>();
test_gh_3980<double>();
test_gh_3980<long double>();

#if _HAS_CXX17
test_float_from_char_cases();
test_double_from_char_cases<double>();
Expand Down

0 comments on commit 766b41b

Please sign in to comment.