]> git.ipfire.org Git - thirdparty/gcc.git/blob - libstdc++-v3/testsuite/27_io/basic_ostream/inserters_arithmetic/char/hexfloat.cc
re PR libstdc++/59987 ([C++11]: Missing ios_base::hexfloat format specifier)
[thirdparty/gcc.git] / libstdc++-v3 / testsuite / 27_io / basic_ostream / inserters_arithmetic / char / hexfloat.cc
1 // { dg-options "-std=gnu++11" }
2
3 // 2014-03-27 RĂ¼diger Sonderfeld
4 // test the hexadecimal floating point inserters (facet num_put)
5
6 // Copyright (C) 2014 Free Software Foundation, Inc.
7 //
8 // This file is part of the GNU ISO C++ Library. This library is free
9 // software; you can redistribute it and/or modify it under the
10 // terms of the GNU General Public License as published by the
11 // Free Software Foundation; either version 3, or (at your option)
12 // any later version.
13
14 // This library is distributed in the hope that it will be useful,
15 // but WITHOUT ANY WARRANTY; without even the implied warranty of
16 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 // GNU General Public License for more details.
18
19 // You should have received a copy of the GNU General Public License along
20 // with this library; see the file COPYING3. If not see
21 // <http://www.gnu.org/licenses/>.
22
23 #include <iomanip>
24 #include <sstream>
25 #include <string>
26 #include <testsuite_hooks.h>
27
28 #ifndef _GLIBCXX_ASSERT
29 # define TEST_NUMPUT_VERBOSE 1
30 #endif
31
32 #ifdef TEST_NUMPUT_VERBOSE
33 # include <iostream>
34 #endif
35
36 using namespace std;
37
38 void
39 test01()
40 {
41 ostringstream os;
42 double d = 272.; // 0x1.1p+8;
43 #ifdef TEST_NUMPUT_VERBOSE
44 cout << os.precision() << endl;
45 #endif
46 os << hexfloat << setprecision(1);
47 os << d;
48 #ifdef TEST_NUMPUT_VERBOSE
49 cout << "got: " << os.str() << endl;
50 #endif
51 VERIFY( os && std::stod(os.str()) == d );
52 VERIFY( os.str().substr(0, 2) == "0x" );
53 VERIFY( os.str().find('p') != std::string::npos );
54
55 os.str("");
56 os << uppercase << d;
57 #ifdef TEST_NUMPUT_VERBOSE
58 cout << "got: " << os.str() << endl;
59 #endif
60 VERIFY( os && std::stod(os.str()) == d );
61 VERIFY( os.str().substr(0, 2) == "0X" );
62 VERIFY( os.str().find('P') != std::string::npos );
63
64 os << nouppercase;
65 os.str("");
66 os << defaultfloat << setprecision(6);
67 os << d;
68 #ifdef TEST_NUMPUT_VERBOSE
69 cout << "got: " << os.str() << endl;
70 #endif
71 VERIFY( os && os.str() == "272" );
72
73 os.str("");
74 d = 15.; //0x1.ep+3;
75 os << hexfloat << setprecision(1);
76 os << d;
77 #ifdef TEST_NUMPUT_VERBOSE
78 cout << "got: " << os.str() << endl;
79 #endif
80 VERIFY( os && std::stod(os.str()) == d );
81 os.str("");
82 os << uppercase << d;
83 #ifdef TEST_NUMPUT_VERBOSE
84 cout << "got: " << os.str() << endl;
85 #endif
86 VERIFY( os && std::stod(os.str()) == d );
87 os << nouppercase;
88 os.str("");
89 os << defaultfloat << setprecision(6);
90 os << d;
91 #ifdef TEST_NUMPUT_VERBOSE
92 cout << "got: " << os.str() << endl;
93 #endif
94 VERIFY( os && os.str() == "15" );
95 }
96
97 void
98 test02()
99 {
100 ostringstream os;
101 long double d = 272.L; // 0x1.1p+8L;
102 os << hexfloat << setprecision(1);
103 os << d;
104 #ifdef TEST_NUMPUT_VERBOSE
105 cout << "got: " << os.str() << endl;
106 #endif
107 VERIFY( os && std::stold(os.str()) == d );
108 os.str("");
109 os << uppercase << d;
110 #ifdef TEST_NUMPUT_VERBOSE
111 cout << "got: " << os.str() << endl;
112 #endif
113 VERIFY( os && std::stold(os.str()) == d );
114 os << nouppercase;
115 os.str("");
116 os << defaultfloat << setprecision(6);
117 os << d;
118 #ifdef TEST_NUMPUT_VERBOSE
119 cout << "got: " << os.str() << endl;
120 #endif
121 VERIFY( os && os.str() == "272" );
122
123 os.str("");
124 os << hexfloat << setprecision(1);
125 d = 15.; //0x1.ep+3;
126 os << d;
127 #ifdef TEST_NUMPUT_VERBOSE
128 cout << "got: " << os.str() << endl;
129 #endif
130 VERIFY( os && std::stold(os.str()) == d );
131 os.str("");
132 os << uppercase << d;
133 #ifdef TEST_NUMPUT_VERBOSE
134 cout << "got: " << os.str() << endl;
135 #endif
136 VERIFY( os && std::stold(os.str()) == d );
137 os << nouppercase;
138 os.str("");
139 os << defaultfloat << setprecision(6);
140 os << d;
141 #ifdef TEST_NUMPUT_VERBOSE
142 cout << "got: " << os.str() << endl;
143 #endif
144 VERIFY( os && os.str() == "15" );
145 }
146
147 int
148 main()
149 {
150 test01();
151 test02();
152 }