diff options
author | redi <redi@138bc75d-0d04-0410-961f-82ee72b054a4> | 2014-10-06 15:55:53 +0000 |
---|---|---|
committer | redi <redi@138bc75d-0d04-0410-961f-82ee72b054a4> | 2014-10-06 15:55:53 +0000 |
commit | acb73ebc901457078189071815ebe6aa81c91abb (patch) | |
tree | a073e4aa7ba9c60171d422fb14bfd20fb5535571 /libstdc++-v3/testsuite/27_io | |
parent | 671b0e9370ecc06d81d49aa97393aee93d36853e (diff) | |
download | gcc-acb73ebc901457078189071815ebe6aa81c91abb.tar.gz |
2014-10-06 RĂ¼diger Sonderfeld <ruediger@c-plusplus.de>
Jonathan Wakely <jwakely@redhat.com>
PR libstdc++/59987
* doc/xml/manual/status_cxx2011.xml: Remove hexfloat from notes.
* doc/html/manual/status.html: Regenerate.
* include/bits/ios_base.h (hexfloat): New function.
(defaultfloat): New function.
* src/c++98/locale_facets.cc (__num_base::_S_format_float): Support
hexadecimal floating point format.
* testsuite/27_io/basic_ostream/inserters_arithmetic/char/hexfloat.cc:
New file.
git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@215952 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'libstdc++-v3/testsuite/27_io')
-rw-r--r-- | libstdc++-v3/testsuite/27_io/basic_ostream/inserters_arithmetic/char/hexfloat.cc | 152 |
1 files changed, 152 insertions, 0 deletions
diff --git a/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_arithmetic/char/hexfloat.cc b/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_arithmetic/char/hexfloat.cc new file mode 100644 index 00000000000..485a485f100 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_arithmetic/char/hexfloat.cc @@ -0,0 +1,152 @@ +// { dg-options "-std=gnu++11" } + +// 2014-03-27 RĂ¼diger Sonderfeld +// test the hexadecimal floating point inserters (facet num_put) + +// Copyright (C) 2014 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +#include <iomanip> +#include <sstream> +#include <string> +#include <testsuite_hooks.h> + +#ifndef _GLIBCXX_ASSERT +# define TEST_NUMPUT_VERBOSE 1 +#endif + +#ifdef TEST_NUMPUT_VERBOSE +# include <iostream> +#endif + +using namespace std; + +void +test01() +{ + ostringstream os; + double d = 272.; // 0x1.1p+8; +#ifdef TEST_NUMPUT_VERBOSE + cout << os.precision() << endl; +#endif + os << hexfloat << setprecision(1); + os << d; +#ifdef TEST_NUMPUT_VERBOSE + cout << "got: " << os.str() << endl; +#endif + VERIFY( os && std::stod(os.str()) == d ); + VERIFY( os.str().substr(0, 2) == "0x" ); + VERIFY( os.str().find('p') != std::string::npos ); + + os.str(""); + os << uppercase << d; +#ifdef TEST_NUMPUT_VERBOSE + cout << "got: " << os.str() << endl; +#endif + VERIFY( os && std::stod(os.str()) == d ); + VERIFY( os.str().substr(0, 2) == "0X" ); + VERIFY( os.str().find('P') != std::string::npos ); + + os << nouppercase; + os.str(""); + os << defaultfloat << setprecision(6); + os << d; +#ifdef TEST_NUMPUT_VERBOSE + cout << "got: " << os.str() << endl; +#endif + VERIFY( os && os.str() == "272" ); + + os.str(""); + d = 15.; //0x1.ep+3; + os << hexfloat << setprecision(1); + os << d; +#ifdef TEST_NUMPUT_VERBOSE + cout << "got: " << os.str() << endl; +#endif + VERIFY( os && std::stod(os.str()) == d ); + os.str(""); + os << uppercase << d; +#ifdef TEST_NUMPUT_VERBOSE + cout << "got: " << os.str() << endl; +#endif + VERIFY( os && std::stod(os.str()) == d ); + os << nouppercase; + os.str(""); + os << defaultfloat << setprecision(6); + os << d; +#ifdef TEST_NUMPUT_VERBOSE + cout << "got: " << os.str() << endl; +#endif + VERIFY( os && os.str() == "15" ); +} + +void +test02() +{ + ostringstream os; + long double d = 272.L; // 0x1.1p+8L; + os << hexfloat << setprecision(1); + os << d; +#ifdef TEST_NUMPUT_VERBOSE + cout << "got: " << os.str() << endl; +#endif + VERIFY( os && std::stold(os.str()) == d ); + os.str(""); + os << uppercase << d; +#ifdef TEST_NUMPUT_VERBOSE + cout << "got: " << os.str() << endl; +#endif + VERIFY( os && std::stold(os.str()) == d ); + os << nouppercase; + os.str(""); + os << defaultfloat << setprecision(6); + os << d; +#ifdef TEST_NUMPUT_VERBOSE + cout << "got: " << os.str() << endl; +#endif + VERIFY( os && os.str() == "272" ); + + os.str(""); + os << hexfloat << setprecision(1); + d = 15.; //0x1.ep+3; + os << d; +#ifdef TEST_NUMPUT_VERBOSE + cout << "got: " << os.str() << endl; +#endif + VERIFY( os && std::stold(os.str()) == d ); + os.str(""); + os << uppercase << d; +#ifdef TEST_NUMPUT_VERBOSE + cout << "got: " << os.str() << endl; +#endif + VERIFY( os && std::stold(os.str()) == d ); + os << nouppercase; + os.str(""); + os << defaultfloat << setprecision(6); + os << d; +#ifdef TEST_NUMPUT_VERBOSE + cout << "got: " << os.str() << endl; +#endif + VERIFY( os && os.str() == "15" ); +} + +int +main() +{ + test01(); + test02(); +} |