]> git.ipfire.org Git - thirdparty/gcc.git/blame - libstdc++-v3/testsuite/experimental/simd/tests/trunc_ceil_floor.cc
Update copyright years.
[thirdparty/gcc.git] / libstdc++-v3 / testsuite / experimental / simd / tests / trunc_ceil_floor.cc
CommitLineData
7adcbafe 1// Copyright (C) 2020-2022 Free Software Foundation, Inc.
02e32295
MK
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
aa89c53c
MK
18// only: float|double|ldouble * * *
19// expensive: * [1-9] * *
02e32295
MK
20#include "bits/test_values.h"
21#include "bits/verify.h"
22
23template <typename V>
24 void
25 test()
26 {
27 using T = typename V::value_type;
28 constexpr T inf = std::__infinity_v<T>;
29 constexpr T denorm_min = std::__denorm_min_v<T>;
30 constexpr T norm_min = std::__norm_min_v<T>;
31 constexpr T max = std::__finite_max_v<T>;
32 constexpr T min = std::__finite_min_v<T>;
33 test_values<V>(
34 {2.1,
35 2.0,
36 2.9,
37 2.5,
38 2.499,
39 1.5,
40 1.499,
41 1.99,
42 0.99,
43 0.5,
44 0.499,
45 0.,
46 -2.1,
47 -2.0,
48 -2.9,
49 -2.5,
50 -2.499,
51 -1.5,
52 -1.499,
53 -1.99,
54 -0.99,
55 -0.5,
56 -0.499,
57 3 << 21,
58 3 << 22,
59 3 << 23,
60 -(3 << 21),
61 -(3 << 22),
62 -(3 << 23),
63#ifdef __STDC_IEC_559__
64 -0.,
65 inf,
66 -inf,
67 denorm_min,
68 norm_min * 0.9,
69 -denorm_min,
70 -norm_min * 0.9,
71#endif
72 max,
73 norm_min,
74 min,
75 -norm_min
76 },
77 [](const V input) {
78 const V expected([&](auto i) { return std::trunc(input[i]); });
79 COMPARE(trunc(input), expected) << input;
80 },
81 [](const V input) {
82 const V expected([&](auto i) { return std::ceil(input[i]); });
83 COMPARE(ceil(input), expected) << input;
84 },
85 [](const V input) {
86 const V expected([&](auto i) { return std::floor(input[i]); });
87 COMPARE(floor(input), expected) << input;
88 });
89
90#ifdef __STDC_IEC_559__
91 test_values<V>(
92 {
93#ifdef __SUPPORT_SNAN__
94 std::__signaling_NaN_v<T>,
95#endif
96 std::__quiet_NaN_v<T>},
97 [](const V input) {
98 const V expected([&](auto i) { return std::trunc(input[i]); });
99 COMPARE(isnan(trunc(input)), isnan(expected)) << input;
100 },
101 [](const V input) {
102 const V expected([&](auto i) { return std::ceil(input[i]); });
103 COMPARE(isnan(ceil(input)), isnan(expected)) << input;
104 },
105 [](const V input) {
106 const V expected([&](auto i) { return std::floor(input[i]); });
107 COMPARE(isnan(floor(input)), isnan(expected)) << input;
108 });
109#endif
110 }