]>
git.ipfire.org Git - thirdparty/gcc.git/blob - libstdc++-v3/testsuite/27_io/basic_ostream/inserters_arithmetic/char/hexfloat.cc
1 // { dg-options "-std=gnu++11" }
3 // 2014-03-27 RĂ¼diger Sonderfeld
4 // test the hexadecimal floating point inserters (facet num_put)
6 // Copyright (C) 2014 Free Software Foundation, Inc.
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)
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.
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/>.
26 #include <testsuite_hooks.h>
28 #ifndef _GLIBCXX_ASSERT
29 # define TEST_NUMPUT_VERBOSE 1
32 #ifdef TEST_NUMPUT_VERBOSE
42 double d
= 272.; // 0x1.1p+8;
43 #ifdef TEST_NUMPUT_VERBOSE
44 cout
<< os
.precision() << endl
;
46 os
<< hexfloat
<< setprecision(1);
48 #ifdef TEST_NUMPUT_VERBOSE
49 cout
<< "got: " << os
.str() << endl
;
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
);
57 #ifdef TEST_NUMPUT_VERBOSE
58 cout
<< "got: " << os
.str() << endl
;
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
);
66 os
<< defaultfloat
<< setprecision(6);
68 #ifdef TEST_NUMPUT_VERBOSE
69 cout
<< "got: " << os
.str() << endl
;
71 VERIFY( os
&& os
.str() == "272" );
75 os
<< hexfloat
<< setprecision(1);
77 #ifdef TEST_NUMPUT_VERBOSE
78 cout
<< "got: " << os
.str() << endl
;
80 VERIFY( os
&& std::stod(os
.str()) == d
);
83 #ifdef TEST_NUMPUT_VERBOSE
84 cout
<< "got: " << os
.str() << endl
;
86 VERIFY( os
&& std::stod(os
.str()) == d
);
89 os
<< defaultfloat
<< setprecision(6);
91 #ifdef TEST_NUMPUT_VERBOSE
92 cout
<< "got: " << os
.str() << endl
;
94 VERIFY( os
&& os
.str() == "15" );
101 long double d
= 272.L
; // 0x1.1p+8L;
102 os
<< hexfloat
<< setprecision(1);
104 #ifdef TEST_NUMPUT_VERBOSE
105 cout
<< "got: " << os
.str() << endl
;
107 VERIFY( os
&& std::stold(os
.str()) == d
);
109 os
<< uppercase
<< d
;
110 #ifdef TEST_NUMPUT_VERBOSE
111 cout
<< "got: " << os
.str() << endl
;
113 VERIFY( os
&& std::stold(os
.str()) == d
);
116 os
<< defaultfloat
<< setprecision(6);
118 #ifdef TEST_NUMPUT_VERBOSE
119 cout
<< "got: " << os
.str() << endl
;
121 VERIFY( os
&& os
.str() == "272" );
124 os
<< hexfloat
<< setprecision(1);
127 #ifdef TEST_NUMPUT_VERBOSE
128 cout
<< "got: " << os
.str() << endl
;
130 VERIFY( os
&& std::stold(os
.str()) == d
);
132 os
<< uppercase
<< d
;
133 #ifdef TEST_NUMPUT_VERBOSE
134 cout
<< "got: " << os
.str() << endl
;
136 VERIFY( os
&& std::stold(os
.str()) == d
);
139 os
<< defaultfloat
<< setprecision(6);
141 #ifdef TEST_NUMPUT_VERBOSE
142 cout
<< "got: " << os
.str() << endl
;
144 VERIFY( os
&& os
.str() == "15" );