float_conversion.cpp File Reference
#include <sstream>
#include "main.h"

Functions

template<typename From , typename To >
void test_conversion ()
 
template<typename To >
void test_conversion_to ()
 
 EIGEN_DECLARE_TEST (float_conversion)
 

Function Documentation

◆ EIGEN_DECLARE_TEST()

EIGEN_DECLARE_TEST ( float_conversion  )
45  {
46  for (int i = 0; i < g_repeat; i++) {
47  CALL_SUBTEST(test_conversion_to<float>());
48  CALL_SUBTEST(test_conversion_to<double>());
49  }
50 }
int i
Definition: BiCGSTAB_step_by_step.cpp:9
#define CALL_SUBTEST(FUNC)
Definition: main.h:382
static int g_repeat
Definition: main.h:191

References CALL_SUBTEST, Eigen::g_repeat, and i.

◆ test_conversion()

template<typename From , typename To >
void test_conversion ( )
13  {
14  typedef Array<From, Dynamic, 1> ArrayXFrom;
15  typedef Array<To, Dynamic, 1> ArrayXTo;
16  typedef Array<double, Dynamic, 1> ArrayXDouble;
17 
18  Index size = internal::random<Index>(1, EIGEN_TEST_MAX_SIZE);
19  double from_min = static_cast<double>((std::numeric_limits<From>::min)());
20  double from_range = static_cast<double>((std::numeric_limits<From>::max)()) - from_min;
21 
22  // ArrayXFrom::Random() only generates 32-bit values (#2749), so we generate
23  // doubles and scale to fit the range.
24  ArrayXDouble doubles = (ArrayXDouble::Random(size) + 1.0) * (from_range / 2.0) + from_min;
25  ArrayXFrom from = doubles.template cast<From>();
26  ArrayXTo to(size);
27  for (Index i = 0; i < size; ++i) {
28  to(i) = static_cast<To>(from(i));
29  }
30  VERIFY_IS_APPROX(from.template cast<To>(), to);
31 }
Scalar Scalar int size
Definition: benchVecAdd.cpp:17
#define EIGEN_TEST_MAX_SIZE
Definition: boostmultiprec.cpp:16
General-purpose arrays with easy API for coefficient-wise operations.
Definition: Array.h:48
#define min(a, b)
Definition: datatypes.h:22
#define max(a, b)
Definition: datatypes.h:23
#define VERIFY_IS_APPROX(a, b)
Definition: integer_types.cpp:13
EIGEN_DEFAULT_DENSE_INDEX_TYPE Index
The Index type as used for the API.
Definition: Meta.h:83

References EIGEN_TEST_MAX_SIZE, i, max, min, size, and VERIFY_IS_APPROX.

◆ test_conversion_to()

template<typename To >
void test_conversion_to ( )
34  {
35  CALL_SUBTEST((test_conversion<int64_t, To>()));
36  CALL_SUBTEST((test_conversion<uint64_t, To>()));
37  CALL_SUBTEST((test_conversion<int32_t, To>()));
38  CALL_SUBTEST((test_conversion<uint32_t, To>()));
39  CALL_SUBTEST((test_conversion<int16_t, To>()));
40  CALL_SUBTEST((test_conversion<uint16_t, To>()));
41  CALL_SUBTEST((test_conversion<int8_t, To>()));
42  CALL_SUBTEST((test_conversion<uint8_t, To>()));
43 }

References CALL_SUBTEST.