check_signbit_impl< T > Struct Template Reference

Static Public Member Functions

static void run ()
 

Member Function Documentation

◆ run()

template<typename T >
static void check_signbit_impl< T >::run ( )
inlinestatic
246  {
247  T true_mask;
248  std::memset(static_cast<void*>(&true_mask), 0xff, sizeof(T));
249  T false_mask;
250  std::memset(static_cast<void*>(&false_mask), 0x00, sizeof(T));
251 
252  std::vector<T> negative_values;
253  std::vector<T> non_negative_values;
254 
256  negative_values = {static_cast<T>(-1), static_cast<T>(NumTraits<T>::lowest())};
257  non_negative_values = {static_cast<T>(0), static_cast<T>(1), static_cast<T>(NumTraits<T>::highest())};
258  } else {
259  // does not have sign bit
260  const T pos_zero = static_cast<T>(0.0);
261  const T pos_one = static_cast<T>(1.0);
262  const T pos_inf = std::numeric_limits<T>::infinity();
263  const T pos_nan = std::numeric_limits<T>::quiet_NaN();
264  // has sign bit
265  const T neg_zero = numext::negate(pos_zero);
266  const T neg_one = numext::negate(pos_one);
267  const T neg_inf = numext::negate(pos_inf);
268  const T neg_nan = numext::negate(pos_nan);
269 
270  negative_values = {neg_zero, neg_one, neg_inf, neg_nan};
271  non_negative_values = {pos_zero, pos_one, pos_inf, pos_nan};
272  }
273 
274  auto check_all = [](auto values, auto expected) {
275  bool all_pass = true;
276  for (T val : values) {
277  const T numext_val = numext::signbit(val);
278  bool not_same = internal::predux_any(internal::bitwise_helper<T>::bitwise_xor(expected, numext_val));
279  all_pass = all_pass && !not_same;
280  if (not_same) std::cout << "signbit(" << val << ") = " << numext_val << " != " << expected << std::endl;
281  }
282  return all_pass;
283  };
284 
285  bool check_all_pass = check_all(non_negative_values, false_mask);
286  check_all_pass = check_all_pass && check_all(negative_values, (NumTraits<T>::IsSigned ? true_mask : false_mask));
287  VERIFY(check_all_pass);
288  }
#define VERIFY(a)
Definition: main.h:362
EIGEN_STRONG_INLINE bool predux_any(const Packet4f &x)
Definition: AltiVec/PacketMath.h:2751
EIGEN_DEVICE_FUNC static constexpr EIGEN_ALWAYS_INLINE Scalar signbit(const Scalar &x)
Definition: MathFunctions.h:1419
T negate(const T &x)
Definition: packetmath_test_shared.h:26
val
Definition: calibrate.py:119
Holds information about the various numeric (i.e. scalar) types allowed by Eigen.
Definition: NumTraits.h:217

References Eigen::test::negate(), Eigen::internal::predux_any(), Eigen::numext::signbit(), calibrate::val, and VERIFY.

Referenced by check_signbit().


The documentation for this struct was generated from the following file: