]>
git.ipfire.org Git - thirdparty/gcc.git/blob - libstdc++-v3/testsuite/experimental/simd/tests/ldexp_scalbn_scalbln_modf.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 vir::test::setFuzzyness
<float>(0);
29 vir::test::setFuzzyness
<double>(0);
31 using T
= typename
V::value_type
;
33 // See https://sourceware.org/bugzilla/show_bug.cgi?id=18031
34 const bool modf_is_broken
= [] {
35 volatile T x
= T(5e20
) / 7;
37 return std::fabs(std::modf(x
, &tmp
)) >= 1;
40 __builtin_fprintf(stderr
,
41 "NOTE: Skipping modf because std::modf is broken.\n");
45 #ifdef __STDC_IEC_559__
46 std::__quiet_NaN_v
<T
>,
48 -std::__infinity_v
<T
>,
50 std::__denorm_min_v
<T
>,
51 std::__norm_min_v
<T
> / 3,
52 -std::__denorm_min_v
<T
>,
53 -std::__norm_min_v
<T
> / 3,
65 std::__finite_max_v
<T
>,
66 -std::__norm_min_v
<T
>,
67 -std::__finite_max_v
<T
>},
70 for (int exp
: {-10000, -100, -10, -1, 0, 1, 10, 100, 10000})
72 const auto totest
= ldexp(input
, exp
);
73 using R
= std::remove_const_t
<decltype(totest
)>;
74 auto&& expected
= [&](const auto& v
) -> const R
{
77 for (std::size_t i
= 0; i
< R::size(); ++i
)
79 tmp
[i
] = ldexp(v
[i
], exp
);
83 const R expect1
= expected(input
);
84 COMPARE(isnan(totest
), isnan(expect1
))
85 << "ldexp(" << input
<< ", " << exp
<< ") = " << totest
87 FUZZY_COMPARE(ldexp(iif(isnan(expect1
), 0, input
), exp
),
88 expected(iif(isnan(expect1
), 0, input
)))
89 << "\nclean = " << iif(isnan(expect1
), 0, input
);
93 for (int exp
: {-10000, -100, -10, -1, 0, 1, 10, 100, 10000})
95 const auto totest
= scalbn(input
, exp
);
96 using R
= std::remove_const_t
<decltype(totest
)>;
97 auto&& expected
= [&](const auto& v
) -> const R
{
100 for (std::size_t i
= 0; i
< R::size(); ++i
)
102 tmp
[i
] = scalbn(v
[i
], exp
);
106 const R expect1
= expected(input
);
107 COMPARE(isnan(totest
), isnan(expect1
))
108 << "scalbn(" << input
<< ", " << exp
<< ") = " << totest
109 << " != " << expect1
;
110 FUZZY_COMPARE(scalbn(iif(isnan(expect1
), 0, input
), exp
),
111 expected(iif(isnan(expect1
), 0, input
)))
112 << "\nclean = " << iif(isnan(expect1
), 0, input
);
116 for (long exp
: {-10000, -100, -10, -1, 0, 1, 10, 100, 10000})
118 const auto totest
= scalbln(input
, exp
);
119 using R
= std::remove_const_t
<decltype(totest
)>;
120 auto&& expected
= [&](const auto& v
) -> const R
{
123 for (std::size_t i
= 0; i
< R::size(); ++i
)
125 tmp
[i
] = scalbln(v
[i
], exp
);
129 const R expect1
= expected(input
);
130 COMPARE(isnan(totest
), isnan(expect1
))
131 << "scalbln(" << input
<< ", " << exp
<< ") = " << totest
132 << " != " << expect1
;
133 FUZZY_COMPARE(scalbln(iif(isnan(expect1
), 0, input
), exp
),
134 expected(iif(isnan(expect1
), 0, input
)))
135 << "\nclean = " << iif(isnan(expect1
), 0, input
);
138 [modf_is_broken
](const V input
) {
142 const V totest
= modf(input
, &integral
);
143 auto&& expected
= [&](const auto& v
) -> std::pair
<const V
, const V
> {
144 std::pair
<V
, V
> tmp
= {};
146 for (std::size_t i
= 0; i
< V::size(); ++i
)
148 typename
V::value_type tmp2
;
149 tmp
.first
[i
] = modf(v
[i
], &tmp2
);
150 tmp
.second
[i
] = tmp2
;
154 const auto expect1
= expected(input
);
155 #ifdef __STDC_IEC_559__
156 COMPARE(isnan(totest
), isnan(expect1
.first
))
157 << "modf(" << input
<< ", iptr) = " << totest
<< " != " << expect1
;
158 COMPARE(isnan(integral
), isnan(expect1
.second
))
159 << "modf(" << input
<< ", iptr) = " << totest
<< " != " << expect1
;
160 COMPARE(isnan(totest
), isnan(integral
))
161 << "modf(" << input
<< ", iptr) = " << totest
<< " != " << expect1
;
162 const V clean
= iif(isnan(totest
), V(), input
);
164 const V clean
= iif(isnormal(input
), input
, V());
166 const auto expect2
= expected(clean
);
167 COMPARE(modf(clean
, &integral
), expect2
.first
) << "\nclean = " << clean
;
168 COMPARE(integral
, expect2
.second
);