| 1 |
// Copyright (C) 2020-2025 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/main.h" |
| 21 |
|
| 22 |
template <typename V> |
| 23 |
void |
| 24 |
test() |
| 25 |
{ |
| 26 |
using T = typename V::value_type; |
| 27 |
#ifdef __STDC_IEC_559__ |
| 28 |
constexpr T inf = std::__infinity_v<T>; |
| 29 |
constexpr T denorm_min = std::__denorm_min_v<T>; |
| 30 |
#endif |
| 31 |
constexpr T norm_min = std::__norm_min_v<T>; |
| 32 |
constexpr T max = std::__finite_max_v<T>; |
| 33 |
constexpr T min = std::__finite_min_v<T>; |
| 34 |
test_values<V>( |
| 35 |
{2.1, |
| 36 |
2.0, |
| 37 |
2.9, |
| 38 |
2.5, |
| 39 |
2.499, |
| 40 |
1.5, |
| 41 |
1.499, |
| 42 |
1.99, |
| 43 |
0.99, |
| 44 |
0.5, |
| 45 |
0.499, |
| 46 |
0., |
| 47 |
-2.1, |
| 48 |
-2.0, |
| 49 |
-2.9, |
| 50 |
-2.5, |
| 51 |
-2.499, |
| 52 |
-1.5, |
| 53 |
-1.499, |
| 54 |
-1.99, |
| 55 |
-0.99, |
| 56 |
-0.5, |
| 57 |
-0.499, |
| 58 |
3 << 21, |
| 59 |
3 << 22, |
| 60 |
3 << 23, |
| 61 |
-(3 << 21), |
| 62 |
-(3 << 22), |
| 63 |
-(3 << 23), |
| 64 |
#ifdef __STDC_IEC_559__ |
| 65 |
-0., |
| 66 |
inf, |
| 67 |
-inf, |
| 68 |
denorm_min, |
| 69 |
norm_min * 0.9, |
| 70 |
-denorm_min, |
| 71 |
-norm_min * 0.9, |
| 72 |
#endif |
| 73 |
max, |
| 74 |
norm_min, |
| 75 |
min, |
| 76 |
-norm_min |
| 77 |
}, |
| 78 |
[](const V input) { |
| 79 |
const V expected([&](auto i) { return std::trunc(input[i]); }); |
| 80 |
COMPARE(trunc(input), expected) << input; |
| 81 |
}, |
| 82 |
[](const V input) { |
| 83 |
const V expected([&](auto i) { return std::ceil(input[i]); }); |
| 84 |
COMPARE(ceil(input), expected) << input; |
| 85 |
}, |
| 86 |
[](const V input) { |
| 87 |
const V expected([&](auto i) { return std::floor(input[i]); }); |
| 88 |
COMPARE(floor(input), expected) << input; |
| 89 |
}); |
| 90 |
|
| 91 |
#ifdef __STDC_IEC_559__ |
| 92 |
test_values<V>( |
| 93 |
{ |
| 94 |
#ifdef __SUPPORT_SNAN__ |
| 95 |
std::__signaling_NaN_v<T>, |
| 96 |
#endif |
| 97 |
std::__quiet_NaN_v<T>}, |
| 98 |
[](const V input) { |
| 99 |
const V expected([&](auto i) { return std::trunc(input[i]); }); |
| 100 |
COMPARE(isnan(trunc(input)), isnan(expected)) << input; |
| 101 |
}, |
| 102 |
[](const V input) { |
| 103 |
const V expected([&](auto i) { return std::ceil(input[i]); }); |
| 104 |
COMPARE(isnan(ceil(input)), isnan(expected)) << input; |
| 105 |
}, |
| 106 |
[](const V input) { |
| 107 |
const V expected([&](auto i) { return std::floor(input[i]); }); |
| 108 |
COMPARE(isnan(floor(input)), isnan(expected)) << input; |
| 109 |
}); |
| 110 |
#endif |
| 111 |
} |