]>
git.ipfire.org Git - thirdparty/gcc.git/blob - libstdc++-v3/testsuite/27_io/basic_ostream/inserters_arithmetic/char/hexfloat.cc
1 // { dg-do run { target c++11 } }
2 // { dg-require-string-conversions "" }
3 // { dg-xfail-run-if "broken long double IO" { newlib_broken_long_double_io } }
5 // 2014-03-27 RĂ¼diger Sonderfeld
6 // test the hexadecimal floating point inserters (facet num_put)
8 // Copyright (C) 2014-2022 Free Software Foundation, Inc.
10 // This file is part of the GNU ISO C++ Library. This library is free
11 // software; you can redistribute it and/or modify it under the
12 // terms of the GNU General Public License as published by the
13 // Free Software Foundation; either version 3, or (at your option)
16 // This library is distributed in the hope that it will be useful,
17 // but WITHOUT ANY WARRANTY; without even the implied warranty of
18 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 // GNU General Public License for more details.
21 // You should have received a copy of the GNU General Public License along
22 // with this library; see the file COPYING3. If not see
23 // <http://www.gnu.org/licenses/>.
28 #include <testsuite_hooks.h>
30 #ifdef TEST_NUMPUT_VERBOSE
40 double d
= 272.; // 0x1.1p+8;
41 #ifdef TEST_NUMPUT_VERBOSE
42 cout
<< os
.precision() << endl
;
44 os
<< hexfloat
<< setprecision(1);
46 #ifdef TEST_NUMPUT_VERBOSE
47 cout
<< "got: " << os
.str() << endl
;
49 VERIFY( os
&& std::stod(os
.str()) == d
);
50 VERIFY( os
.str().substr(0, 2) == "0x" );
51 VERIFY( os
.str().find('p') != std::string::npos
);
55 #ifdef TEST_NUMPUT_VERBOSE
56 cout
<< "got: " << os
.str() << endl
;
58 VERIFY( os
&& std::stod(os
.str()) == d
);
59 VERIFY( os
.str().substr(0, 2) == "0X" );
60 VERIFY( os
.str().find('P') != std::string::npos
);
64 os
<< defaultfloat
<< setprecision(6);
66 #ifdef TEST_NUMPUT_VERBOSE
67 cout
<< "got: " << os
.str() << endl
;
69 VERIFY( os
&& os
.str() == "272" );
73 os
<< hexfloat
<< setprecision(1);
75 #ifdef TEST_NUMPUT_VERBOSE
76 cout
<< "got: " << os
.str() << endl
;
78 VERIFY( os
&& std::stod(os
.str()) == d
);
81 #ifdef TEST_NUMPUT_VERBOSE
82 cout
<< "got: " << os
.str() << endl
;
84 VERIFY( os
&& std::stod(os
.str()) == d
);
87 os
<< defaultfloat
<< setprecision(6);
89 #ifdef TEST_NUMPUT_VERBOSE
90 cout
<< "got: " << os
.str() << endl
;
92 VERIFY( os
&& os
.str() == "15" );
99 long double d
= 272.L
; // 0x1.1p+8L;
100 os
<< hexfloat
<< setprecision(1);
102 #ifdef TEST_NUMPUT_VERBOSE
103 cout
<< "got: " << os
.str() << endl
;
105 VERIFY( os
&& std::stold(os
.str()) == d
);
107 os
<< uppercase
<< d
;
108 #ifdef TEST_NUMPUT_VERBOSE
109 cout
<< "got: " << os
.str() << endl
;
111 VERIFY( os
&& std::stold(os
.str()) == d
);
114 os
<< defaultfloat
<< setprecision(6);
116 #ifdef TEST_NUMPUT_VERBOSE
117 cout
<< "got: " << os
.str() << endl
;
119 VERIFY( os
&& os
.str() == "272" );
122 os
<< hexfloat
<< setprecision(1);
125 #ifdef TEST_NUMPUT_VERBOSE
126 cout
<< "got: " << os
.str() << endl
;
128 VERIFY( os
&& std::stold(os
.str()) == d
);
130 os
<< uppercase
<< d
;
131 #ifdef TEST_NUMPUT_VERBOSE
132 cout
<< "got: " << os
.str() << endl
;
134 VERIFY( os
&& std::stold(os
.str()) == d
);
137 os
<< defaultfloat
<< setprecision(6);
139 #ifdef TEST_NUMPUT_VERBOSE
140 cout
<< "got: " << os
.str() << endl
;
142 VERIFY( os
&& os
.str() == "15" );