Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion stl/inc/random
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ _INLINE_VAR constexpr int _Nwords = 4;
template <class _Elem, class _Traits>
basic_ostream<_Elem, _Traits>& _Write(
basic_ostream<_Elem, _Traits>& _Os, long double _Dx) { // write long double to stream
int _Ex;
int _Ex = 0;
long double _Frac = _CSTD frexpl(_Dx, &_Ex);
for (int _Nw = 0; _Nw < _Nwords; ++_Nw) { // break into 31-bit words
_Frac *= _Two31;
Expand Down
16 changes: 8 additions & 8 deletions stl/inc/xlocnum
Original file line number Diff line number Diff line change
Expand Up @@ -1385,15 +1385,15 @@ protected:
const streamsize _Precision = _Is_hex ? -1 : _Iosbase.precision(); // precision setting
const int _Desired_precision =
_Float_put_desired_precision<double>(_Precision, _Float_flags); // desired precision
size_t _Bufsize = static_cast<size_t>(_Desired_precision);
if (_Is_fixed && 1e10 < _CSTD fabs(_Val)) { // f or F format
int _Ptwo;
size_t _Bufsize = static_cast<size_t>(_Desired_precision);
const bool _Is_finite = (_STD isfinite) (_Val);
if (_Is_fixed && _Is_finite && 1e10 < _CSTD fabs(_Val)) { // f or F format
int _Ptwo = 0;
(void) _CSTD frexp(_Val, &_Ptwo);
_Bufsize += _CSTD abs(_Ptwo) * 30103L / 100000L;
}

_Buf.resize(_Bufsize + 50); // add fudge factor
const bool _Is_finite = (_STD isfinite) (_Val);
const auto _Adjusted_flags = // TRANSITION, DevCom-10519861
_Is_finite ? _Iosbase.flags() : _Iosbase.flags() & ~ios_base::showpoint;

Expand All @@ -1419,15 +1419,15 @@ protected:
const streamsize _Precision = _Is_hex ? -1 : _Iosbase.precision(); // precision setting
const int _Desired_precision =
_Float_put_desired_precision<long double>(_Precision, _Float_flags); // desired precision
size_t _Bufsize = static_cast<size_t>(_Desired_precision);
if (_Is_fixed && 1e10 < _CSTD fabsl(_Val)) { // f or F format
int _Ptwo;
size_t _Bufsize = static_cast<size_t>(_Desired_precision);
const bool _Is_finite = (_STD isfinite) (_Val);
if (_Is_fixed && _Is_finite && 1e10 < _CSTD fabsl(_Val)) { // f or F format
int _Ptwo = 0;
(void) _CSTD frexpl(_Val, &_Ptwo);
_Bufsize += _CSTD abs(_Ptwo) * 30103L / 100000L;
}

_Buf.resize(_Bufsize + 50); // add fudge factor
const bool _Is_finite = (_STD isfinite) (_Val);
const auto _Adjusted_flags = // TRANSITION, DevCom-10519861
_Is_finite ? _Iosbase.flags() : _Iosbase.flags() & ~ios_base::showpoint;

Expand Down
14 changes: 9 additions & 5 deletions tests/std/tests/GH_003867_output_nan/test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,8 @@ void test_gh_3867() {
// Also test GH-4210: With setprecision(0) showpoint fixed, a bogus '.' is emitted for infinity and NaN

template <class FloatingPoint>
void test_output_nonfinite_value(const FloatingPoint x) {
void test_output_nonfinite_value(
const FloatingPoint x, const string& expected_noshowpos, const string& expected_showpos) {
const auto s1 = [x] {
ostringstream os;
os << setprecision(0) << showpoint << fixed;
Expand All @@ -72,6 +73,7 @@ void test_output_nonfinite_value(const FloatingPoint x) {
return os.str();
}();
assert(s1 == s2);
assert(s1 == expected_noshowpos);

const auto s3 = [x] {
ostringstream os;
Expand All @@ -86,17 +88,19 @@ void test_output_nonfinite_value(const FloatingPoint x) {
return os.str();
}();
assert(s3 == s4);
assert(s3 == expected_showpos);
}

template <class FloatingPoint>
void test_gh_4210() {
constexpr auto inf_val = numeric_limits<FloatingPoint>::infinity();
constexpr auto nan_val = numeric_limits<FloatingPoint>::quiet_NaN();

test_output_nonfinite_value(inf_val);
test_output_nonfinite_value(-inf_val);
test_output_nonfinite_value(nan_val);
test_output_nonfinite_value(-nan_val);
// These expected results are implementation-defined:
test_output_nonfinite_value(inf_val, "inf", "+inf");
test_output_nonfinite_value(-inf_val, "-inf", "-inf");
test_output_nonfinite_value(nan_val, "nan", "+nan");
test_output_nonfinite_value(-nan_val, "-nan(ind)", "-nan(ind)");
}

int main() {
Expand Down