mirror of
https://gitlab.com/libeigen/eigen.git
synced 2025-04-20 16:49:38 +08:00
Update test of numext::signbit.
This commit is contained in:
parent
3717854a21
commit
e1aee4ab39
@ -239,19 +239,6 @@ void check_rsqrt() {
|
|||||||
check_rsqrt_impl<T>::run();
|
check_rsqrt_impl<T>::run();
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename T, bool IsInteger = NumTraits<T>::IsInteger>
|
|
||||||
struct ref_signbit_func_impl {
|
|
||||||
static bool run(const T& x) { return std::signbit(x); }
|
|
||||||
};
|
|
||||||
template <typename T>
|
|
||||||
struct ref_signbit_func_impl<T, true> {
|
|
||||||
// MSVC (perhaps others) does not have a std::signbit overload for integers
|
|
||||||
static bool run(const T& x) { return x < T(0); }
|
|
||||||
};
|
|
||||||
template <typename T>
|
|
||||||
bool ref_signbit_func(const T& x) {
|
|
||||||
return ref_signbit_func_impl<T>::run(x);
|
|
||||||
}
|
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
struct check_signbit_impl {
|
struct check_signbit_impl {
|
||||||
@ -261,6 +248,15 @@ struct check_signbit_impl {
|
|||||||
T false_mask;
|
T false_mask;
|
||||||
std::memset(static_cast<void*>(&false_mask), 0x00, sizeof(T));
|
std::memset(static_cast<void*>(&false_mask), 0x00, sizeof(T));
|
||||||
|
|
||||||
|
std::vector<T> negative_values;
|
||||||
|
std::vector<T> non_negative_values;
|
||||||
|
|
||||||
|
if (NumTraits<T>::IsInteger) {
|
||||||
|
negative_values = {static_cast<T>(-1),
|
||||||
|
static_cast<T>(NumTraits<T>::lowest())};
|
||||||
|
non_negative_values = {static_cast<T>(0), static_cast<T>(1),
|
||||||
|
static_cast<T>(NumTraits<T>::highest())};
|
||||||
|
} else {
|
||||||
// has sign bit
|
// has sign bit
|
||||||
const T neg_zero = static_cast<T>(-0.0);
|
const T neg_zero = static_cast<T>(-0.0);
|
||||||
const T neg_one = static_cast<T>(-1.0);
|
const T neg_one = static_cast<T>(-1.0);
|
||||||
@ -271,18 +267,27 @@ struct check_signbit_impl {
|
|||||||
const T pos_one = static_cast<T>(1.0);
|
const T pos_one = static_cast<T>(1.0);
|
||||||
const T pos_inf = std::numeric_limits<T>::infinity();
|
const T pos_inf = std::numeric_limits<T>::infinity();
|
||||||
const T pos_nan = std::numeric_limits<T>::quiet_NaN();
|
const T pos_nan = std::numeric_limits<T>::quiet_NaN();
|
||||||
|
negative_values = {neg_zero, neg_one, neg_inf, neg_nan};
|
||||||
|
non_negative_values = {pos_zero, pos_one, pos_inf, pos_nan};
|
||||||
|
}
|
||||||
|
|
||||||
std::vector<T> values = {neg_zero, neg_one, neg_inf, neg_nan, pos_zero, pos_one, pos_inf, pos_nan};
|
|
||||||
|
|
||||||
|
auto check_all = [](auto values, auto expected) {
|
||||||
bool all_pass = true;
|
bool all_pass = true;
|
||||||
|
|
||||||
for (T val : values) {
|
for (T val : values) {
|
||||||
const T numext_val = numext::signbit(val);
|
const T numext_val = numext::signbit(val);
|
||||||
const T ref_val = ref_signbit_func(val) ? true_mask : false_mask;
|
bool not_same = internal::predux_any(
|
||||||
bool not_same = internal::predux_any(internal::bitwise_helper<T>::bitwise_xor(ref_val, numext_val));
|
internal::bitwise_helper<T>::bitwise_xor(expected, numext_val));
|
||||||
all_pass = all_pass && !not_same;
|
all_pass = all_pass && !not_same;
|
||||||
if (not_same) std::cout << "signbit(" << val << ") != " << numext_val << "\n";
|
if (not_same)
|
||||||
|
std::cout << "signbit(" << val << ") = " << numext_val
|
||||||
|
<< " != " << expected << std::endl;
|
||||||
}
|
}
|
||||||
|
return all_pass;
|
||||||
|
};
|
||||||
|
|
||||||
|
bool all_pass = check_all(non_negative_values, false_mask);
|
||||||
|
all_pass = all_pass && check_all(negative_values, (NumTraits<T>::IsSigned ? true_mask : false_mask));
|
||||||
VERIFY(all_pass);
|
VERIFY(all_pass);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
Loading…
x
Reference in New Issue
Block a user