| 1 | // { dg-do run { target c++11 } } |
| 2 | // { dg-options "-D__STDCPP_WANT_MATH_SPEC_FUNCS__" } |
| 3 | // { dg-skip-if "no extensions in strict dialects" { *-*-* } { "-std=c++*" } } |
| 4 | // |
| 5 | // Copyright (C) 2016-2025 Free Software Foundation, Inc. |
| 6 | // |
| 7 | // This file is part of the GNU ISO C++ Library. This library is free |
| 8 | // software; you can redistribute it and/or modify it under the |
| 9 | // terms of the GNU General Public License as published by the |
| 10 | // Free Software Foundation; either version 3, or (at your option) |
| 11 | // any later version. |
| 12 | // |
| 13 | // This library is distributed in the hope that it will be useful, |
| 14 | // but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 15 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 16 | // GNU General Public License for more details. |
| 17 | // |
| 18 | // You should have received a copy of the GNU General Public License along |
| 19 | // with this library; see the file COPYING3. If not see |
| 20 | // <http://www.gnu.org/licenses/>. |
| 21 | |
| 22 | // airy_ai |
| 23 | |
| 24 | // Compare against values generated by the GNU Scientific Library. |
| 25 | // The GSL can be found on the web: http://www.gnu.org/software/gsl/ |
| 26 | #include <limits> |
| 27 | #include <cmath> |
| 28 | #if defined(__TEST_DEBUG) |
| 29 | # include <iostream> |
| 30 | # define VERIFY(A) \ |
| 31 | if (!(A)) \ |
| 32 | { \ |
| 33 | std::cout << "line " << __LINE__ \ |
| 34 | << " max_abs_frac = " << max_abs_frac \ |
| 35 | << std::endl; \ |
| 36 | } |
| 37 | #else |
| 38 | # include <testsuite_hooks.h> |
| 39 | #endif |
| 40 | #include <specfun_testcase.h> |
| 41 | |
| 42 | // Test data. |
| 43 | // max(|f - f_GSL|): 2.0261570199409107e-15 at index 0 |
| 44 | // max(|f - f_GSL| / |f_GSL|): 5.7527019513802774e-14 |
| 45 | // mean(f - f_GSL): 5.7893945880945940e-17 |
| 46 | // variance(f - f_GSL): 8.5887539970087062e-35 |
| 47 | // stddev(f - f_GSL): 9.2675530734971811e-18 |
| 48 | const testcase_airy_ai<double> |
| 49 | data001[41] = |
| 50 | { |
| 51 | { 0.040241238486444071, -10.000000000000000, 0.0 }, |
| 52 | { 0.31910324771912801, -9.5000000000000000, 0.0 }, |
| 53 | { -0.022133721547341240, -9.0000000000000000, 0.0 }, |
| 54 | { -0.33029023763020882, -8.5000000000000000, 0.0 }, |
| 55 | { -0.052705050356385910, -8.0000000000000000, 0.0 }, |
| 56 | { 0.32177571638064789, -7.5000000000000000, 0.0 }, |
| 57 | { 0.18428083525050609, -7.0000000000000000, 0.0 }, |
| 58 | { -0.23802030199711663, -6.5000000000000000, 0.0 }, |
| 59 | { -0.32914517362982321, -6.0000000000000000, 0.0 }, |
| 60 | { 0.017781541276574383, -5.5000000000000000, 0.0 }, |
| 61 | { 0.35076100902411411, -5.0000000000000000, 0.0 }, |
| 62 | { 0.29215278105595921, -4.5000000000000000, 0.0 }, |
| 63 | { -0.070265532949289680, -4.0000000000000000, 0.0 }, |
| 64 | { -0.37553382314043182, -3.5000000000000000, 0.0 }, |
| 65 | { -0.37881429367765823, -3.0000000000000000, 0.0 }, |
| 66 | { -0.11232506769296607, -2.5000000000000000, 0.0 }, |
| 67 | { 0.22740742820168561, -2.0000000000000000, 0.0 }, |
| 68 | { 0.46425657774886947, -1.5000000000000000, 0.0 }, |
| 69 | { 0.53556088329235207, -1.0000000000000000, 0.0 }, |
| 70 | { 0.47572809161053958, -0.50000000000000000, 0.0 }, |
| 71 | { 0.35502805388781722, 0.0000000000000000, 0.0 }, |
| 72 | { 0.23169360648083348, 0.50000000000000000, 0.0 }, |
| 73 | { 0.13529241631288141, 1.0000000000000000, 0.0 }, |
| 74 | { 0.071749497008105428, 1.5000000000000000, 0.0 }, |
| 75 | { 0.034924130423274372, 2.0000000000000000, 0.0 }, |
| 76 | { 0.015725923380470481, 2.5000000000000000, 0.0 }, |
| 77 | { 0.0065911393574607175, 3.0000000000000000, 0.0 }, |
| 78 | { 0.0025840987869896349, 3.5000000000000000, 0.0 }, |
| 79 | { 0.00095156385120480195, 4.0000000000000000, 0.0 }, |
| 80 | { 0.00033025032351430934, 4.5000000000000000, 0.0 }, |
| 81 | { 0.00010834442813607434, 5.0000000000000000, 0.0 }, |
| 82 | { 3.3685311908599812e-05, 5.5000000000000000, 0.0 }, |
| 83 | { 9.9476943602528973e-06, 6.0000000000000000, 0.0 }, |
| 84 | { 2.7958823432049148e-06, 6.5000000000000000, 0.0 }, |
| 85 | { 7.4921288639971570e-07, 7.0000000000000000, 0.0 }, |
| 86 | { 1.9172560675134295e-07, 7.5000000000000000, 0.0 }, |
| 87 | { 4.6922076160992236e-08, 8.0000000000000000, 0.0 }, |
| 88 | { 1.0997009755195515e-08, 8.5000000000000000, 0.0 }, |
| 89 | { 2.4711684308724904e-09, 9.0000000000000000, 0.0 }, |
| 90 | { 5.3302637046174900e-10, 9.5000000000000000, 0.0 }, |
| 91 | { 1.1047532552898652e-10, 10.000000000000000, 0.0 }, |
| 92 | }; |
| 93 | const double toler001 = 5.0000000000000029e-12; |
| 94 | |
| 95 | template<typename Ret, unsigned int Num> |
| 96 | void |
| 97 | test(const testcase_airy_ai<Ret> (&data)[Num], Ret toler) |
| 98 | { |
| 99 | bool test __attribute__((unused)) = true; |
| 100 | const Ret eps = std::numeric_limits<Ret>::epsilon(); |
| 101 | Ret max_abs_diff = -Ret(1); |
| 102 | Ret max_abs_frac = -Ret(1); |
| 103 | unsigned int num_datum = Num; |
| 104 | for (unsigned int i = 0; i < num_datum; ++i) |
| 105 | { |
| 106 | const Ret f = __gnu_cxx::airy_ai(data[i].x); |
| 107 | const Ret f0 = data[i].f0; |
| 108 | const Ret diff = f - f0; |
| 109 | if (std::abs(diff) > max_abs_diff) |
| 110 | max_abs_diff = std::abs(diff); |
| 111 | if (std::abs(f0) > Ret(10) * eps |
| 112 | && std::abs(f) > Ret(10) * eps) |
| 113 | { |
| 114 | const Ret frac = diff / f0; |
| 115 | if (std::abs(frac) > max_abs_frac) |
| 116 | max_abs_frac = std::abs(frac); |
| 117 | } |
| 118 | } |
| 119 | VERIFY(max_abs_frac < toler); |
| 120 | } |
| 121 | |
| 122 | int |
| 123 | main() |
| 124 | { |
| 125 | test(data001, toler001); |
| 126 | return 0; |
| 127 | } |