Skip to content

Commit 17cf9b9

Browse files
1 parent db57de0 commit 17cf9b9

3 files changed

Lines changed: 18 additions & 14 deletions

File tree

stl/inc/random

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ _INLINE_VAR constexpr int _Nwords = 4;
7070
template <class _Elem, class _Traits>
7171
basic_ostream<_Elem, _Traits>& _Write(
7272
basic_ostream<_Elem, _Traits>& _Os, long double _Dx) { // write long double to stream
73-
int _Ex;
73+
int _Ex = 0;
7474
long double _Frac = _CSTD frexpl(_Dx, &_Ex);
7575
for (int _Nw = 0; _Nw < _Nwords; ++_Nw) { // break into 31-bit words
7676
_Frac *= _Two31;

stl/inc/xlocnum

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1385,15 +1385,15 @@ protected:
13851385
const streamsize _Precision = _Is_hex ? -1 : _Iosbase.precision(); // precision setting
13861386
const int _Desired_precision =
13871387
_Float_put_desired_precision<double>(_Precision, _Float_flags); // desired precision
1388-
size_t _Bufsize = static_cast<size_t>(_Desired_precision);
1389-
if (_Is_fixed && 1e10 < _CSTD fabs(_Val)) { // f or F format
1390-
int _Ptwo;
1388+
size_t _Bufsize = static_cast<size_t>(_Desired_precision);
1389+
const bool _Is_finite = (_STD isfinite) (_Val);
1390+
if (_Is_fixed && _Is_finite && 1e10 < _CSTD fabs(_Val)) { // f or F format
1391+
int _Ptwo = 0;
13911392
(void) _CSTD frexp(_Val, &_Ptwo);
13921393
_Bufsize += _CSTD abs(_Ptwo) * 30103L / 100000L;
13931394
}
13941395

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

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

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

tests/std/tests/GH_003867_output_nan/test.cpp

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,8 @@ void test_gh_3867() {
5858
// Also test GH-4210: With setprecision(0) showpoint fixed, a bogus '.' is emitted for infinity and NaN
5959

6060
template <class FloatingPoint>
61-
void test_output_nonfinite_value(const FloatingPoint x) {
61+
void test_output_nonfinite_value(
62+
const FloatingPoint x, const string& expected_noshowpos, const string& expected_showpos) {
6263
const auto s1 = [x] {
6364
ostringstream os;
6465
os << setprecision(0) << showpoint << fixed;
@@ -72,6 +73,7 @@ void test_output_nonfinite_value(const FloatingPoint x) {
7273
return os.str();
7374
}();
7475
assert(s1 == s2);
76+
assert(s1 == expected_noshowpos);
7577

7678
const auto s3 = [x] {
7779
ostringstream os;
@@ -86,17 +88,19 @@ void test_output_nonfinite_value(const FloatingPoint x) {
8688
return os.str();
8789
}();
8890
assert(s3 == s4);
91+
assert(s3 == expected_showpos);
8992
}
9093

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

96-
test_output_nonfinite_value(inf_val);
97-
test_output_nonfinite_value(-inf_val);
98-
test_output_nonfinite_value(nan_val);
99-
test_output_nonfinite_value(-nan_val);
99+
// These expected results are implementation-defined:
100+
test_output_nonfinite_value(inf_val, "inf", "+inf");
101+
test_output_nonfinite_value(-inf_val, "-inf", "-inf");
102+
test_output_nonfinite_value(nan_val, "nan", "+nan");
103+
test_output_nonfinite_value(-nan_val, "-nan(ind)", "-nan(ind)");
100104
}
101105

102106
int main() {

0 commit comments

Comments
 (0)