]>
git.ipfire.org Git - thirdparty/gcc.git/blob - libstdc++-v3/testsuite/experimental/simd/tests/frexp.cc
1 // Copyright (C) 2020-2022 Free Software Foundation, Inc.
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)
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.
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/>.
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"
28 using int_v
= std::experimental::fixed_size_simd
<int, V::size()>;
29 using T
= typename
V::value_type
;
30 constexpr auto denorm_min
= std::__denorm_min_v
<T
>;
31 constexpr auto norm_min
= std::__norm_min_v
<T
>;
32 constexpr auto max
= std::__finite_max_v
<T
>;
33 constexpr auto nan
= std::__quiet_NaN_v
<T
>;
34 constexpr auto inf
= std::__infinity_v
<T
>;
36 {0, 0.25, 0.5, 1, 3, 4, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19,
37 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 32, 31, -0., -0.25, -0.5, -1,
38 -3, -4, -6, -7, -8, -9, -10, -11, -12, -13, -14, -15, -16, -17, -18,
39 -19, -20, -21, -22, -23, -24, -25, -26, -27, -28, -29, -32, -31,
40 #if __GCC_IEC_559 >= 2
41 denorm_min
, -denorm_min
, norm_min
/ 2, -norm_min
/ 2,
43 max
, -max
, max
* 0.123f
, -max
* 0.123f
},
46 const int_v
expectedExponent([&](auto i
) {
48 expectedFraction
[i
] = std::frexp(input
[i
], &exp
);
52 const V fraction
= frexp(input
, &exponent
);
53 COMPARE(fraction
, expectedFraction
) << ", input = " << input
54 << ", delta: " << fraction
- expectedFraction
;
55 COMPARE(exponent
, expectedExponent
)
56 << "\ninput: " << input
<< ", fraction: " << fraction
;
58 #ifdef __STDC_IEC_559__
60 // If x is a NaN, a NaN is returned, and the value of *exp is unspecified.
62 // If x is positive infinity (negative infinity), positive infinity
63 // (negative infinity) is returned, and the value of *exp is unspecified.
64 // This behavior is only guaranteed with C's Annex F when __STDC_IEC_559__
66 {nan
, inf
, -inf
, denorm_min
, denorm_min
* 1.72, -denorm_min
,
67 -denorm_min
* 1.72, 0., -0., 1, -1},
69 const V
expectedFraction([&](auto i
) {
71 return std::frexp(input
[i
], &exp
);
74 const V fraction
= frexp(input
, &exponent
);
75 COMPARE(isnan(fraction
), isnan(expectedFraction
))
76 << fraction
<< ", input = " << input
77 << ", delta: " << fraction
- expectedFraction
;
78 COMPARE(isinf(fraction
), isinf(expectedFraction
))
79 << fraction
<< ", input = " << input
80 << ", delta: " << fraction
- expectedFraction
;
81 COMPARE(signbit(fraction
), signbit(expectedFraction
))
82 << fraction
<< ", input = " << input
83 << ", delta: " << fraction
- expectedFraction
;