| 1 | // Copyright (C) 2022-2025 Free Software Foundation, Inc. |
| 2 | // |
| 3 | // This file is part of the GNU ISO C++ Library. This library is free |
| 4 | // software; you can redistribute it and/or modify it under the |
| 5 | // terms of the GNU General Public License as published by the |
| 6 | // Free Software Foundation; either version 3, or (at your option) |
| 7 | // any later version. |
| 8 | |
| 9 | // This library is distributed in the hope that it will be useful, |
| 10 | // but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 | // GNU General Public License for more details. |
| 13 | |
| 14 | // You should have received a copy of the GNU General Public License along |
| 15 | // with this library; see the file COPYING3. If not see |
| 16 | // <http://www.gnu.org/licenses/>. |
| 17 | |
| 18 | // { dg-do run { target c++17 } } |
| 19 | // { dg-add-options ieee } |
| 20 | |
| 21 | #include <charconv> |
| 22 | #include <string> |
| 23 | #include <cfenv> |
| 24 | #include <testsuite_hooks.h> |
| 25 | |
| 26 | int |
| 27 | main() |
| 28 | { |
| 29 | // FP from_char not available otherwise. |
| 30 | #if __cpp_lib_to_chars >= 201611L \ |
| 31 | && _GLIBCXX_USE_C99_FENV_TR1 \ |
| 32 | && defined(FE_DOWNWARD) \ |
| 33 | && defined(_GLIBCXX_FLOAT_IS_IEEE_BINARY32) |
| 34 | // PR libstdc++/107468 |
| 35 | float f; |
| 36 | char buf[] = "3.355447e+07"; |
| 37 | std::fesetround(FE_DOWNWARD); |
| 38 | auto [ptr, ec] = std::from_chars(buf, buf + sizeof(buf) - 1, f, std::chars_format::scientific); |
| 39 | VERIFY( ec == std::errc() && ptr == buf + sizeof(buf) - 1 ); |
| 40 | VERIFY( f == 33554472.0f ); |
| 41 | #endif |
| 42 | } |