]> git.ipfire.org Git - thirdparty/gcc.git/blob - libstdc++-v3/testsuite/experimental/simd/tests/remqo.cc
Update copyright years.
[thirdparty/gcc.git] / libstdc++-v3 / testsuite / experimental / simd / tests / remqo.cc
1 // Copyright (C) 2020-2023 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/verify.h"
21 #include "bits/metahelpers.h"
22 #include "bits/test_values.h"
23
24 template <typename V>
25 void
26 test()
27 {
28 vir::test::setFuzzyness<float>(0);
29 vir::test::setFuzzyness<double>(0);
30
31 using T = typename V::value_type;
32 test_values_2arg<V>(
33 {
34 #ifdef __STDC_IEC_559__
35 std::__quiet_NaN_v<T>, std::__infinity_v<T>, -std::__infinity_v<T>,
36 std::__denorm_min_v<T>, std::__norm_min_v<T> / 3, -0.,
37 #endif
38 +0., std::__norm_min_v<T>, std::__finite_max_v<T>},
39 {10000}, [](V a, V b) {
40
41 #ifndef __STDC_IEC_559__
42 // without __STDC_IEC_559__, remquo(a, 0) is unspecified
43 where(b == 0, b) = 1;
44 #endif
45 using IV = std::experimental::fixed_size_simd<int, V::size()>;
46 IV quo = {};
47 const V totest = remquo(a, b, &quo);
48 auto&& expected
49 = [&](const auto& v, const auto& w) -> std::pair<const V, const IV> {
50 std::pair<V, IV> tmp = {};
51 using std::remquo;
52 for (std::size_t i = 0; i < V::size(); ++i)
53 {
54 int tmp2;
55 tmp.first[i] = remquo(v[i], w[i], &tmp2);
56 tmp.second[i] = tmp2;
57 }
58 return tmp;
59 };
60 const auto expect1 = expected(a, b);
61 COMPARE(isnan(totest), isnan(expect1.first))
62 << "remquo(" << a << ", " << b << ", quo) = " << totest
63 << " != " << expect1.first;
64 const V clean_a = iif(isnan(totest), 0, a);
65 const V clean_b = iif(isnan(totest), 1, b);
66 const auto expect2 = expected(clean_a, clean_b);
67 COMPARE(remquo(clean_a, clean_b, &quo), expect2.first)
68 << "\nclean_a/b = " << clean_a << ", " << clean_b;
69 COMPARE(quo, expect2.second);
70 });
71 }