4 #define BOOST_TEST_DYN_LINK
5 #define BOOST_TEST_MODULE IEEE754_SingleConverterTest
6 #include <boost/test/unit_test.hpp>
7 using namespace boost::unit_test_framework;
18 float testValue = 3.25;
19 void* warningAvoider = &testValue;
20 int32_t rawValue = *(
reinterpret_cast<int32_t*
>(warningAvoider));
22 BOOST_CHECK_CLOSE(converter.
scalarToCooked<
float>(rawValue), 3.25, 0.0001);
23 BOOST_CHECK_CLOSE(converter.
scalarToCooked<
double>(rawValue), 3.25, 0.0001);
27 BOOST_CHECK_EQUAL(converter.
scalarToCooked<uint16_t>(rawValue), 3);
29 BOOST_CHECK_EQUAL(converter.
scalarToCooked<uint32_t>(rawValue), 3);
31 BOOST_CHECK_EQUAL(converter.
scalarToCooked<uint64_t>(rawValue), 3);
41 float testValue = 60000.7;
42 void* warningAvoider = &testValue;
43 int32_t rawValue = *(
reinterpret_cast<int32_t*
>(warningAvoider));
45 BOOST_CHECK_CLOSE(converter.
scalarToCooked<
float>(rawValue), 60000.7, 0.0001);
46 BOOST_CHECK_CLOSE(converter.
scalarToCooked<
double>(rawValue), 60000.7, 0.0001);
47 BOOST_CHECK_THROW(converter.
scalarToCooked<int8_t>(rawValue), boost::numeric::positive_overflow);
48 BOOST_CHECK_THROW(converter.
scalarToCooked<uint8_t>(rawValue), boost::numeric::positive_overflow);
49 BOOST_CHECK_THROW(converter.
scalarToCooked<int16_t>(rawValue), boost::numeric::positive_overflow);
50 BOOST_CHECK_EQUAL(converter.
scalarToCooked<uint16_t>(rawValue), 60001);
51 BOOST_CHECK_EQUAL(converter.
scalarToCooked<int32_t>(rawValue), 60001);
52 BOOST_CHECK_EQUAL(converter.
scalarToCooked<uint32_t>(rawValue), 60001);
53 BOOST_CHECK_EQUAL(converter.
scalarToCooked<int64_t>(rawValue), 60001);
54 BOOST_CHECK_EQUAL(converter.
scalarToCooked<uint64_t>(rawValue), 60001);
62 float testValue = -240.6;
63 void* warningAvoider = &testValue;
64 int32_t rawValue = *(
reinterpret_cast<int32_t*
>(warningAvoider));
66 BOOST_CHECK_CLOSE(converter.
scalarToCooked<
float>(rawValue), -240.6, 0.0001);
67 BOOST_CHECK_CLOSE(converter.
scalarToCooked<
double>(rawValue), -240.6, 0.0001);
68 BOOST_CHECK_THROW(converter.
scalarToCooked<int8_t>(rawValue), boost::numeric::negative_overflow);
69 BOOST_CHECK_THROW(converter.
scalarToCooked<uint8_t>(rawValue), boost::numeric::negative_overflow);
70 BOOST_CHECK_EQUAL(converter.
scalarToCooked<int16_t>(rawValue), -241);
71 BOOST_CHECK_THROW(converter.
scalarToCooked<uint16_t>(rawValue), boost::numeric::negative_overflow);
72 BOOST_CHECK_EQUAL(converter.
scalarToCooked<int32_t>(rawValue), -241);
73 BOOST_CHECK_THROW(converter.
scalarToCooked<uint32_t>(rawValue), boost::numeric::negative_overflow);
74 BOOST_CHECK_EQUAL(converter.
scalarToCooked<int64_t>(rawValue), -241);
75 BOOST_CHECK_THROW(converter.
scalarToCooked<uint64_t>(rawValue), boost::numeric::negative_overflow);
81 void* warningAvoider = &rawValue;
82 float testValue = *(
reinterpret_cast<float*
>(warningAvoider));
84 BOOST_CHECK_CLOSE(testValue, expectedValue, 0.0001);
106 double tooLarge = DBL_MAX + 1;
107 double tooSmall = -(DBL_MAX);
118 float testValue = 0.0;
119 void* warningAvoider = &testValue;
120 int32_t rawValue = *(
reinterpret_cast<int32_t*
>(warningAvoider));