1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
|
// Copyright (C) 2020-2024 Free Software Foundation, Inc.
//
// This file is part of the GNU ISO C++ Library. This library is free
// software; you can redistribute it and/or modify it under the
// terms of the GNU General Public License as published by the
// Free Software Foundation; either version 3, or (at your option)
// any later version.
//
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License along
// with this library; see the file COPYING3. If not see
// <http://www.gnu.org/licenses/>.
// only: float|double|ldouble * * *
// expensive: * [1-9] * *
#include "bits/main.h"
template <typename V>
void
test()
{
using T = typename V::value_type;
#ifdef __STDC_IEC_559__
constexpr T inf = std::__infinity_v<T>;
constexpr T denorm_min = std::__denorm_min_v<T>;
#endif
constexpr T norm_min = std::__norm_min_v<T>;
constexpr T max = std::__finite_max_v<T>;
constexpr T min = std::__finite_min_v<T>;
test_values<V>(
{2.1,
2.0,
2.9,
2.5,
2.499,
1.5,
1.499,
1.99,
0.99,
0.5,
0.499,
0.,
-2.1,
-2.0,
-2.9,
-2.5,
-2.499,
-1.5,
-1.499,
-1.99,
-0.99,
-0.5,
-0.499,
3 << 21,
3 << 22,
3 << 23,
-(3 << 21),
-(3 << 22),
-(3 << 23),
#ifdef __STDC_IEC_559__
-0.,
inf,
-inf,
denorm_min,
norm_min * 0.9,
-denorm_min,
-norm_min * 0.9,
#endif
max,
norm_min,
min,
-norm_min
},
[](const V input) {
const V expected([&](auto i) { return std::trunc(input[i]); });
COMPARE(trunc(input), expected) << input;
},
[](const V input) {
const V expected([&](auto i) { return std::ceil(input[i]); });
COMPARE(ceil(input), expected) << input;
},
[](const V input) {
const V expected([&](auto i) { return std::floor(input[i]); });
COMPARE(floor(input), expected) << input;
});
#ifdef __STDC_IEC_559__
test_values<V>(
{
#ifdef __SUPPORT_SNAN__
std::__signaling_NaN_v<T>,
#endif
std::__quiet_NaN_v<T>},
[](const V input) {
const V expected([&](auto i) { return std::trunc(input[i]); });
COMPARE(isnan(trunc(input)), isnan(expected)) << input;
},
[](const V input) {
const V expected([&](auto i) { return std::ceil(input[i]); });
COMPARE(isnan(ceil(input)), isnan(expected)) << input;
},
[](const V input) {
const V expected([&](auto i) { return std::floor(input[i]); });
COMPARE(isnan(floor(input)), isnan(expected)) << input;
});
#endif
}
|