| 1 | // Copyright (C) 2019-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 compile { target c++20 } } |
| 19 | // { dg-add-options no_pch } |
| 20 | |
| 21 | #include <numbers> |
| 22 | |
| 23 | #ifndef __cpp_lib_math_constants |
| 24 | # error "Feature-test macro for math constants missing in <numbers>" |
| 25 | #elif __cpp_lib_math_constants != 201907L |
| 26 | # error "Feature-test macro for math constants has wrong value in <numbers>" |
| 27 | #endif |
| 28 | |
| 29 | void |
| 30 | test01() |
| 31 | { |
| 32 | const double* d1 = &std::numbers::e_v<double>; |
| 33 | const double* d2 = &std::numbers::log2e_v<double>; |
| 34 | const double* d3 = &std::numbers::log10e_v<double>; |
| 35 | const double* d4 = &std::numbers::pi_v<double>; |
| 36 | const double* d5 = &std::numbers::inv_pi_v<double>; |
| 37 | const double* d6 = &std::numbers::inv_sqrtpi_v<double>; |
| 38 | const double* d7 = &std::numbers::ln2_v<double>; |
| 39 | const double* d8 = &std::numbers::ln10_v<double>; |
| 40 | const double* d9 = &std::numbers::sqrt2_v<double>; |
| 41 | const double* d10 = &std::numbers::sqrt3_v<double>; |
| 42 | const double* d11 = &std::numbers::inv_sqrt3_v<double>; |
| 43 | const double* d12 = &std::numbers::egamma_v<double>; |
| 44 | const double* d13 = &std::numbers::phi_v<double>; |
| 45 | } |
| 46 | |
| 47 | void |
| 48 | test02() |
| 49 | { |
| 50 | const float* d1 = &std::numbers::e_v<float>; |
| 51 | const float* d2 = &std::numbers::log2e_v<float>; |
| 52 | const float* d3 = &std::numbers::log10e_v<float>; |
| 53 | const float* d4 = &std::numbers::pi_v<float>; |
| 54 | const float* d5 = &std::numbers::inv_pi_v<float>; |
| 55 | const float* d6 = &std::numbers::inv_sqrtpi_v<float>; |
| 56 | const float* d7 = &std::numbers::ln2_v<float>; |
| 57 | const float* d8 = &std::numbers::ln10_v<float>; |
| 58 | const float* d9 = &std::numbers::sqrt2_v<float>; |
| 59 | const float* d10 = &std::numbers::sqrt3_v<float>; |
| 60 | const float* d11 = &std::numbers::inv_sqrt3_v<float>; |
| 61 | const float* d12 = &std::numbers::egamma_v<float>; |
| 62 | const float* d13 = &std::numbers::phi_v<float>; |
| 63 | } |
| 64 | |
| 65 | void |
| 66 | test03() |
| 67 | { |
| 68 | const long double* d1 = &std::numbers::e_v<long double>; |
| 69 | const long double* d2 = &std::numbers::log2e_v<long double>; |
| 70 | const long double* d3 = &std::numbers::log10e_v<long double>; |
| 71 | const long double* d4 = &std::numbers::pi_v<long double>; |
| 72 | const long double* d5 = &std::numbers::inv_pi_v<long double>; |
| 73 | const long double* d6 = &std::numbers::inv_sqrtpi_v<long double>; |
| 74 | const long double* d7 = &std::numbers::ln2_v<long double>; |
| 75 | const long double* d8 = &std::numbers::ln10_v<long double>; |
| 76 | const long double* d9 = &std::numbers::sqrt2_v<long double>; |
| 77 | const long double* d10 = &std::numbers::sqrt3_v<long double>; |
| 78 | const long double* d11 = &std::numbers::inv_sqrt3_v<long double>; |
| 79 | const long double* d12 = &std::numbers::egamma_v<long double>; |
| 80 | const long double* d13 = &std::numbers::phi_v<long double>; |
| 81 | } |
| 82 | |
| 83 | void |
| 84 | test04() |
| 85 | { |
| 86 | static_assert(std::numbers::e == std::numbers::e_v<double>); |
| 87 | static_assert(std::numbers::log2e == std::numbers::log2e_v<double>); |
| 88 | static_assert(std::numbers::log10e == std::numbers::log10e_v<double>); |
| 89 | static_assert(std::numbers::pi == std::numbers::pi_v<double>); |
| 90 | static_assert(std::numbers::inv_pi == std::numbers::inv_pi_v<double>); |
| 91 | static_assert(std::numbers::inv_sqrtpi == std::numbers::inv_sqrtpi_v<double>); |
| 92 | static_assert(std::numbers::ln2 == std::numbers::ln2_v<double>); |
| 93 | static_assert(std::numbers::ln10 == std::numbers::ln10_v<double>); |
| 94 | static_assert(std::numbers::sqrt2 == std::numbers::sqrt2_v<double>); |
| 95 | static_assert(std::numbers::sqrt3 == std::numbers::sqrt3_v<double>); |
| 96 | static_assert(std::numbers::inv_sqrt3 == std::numbers::inv_sqrt3_v<double>); |
| 97 | static_assert(std::numbers::egamma == std::numbers::egamma_v<double>); |
| 98 | static_assert(std::numbers::phi == std::numbers::phi_v<double>); |
| 99 | } |