| 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 |
vir::test::setFuzzyness<float>(0); |
| 27 |
vir::test::setFuzzyness<double>(0); |
| 28 |
|
| 29 |
using T = typename V::value_type; |
| 30 |
test_values_2arg<V>( |
| 31 |
{ |
| 32 |
#ifdef __STDC_IEC_559__ |
| 33 |
std::__quiet_NaN_v<T>, std::__infinity_v<T>, -std::__infinity_v<T>, |
| 34 |
std::__denorm_min_v<T>, std::__norm_min_v<T> / 3, -0., |
| 35 |
#endif |
| 36 |
+0., std::__norm_min_v<T>, std::__finite_max_v<T>}, |
| 37 |
{10000}, [](V a, V b) { |
| 38 |
|
| 39 |
#ifndef __STDC_IEC_559__ |
| 40 |
// without __STDC_IEC_559__, remquo(a, 0) is unspecified |
| 41 |
where(b == 0, b) = 1; |
| 42 |
#endif |
| 43 |
using IV = std::experimental::fixed_size_simd<int, V::size()>; |
| 44 |
IV quo = {}; |
| 45 |
const V totest = remquo(a, b, &quo); |
| 46 |
auto&& expected |
| 47 |
= [&](const auto& v, const auto& w) -> std::pair<const V, const IV> { |
| 48 |
std::pair<V, IV> tmp = {}; |
| 49 |
using std::remquo; |
| 50 |
for (std::size_t i = 0; i < V::size(); ++i) |
| 51 |
{ |
| 52 |
int tmp2; |
| 53 |
tmp.first[i] = remquo(v[i], w[i], &tmp2); |
| 54 |
tmp.second[i] = tmp2; |
| 55 |
} |
| 56 |
return tmp; |
| 57 |
}; |
| 58 |
const auto expect1 = expected(a, b); |
| 59 |
COMPARE(isnan(totest), isnan(expect1.first)) |
| 60 |
<< "remquo(" << a << ", " << b << ", quo) = " << totest |
| 61 |
<< " != " << expect1.first; |
| 62 |
const V clean_a = iif(isnan(totest), 0, a); |
| 63 |
const V clean_b = iif(isnan(totest), 1, b); |
| 64 |
const auto expect2 = expected(clean_a, clean_b); |
| 65 |
COMPARE(remquo(clean_a, clean_b, &quo), expect2.first) |
| 66 |
<< "\nclean_a/b = " << clean_a << ", " << clean_b; |
| 67 |
COMPARE(quo, expect2.second); |
| 68 |
}); |
| 69 |
} |