| 1 | // Copyright (C) 2024-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++23 } } |
| 19 | // { dg-require-cmath "" } |
| 20 | |
| 21 | #include <stdfloat> |
| 22 | #include <cmath> |
| 23 | #include <limits> |
| 24 | #include <testsuite_hooks.h> |
| 25 | |
| 26 | template <typename T> |
| 27 | void |
| 28 | test () |
| 29 | { |
| 30 | using lim = std::numeric_limits<T>; |
| 31 | int t0 = std::ilogb(T(4.0)); |
| 32 | VERIFY( t0 == 2 ); |
| 33 | int t1 = std::ilogb(lim::infinity()); |
| 34 | VERIFY( t1 == std::numeric_limits<int>::max() ); |
| 35 | int t2 = std::ilogb(-lim::infinity()); |
| 36 | VERIFY( t2 == std::numeric_limits<int>::max() ); |
| 37 | } |
| 38 | |
| 39 | int |
| 40 | main () |
| 41 | { |
| 42 | #if defined(__STDCPP_FLOAT16_T__) && defined(_GLIBCXX_FLOAT_IS_IEEE_BINARY32) |
| 43 | test <std::float16_t>(); |
| 44 | #endif |
| 45 | #if defined(__STDCPP_FLOAT32_T__) && defined(_GLIBCXX_FLOAT_IS_IEEE_BINARY32) |
| 46 | test <std::float32_t>(); |
| 47 | #endif |
| 48 | #if defined(__STDCPP_FLOAT64_T__) && defined(_GLIBCXX_DOUBLE_IS_IEEE_BINARY64) |
| 49 | test <std::float64_t>(); |
| 50 | #endif |
| 51 | #if defined(__STDCPP_FLOAT128_T__) \ |
| 52 | && (defined(_GLIBCXX_LDOUBLE_IS_IEEE_BINARY128) \ |
| 53 | || defined(_GLIBCXX_HAVE_FLOAT128_MATH)) |
| 54 | test <std::float128_t>(); |
| 55 | #endif |
| 56 | #if defined(__STDCPP_BFLOAT16_T__) && defined(_GLIBCXX_FLOAT_IS_IEEE_BINARY32) |
| 57 | test <std::bfloat16_t>(); |
| 58 | #endif |
| 59 | } |