| 1 | // Copyright (C) 2020-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 | // only: float|double|ldouble * * * |
| 19 | // expensive: * [1-9] * * |
| 20 | #include "bits/main.h" |
| 21 | |
| 22 | template <typename V> |
| 23 | void |
| 24 | test() |
| 25 | { |
| 26 | using T = typename V::value_type; |
| 27 | |
| 28 | vir::test::setFuzzyness<float>(1); |
| 29 | vir::test::setFuzzyness<double>(1); |
| 30 | vir::test::setFuzzyness<long double>(1); |
| 31 | test_values_2arg<V>( |
| 32 | { |
| 33 | #ifdef __STDC_IEC_559__ |
| 34 | std::__quiet_NaN_v<T>, std::__infinity_v<T>, -std::__infinity_v<T>, -0., |
| 35 | std::__denorm_min_v<T>, std::__norm_min_v<T> / 3, |
| 36 | #endif |
| 37 | +0., std::__norm_min_v<T>, 1., 2., std::__finite_max_v<T> / 5, |
| 38 | std::__finite_max_v<T> / 3, std::__finite_max_v<T> / 2, |
| 39 | #ifdef __FAST_MATH__ |
| 40 | // fast-math hypot is imprecise for the max exponent |
| 41 | }, |
| 42 | {100000, std::__finite_max_v<T> / 2}, |
| 43 | #else |
| 44 | std::__finite_max_v<T>}, |
| 45 | {100000}, |
| 46 | #endif |
| 47 | MAKE_TESTER(hypot)); |
| 48 | #if !__FINITE_MATH_ONLY__ |
| 49 | COMPARE(hypot(V(std::__finite_max_v<T>), V(std::__finite_max_v<T>)), |
| 50 | V(std::__infinity_v<T>)); |
| 51 | #endif |
| 52 | COMPARE(hypot(V(std::__norm_min_v<T>), V(std::__norm_min_v<T>)), |
| 53 | V(std::__norm_min_v<T> * std::sqrt(T(2)))); |
| 54 | VERIFY((sfinae_is_callable<V, V>( |
| 55 | [](auto a, auto b) -> decltype(hypot(a, b)) { return {}; }))); |
| 56 | VERIFY((sfinae_is_callable<typename V::value_type, V>( |
| 57 | [](auto a, auto b) -> decltype(hypot(a, b)) { return {}; }))); |
| 58 | VERIFY((sfinae_is_callable<V, typename V::value_type>( |
| 59 | [](auto a, auto b) -> decltype(hypot(a, b)) { return {}; }))); |
| 60 | |
| 61 | vir::test::setFuzzyness<float>(0); |
| 62 | vir::test::setFuzzyness<double>(0); |
| 63 | vir::test::setFuzzyness<long double>(0); |
| 64 | test_values_2arg<V>( |
| 65 | { |
| 66 | #ifdef __STDC_IEC_559__ |
| 67 | std::__quiet_NaN_v<T>, std::__infinity_v<T>, -std::__infinity_v<T>, |
| 68 | std::__denorm_min_v<T>, std::__norm_min_v<T> / 3, -0., |
| 69 | #endif |
| 70 | +0., std::__norm_min_v<T>, std::__finite_max_v<T>}, |
| 71 | {10000}, MAKE_TESTER(pow), MAKE_TESTER(fmod), MAKE_TESTER(remainder), |
| 72 | MAKE_TESTER_NOFPEXCEPT(copysign), |
| 73 | MAKE_TESTER(nextafter), // MAKE_TESTER(nexttoward), |
| 74 | MAKE_TESTER(fdim), MAKE_TESTER(fmax), MAKE_TESTER(fmin), |
| 75 | MAKE_TESTER_NOFPEXCEPT(isgreater), MAKE_TESTER_NOFPEXCEPT(isgreaterequal), |
| 76 | MAKE_TESTER_NOFPEXCEPT(isless), MAKE_TESTER_NOFPEXCEPT(islessequal), |
| 77 | MAKE_TESTER_NOFPEXCEPT(islessgreater), MAKE_TESTER_NOFPEXCEPT(isunordered)); |
| 78 | } |