]> git.ipfire.org Git - thirdparty/gcc.git/blob - libstdc++-v3/testsuite/experimental/simd/tests/math_1arg.cc
libstdc++: Add simd testsuite
[thirdparty/gcc.git] / libstdc++-v3 / testsuite / experimental / simd / tests / math_1arg.cc
1 // test only floattypes
2 // Copyright (C) 2020 Free Software Foundation, Inc.
3 //
4 // This file is part of the GNU ISO C++ Library. This library is free
5 // software; you can redistribute it and/or modify it under the
6 // terms of the GNU General Public License as published by the
7 // Free Software Foundation; either version 3, or (at your option)
8 // any later version.
9 //
10 // This library is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU General Public License for more details.
14 //
15 // You should have received a copy of the GNU General Public License along
16 // with this library; see the file COPYING3. If not see
17 // <http://www.gnu.org/licenses/>.
18
19 #include "bits/verify.h"
20 #include "bits/test_values.h"
21
22 template <typename V>
23 void
24 test()
25 {
26 vir::test::setFuzzyness<float>(0);
27 vir::test::setFuzzyness<double>(0);
28
29 using T = typename V::value_type;
30 constexpr T inf = std::__infinity_v<T>;
31 constexpr T nan = std::__quiet_NaN_v<T>;
32 constexpr T denorm_min = std::__denorm_min_v<T>;
33 constexpr T norm_min = std::__norm_min_v<T>;
34 constexpr T max = std::__finite_max_v<T>;
35 #if defined __LONG_DOUBLE_IBM128__
36 // On POWER with IBM128 long double, 1+eps and 2-eps is not a constant
37 // expression. Until this is fixed, just use const instead of constexpr.
38 // (error: '(1.0e+0l + 4.94065645841246544176568792868221e-324l)' is not a
39 // constant expression)
40 const T after_one = 1 + std::__epsilon_v<T>;
41 const T before_one = (2 - std::__epsilon_v<T>) / 2;
42 #else
43 constexpr T after_one = 1 + std::__epsilon_v<T>;
44 constexpr T before_one = (2 - std::__epsilon_v<T>) / 2;
45 #endif
46 const std::initializer_list<T>
47 input_values = {+0.,
48 0.5,
49 -0.5,
50 before_one,
51 -before_one,
52 after_one,
53 -after_one,
54 1.5,
55 -1.5,
56 2 * before_one,
57 -2 * before_one,
58 2 * after_one,
59 -2 * after_one,
60 2.5,
61 -2.5,
62 0x1.fffffffffffffp52,
63 -0x1.fffffffffffffp52,
64 0x1.ffffffffffffep52,
65 -0x1.ffffffffffffep52,
66 0x1.ffffffffffffdp52,
67 -0x1.ffffffffffffdp52,
68 0x1.fffffep21,
69 -0x1.fffffep21,
70 0x1.fffffcp21,
71 -0x1.fffffcp21,
72 0x1.fffffep22,
73 -0x1.fffffep22,
74 0x1.fffffcp22,
75 -0x1.fffffcp22,
76 0x1.fffffep23,
77 -0x1.fffffep23,
78 0x1.fffffcp23,
79 -0x1.fffffcp23,
80 0x1.8p23,
81 -0x1.8p23,
82 inf,
83 -inf,
84 -0.,
85 nan,
86 denorm_min,
87 norm_min / 3,
88 norm_min,
89 max};
90 test_values<V>(input_values, {10000}, MAKE_TESTER(erf), MAKE_TESTER(erfc),
91 MAKE_TESTER(tgamma), MAKE_TESTER(lgamma), MAKE_TESTER(ceil),
92 MAKE_TESTER(floor), MAKE_TESTER(trunc), MAKE_TESTER(round),
93 MAKE_TESTER(lround), MAKE_TESTER(llround),
94 MAKE_TESTER(nearbyint), MAKE_TESTER(rint), MAKE_TESTER(lrint),
95 MAKE_TESTER(llrint), MAKE_TESTER(ilogb));
96
97 // sqrt(x) on x87 is precise in 80 bits, but the subsequent rounding can be
98 // wrong (up to 1 ULP)
99 #if __FLT_EVAL_METHOD__ == 1
100 vir::test::setFuzzyness<float>(1);
101 vir::test::setFuzzyness<double>(0);
102 #elif __FLT_EVAL_METHOD__ == 2
103 vir::test::setFuzzyness<float>(1);
104 vir::test::setFuzzyness<double>(1);
105 #endif
106 test_values<V>(input_values, {10000}, MAKE_TESTER(sqrt));
107 }