mirror of
https://github.com/boostorg/endian.git
synced 2025-07-29 20:17:26 +02:00
Remove floating point support for boost 1.58.0. As currently implemented, return by value operations are not reliable because normalization and other bit pattern changes can occur. Docs not updated as yet. Floating point support will be corrected and reinstated for boost 1.59.0, based on in-place customization and inplace and/or copy signatures to replace the unsafe (i.e. native_to_big/little ) by value returns. The big/little_to_native return by value functions are safe, but require reimplementation.
This commit is contained in:
@ -17,23 +17,24 @@ using namespace boost::endian;
|
||||
using std::cout;
|
||||
using std::endl;
|
||||
using boost::int32_t;
|
||||
using boost::int64_t;
|
||||
|
||||
namespace user
|
||||
{
|
||||
class UDT
|
||||
{
|
||||
public:
|
||||
UDT() : id_(0), value_(0.0) {desc_[0] = '\0';}
|
||||
UDT(int32_t id, float value, const char* desc) : id_(id), value_(value)
|
||||
UDT() : id_(0), value_(0) {desc_[0] = '\0';}
|
||||
UDT(int32_t id, int64_t value, const char* desc) : id_(id), value_(value)
|
||||
{
|
||||
std::strncpy(desc_, desc, sizeof(desc_)-1);
|
||||
desc_[sizeof(desc_)-1] = '\0';
|
||||
}
|
||||
int32_t id() const {return id_;}
|
||||
float value() const {return value_;}
|
||||
int64_t value() const {return value_;}
|
||||
const char* desc() const {return desc_;}
|
||||
void id(int32_t x) {id_ = x;}
|
||||
void value(float v) {value_ = v;}
|
||||
void value(int64_t v) {value_ = v;}
|
||||
void desc(const char* s)
|
||||
{
|
||||
std::strncpy(desc_, s, sizeof(desc_)-1);
|
||||
@ -44,7 +45,7 @@ namespace user
|
||||
|
||||
private:
|
||||
int32_t id_;
|
||||
float value_;
|
||||
int64_t value_;
|
||||
char desc_[56]; // '/0'
|
||||
};
|
||||
|
||||
@ -57,7 +58,7 @@ namespace user
|
||||
|
||||
int main(int, char* [])
|
||||
{
|
||||
user::UDT x(1, 1.2345f, "Bingo!");
|
||||
user::UDT x(1, 123456789012345LL, "Bingo!");
|
||||
|
||||
//cout << std::hex;
|
||||
cout << "(1) " << x.id() << ' ' << x.value() << ' ' << x.desc() << endl;
|
||||
|
@ -79,22 +79,6 @@ namespace endian
|
||||
BOOST_SCOPED_ENUM(align) A = align::no>
|
||||
class endian_arithmetic;
|
||||
|
||||
// big endian floating point aligned types
|
||||
typedef endian_arithmetic<order::big, float, 32, align::yes> big_float32_at;
|
||||
typedef endian_arithmetic<order::big, double, 64, align::yes> big_float64_at;
|
||||
|
||||
// little endian floating point aligned types
|
||||
typedef endian_arithmetic<order::little, float, 32, align::yes> little_float32_at;
|
||||
typedef endian_arithmetic<order::little, double, 64, align::yes> little_float64_at;
|
||||
|
||||
// big endian floating point unaligned types
|
||||
typedef endian_arithmetic<order::big, float, 32, align::no> big_float32_t;
|
||||
typedef endian_arithmetic<order::big, double, 64, align::no> big_float64_t;
|
||||
|
||||
// little endian floating point unaligned types
|
||||
typedef endian_arithmetic<order::little, float, 32, align::no> little_float32_t;
|
||||
typedef endian_arithmetic<order::little, double, 64, align::no> little_float64_t;
|
||||
|
||||
// big endian signed integer aligned types
|
||||
typedef endian_arithmetic<order::big, int8_t, 8, align::yes> big_int8_at;
|
||||
typedef endian_arithmetic<order::big, int16_t, 16, align::yes> big_int16_at;
|
||||
@ -182,12 +166,6 @@ namespace endian
|
||||
typedef big_uint48_t native_uint48_t;
|
||||
typedef big_uint56_t native_uint56_t;
|
||||
typedef big_uint64_t native_uint64_t;
|
||||
|
||||
// native endian floating point types
|
||||
typedef big_float32_t native_float32_t;
|
||||
typedef big_float64_t native_float64_t;
|
||||
typedef big_float32_at native_float32_at;
|
||||
typedef big_float64_at native_float64_at;
|
||||
# else
|
||||
// native endian signed integer unaligned types
|
||||
typedef little_int8_t native_int8_t;
|
||||
@ -208,12 +186,6 @@ namespace endian
|
||||
typedef little_uint48_t native_uint48_t;
|
||||
typedef little_uint56_t native_uint56_t;
|
||||
typedef little_uint64_t native_uint64_t;
|
||||
|
||||
// native endian floating point types
|
||||
typedef little_float32_t native_float32_t;
|
||||
typedef little_float64_t native_float64_t;
|
||||
typedef little_float32_at native_float32_at;
|
||||
typedef little_float64_at native_float64_at;
|
||||
# endif
|
||||
|
||||
# ifdef BOOST_ENDIAN_DEPRECATED_NAMES
|
||||
@ -340,78 +312,6 @@ namespace endian
|
||||
{ detail::store_big_endian<T, n_bits/8>(this->m_value, val); return *this; }
|
||||
operator value_type() const BOOST_NOEXCEPT { return this->value(); }
|
||||
};
|
||||
|
||||
// unaligned float big endian specialization
|
||||
template <>
|
||||
class endian_arithmetic< order::big, float, 32, align::no >
|
||||
: public endian_buffer< order::big, float, 32, align::no >,
|
||||
cover_operators< endian_arithmetic< order::big, float, 32 >, float >
|
||||
{
|
||||
public:
|
||||
typedef float value_type;
|
||||
# ifndef BOOST_ENDIAN_NO_CTORS
|
||||
endian_arithmetic() BOOST_ENDIAN_DEFAULT_CONSTRUCT
|
||||
BOOST_ENDIAN_EXPLICIT_OPT endian_arithmetic(value_type val) BOOST_NOEXCEPT
|
||||
{ detail::big_reverse_copy(val, this->m_value); }
|
||||
# endif
|
||||
endian_arithmetic& operator=(value_type val) BOOST_NOEXCEPT
|
||||
{ detail::big_reverse_copy(val, this->m_value); return *this; }
|
||||
operator value_type() const BOOST_NOEXCEPT { return this->value(); }
|
||||
};
|
||||
|
||||
// unaligned double big endian specialization
|
||||
template <>
|
||||
class endian_arithmetic< order::big, double, 64, align::no >
|
||||
: public endian_buffer< order::big, double, 64, align::no >,
|
||||
cover_operators< endian_arithmetic< order::big, double, 64 >, double >
|
||||
{
|
||||
public:
|
||||
typedef double value_type;
|
||||
# ifndef BOOST_ENDIAN_NO_CTORS
|
||||
endian_arithmetic() BOOST_ENDIAN_DEFAULT_CONSTRUCT
|
||||
BOOST_ENDIAN_EXPLICIT_OPT endian_arithmetic(value_type val) BOOST_NOEXCEPT
|
||||
{ detail::big_reverse_copy(val, this->m_value); }
|
||||
# endif
|
||||
endian_arithmetic& operator=(value_type val) BOOST_NOEXCEPT
|
||||
{ detail::big_reverse_copy(val, this->m_value); return *this; }
|
||||
operator value_type() const BOOST_NOEXCEPT { return this->value(); }
|
||||
};
|
||||
|
||||
// unaligned float little endian specialization
|
||||
template <>
|
||||
class endian_arithmetic< order::little, float, 32, align::no >
|
||||
: public endian_buffer< order::little, float, 32, align::no >,
|
||||
cover_operators< endian_arithmetic< order::little, float, 32 >, float >
|
||||
{
|
||||
public:
|
||||
typedef float value_type;
|
||||
# ifndef BOOST_ENDIAN_NO_CTORS
|
||||
endian_arithmetic() BOOST_ENDIAN_DEFAULT_CONSTRUCT
|
||||
BOOST_ENDIAN_EXPLICIT_OPT endian_arithmetic(value_type val) BOOST_NOEXCEPT
|
||||
{ detail::little_reverse_copy(val, this->m_value); }
|
||||
# endif
|
||||
endian_arithmetic& operator=(value_type val) BOOST_NOEXCEPT
|
||||
{ detail::little_reverse_copy(val, this->m_value); return *this; }
|
||||
operator value_type() const BOOST_NOEXCEPT { return this->value(); }
|
||||
};
|
||||
|
||||
// unaligned double little endian specialization
|
||||
template <>
|
||||
class endian_arithmetic< order::little, double, 64, align::no >
|
||||
: public endian_buffer< order::little, double, 64, align::no >,
|
||||
cover_operators< endian_arithmetic< order::little, double, 64 >, double >
|
||||
{
|
||||
public:
|
||||
typedef double value_type;
|
||||
# ifndef BOOST_ENDIAN_NO_CTORS
|
||||
endian_arithmetic() BOOST_ENDIAN_DEFAULT_CONSTRUCT
|
||||
BOOST_ENDIAN_EXPLICIT_OPT endian_arithmetic(value_type val) BOOST_NOEXCEPT
|
||||
{ detail::little_reverse_copy(val, this->m_value); }
|
||||
# endif
|
||||
endian_arithmetic& operator=(value_type val) BOOST_NOEXCEPT
|
||||
{ detail::little_reverse_copy(val, this->m_value); return *this; }
|
||||
operator value_type() const BOOST_NOEXCEPT { return this->value(); }
|
||||
};
|
||||
|
||||
// unaligned little endian specialization
|
||||
template <typename T, std::size_t n_bits>
|
||||
|
@ -76,22 +76,6 @@ namespace endian
|
||||
BOOST_SCOPED_ENUM(align) A = align::no>
|
||||
class endian_buffer;
|
||||
|
||||
// aligned big endian floating point buffers
|
||||
typedef endian_buffer<order::big, float, 32, align::yes> big_float32_buf_at;
|
||||
typedef endian_buffer<order::big, double, 64, align::yes> big_float64_buf_at;
|
||||
|
||||
// aligned little endian floating point buffers
|
||||
typedef endian_buffer<order::little, float, 32, align::yes> little_float32_buf_at;
|
||||
typedef endian_buffer<order::little, double, 64, align::yes> little_float64_buf_at;
|
||||
|
||||
// unaligned big endian floating point buffers
|
||||
typedef endian_buffer<order::big, float, 32, align::no> big_float32_buf_t;
|
||||
typedef endian_buffer<order::big, double, 64, align::no> big_float64_buf_t;
|
||||
|
||||
// unaligned little endian floating point buffers
|
||||
typedef endian_buffer<order::little, float, 32, align::no> little_float32_buf_t;
|
||||
typedef endian_buffer<order::little, double, 64, align::no> little_float64_buf_t;
|
||||
|
||||
// aligned big endian signed integer buffers
|
||||
typedef endian_buffer<order::big, int8_t, 8, align::yes> big_int8_buf_at;
|
||||
typedef endian_buffer<order::big, int16_t, 16, align::yes> big_int16_buf_at;
|
||||
@ -179,12 +163,6 @@ namespace endian
|
||||
typedef big_uint48_buf_t native_uint48_buf_t;
|
||||
typedef big_uint56_buf_t native_uint56_buf_t;
|
||||
typedef big_uint64_buf_t native_uint64_buf_t;
|
||||
|
||||
// native endian floating point buffers
|
||||
typedef big_float32_buf_t native_float32_buf_t;
|
||||
typedef big_float64_buf_t native_float64_buf_t;
|
||||
typedef big_float32_buf_at native_float32_buf_at;
|
||||
typedef big_float64_buf_at native_float64_buf_at;
|
||||
# else
|
||||
// unaligned native endian signed integer buffers
|
||||
typedef little_int8_buf_t native_int8_buf_t;
|
||||
@ -205,12 +183,6 @@ namespace endian
|
||||
typedef little_uint48_buf_t native_uint48_buf_t;
|
||||
typedef little_uint56_buf_t native_uint56_buf_t;
|
||||
typedef little_uint64_buf_t native_uint64_buf_t;
|
||||
|
||||
// native endian floating point buffers
|
||||
typedef little_float32_buf_t native_float32_buf_t;
|
||||
typedef little_float64_buf_t native_float64_buf_t;
|
||||
typedef little_float32_buf_at native_float32_buf_at;
|
||||
typedef little_float64_buf_at native_float64_buf_at;
|
||||
# endif
|
||||
|
||||
// Stream inserter
|
||||
|
@ -61,9 +61,6 @@ namespace endian
|
||||
inline uint16_t endian_reverse(uint16_t x) BOOST_NOEXCEPT;
|
||||
inline uint32_t endian_reverse(uint32_t x) BOOST_NOEXCEPT;
|
||||
inline uint64_t endian_reverse(uint64_t x) BOOST_NOEXCEPT;
|
||||
// TODO: Track N3626,Floating-Point Typedefs Having Specified Widths, proposal
|
||||
inline float endian_reverse(float x) BOOST_NOEXCEPT;
|
||||
inline double endian_reverse(double x) BOOST_NOEXCEPT;
|
||||
|
||||
// reverse byte order unless native endianness is big
|
||||
template <class EndianReversible >
|
||||
@ -162,9 +159,7 @@ namespace endian
|
||||
{
|
||||
// generic reverse function template implementation approach using std::reverse
|
||||
// suggested by Mathias Gaunard. Primary motivation for inclusion is to have an
|
||||
// independent implementation to test against. Secondary motivation is use by
|
||||
// floating-point endian_reverse, but that use is likely to be replace by a
|
||||
// more tailored floating-point implementation.
|
||||
// independent implementation to test against.
|
||||
|
||||
template <class T>
|
||||
inline T std_endian_reverse(T x) BOOST_NOEXCEPT
|
||||
@ -283,22 +278,6 @@ namespace endian
|
||||
# endif
|
||||
}
|
||||
|
||||
inline float endian_reverse(float x) BOOST_NOEXCEPT
|
||||
{
|
||||
BOOST_STATIC_ASSERT_MSG(sizeof(float) == sizeof(uint32_t),
|
||||
"boost::endian currently supports only sizeof(float) == 4;"
|
||||
" please report static_assert failure to the boost mailing list");
|
||||
return detail::std_endian_reverse(x);
|
||||
}
|
||||
|
||||
inline double endian_reverse(double x) BOOST_NOEXCEPT
|
||||
{
|
||||
BOOST_STATIC_ASSERT_MSG(sizeof(double) == sizeof(uint64_t),
|
||||
"boost::endian currently supports only sizeof(double) == 8;"
|
||||
" please report static_assert failure to the boost mailing list");
|
||||
return detail::std_endian_reverse(x);
|
||||
}
|
||||
|
||||
template <class EndianReversible >
|
||||
inline EndianReversible big_to_native(EndianReversible x) BOOST_NOEXCEPT
|
||||
{
|
||||
|
@ -24,5 +24,5 @@ project
|
||||
[ run endian_operations_test.cpp ]
|
||||
[ run endian_in_union_test.cpp ]
|
||||
[ run conversion_test.cpp ]
|
||||
[ run floating_point_test.cpp : : : <test-info>always_show_run_output ]
|
||||
# [ run floating_point_test.cpp : : : <test-info>always_show_run_output ]
|
||||
;
|
||||
|
@ -30,20 +30,6 @@ namespace
|
||||
void check_size()
|
||||
{
|
||||
|
||||
BOOST_TEST_EQ(sizeof(big_float32_buf_at), 4u);
|
||||
BOOST_TEST_EQ(sizeof(big_float64_buf_at), 8u);
|
||||
BOOST_TEST_EQ(sizeof(little_float32_buf_at), 4u);
|
||||
BOOST_TEST_EQ(sizeof(little_float64_buf_at), 8u);
|
||||
BOOST_TEST_EQ(sizeof(native_float32_buf_at), 4u);
|
||||
BOOST_TEST_EQ(sizeof(native_float64_buf_at), 8u);
|
||||
|
||||
BOOST_TEST_EQ(sizeof(big_float32_buf_t), 4u);
|
||||
BOOST_TEST_EQ(sizeof(big_float64_buf_t), 8u);
|
||||
BOOST_TEST_EQ(sizeof(little_float32_buf_t), 4u);
|
||||
BOOST_TEST_EQ(sizeof(little_float64_buf_t), 8u);
|
||||
BOOST_TEST_EQ(sizeof(native_float32_buf_t), 4u);
|
||||
BOOST_TEST_EQ(sizeof(native_float64_buf_t), 8u);
|
||||
|
||||
BOOST_TEST_EQ(sizeof(big_int8_buf_t), 1u);
|
||||
BOOST_TEST_EQ(sizeof(big_int16_buf_t), 2u);
|
||||
BOOST_TEST_EQ(sizeof(big_int24_buf_t), 3u);
|
||||
|
@ -88,43 +88,6 @@ namespace
|
||||
void little_value(uint64_t& x) {x = static_cast<uint64_t>(0xF1E2D3C444231201ULL);}
|
||||
# endif
|
||||
|
||||
const float float_value = -1.234F;
|
||||
const double double_value = -1.234567;
|
||||
|
||||
void native_value(float& x) {std::memcpy(&x, &float_value, sizeof(float));}
|
||||
void native_value(double& x) {memcpy(&x, &double_value, sizeof(double));}
|
||||
# ifdef BOOST_BIG_ENDIAN
|
||||
void big_value(float& x) {memcpy(&x, &float_value, sizeof(float));}
|
||||
void big_value(double& x) {memcpy(&x, &double_value, sizeof(double));}
|
||||
void little_value(float& x)
|
||||
{
|
||||
memcpy(&x, &float_value, sizeof(float));
|
||||
std::reverse(reinterpret_cast<char*>(&x),
|
||||
reinterpret_cast<char*>(&x)+sizeof(float));
|
||||
}
|
||||
void little_value(double& x)
|
||||
{
|
||||
memcpy(&x, &double_value, sizeof(double));
|
||||
std::reverse(reinterpret_cast<char*>(&x),
|
||||
reinterpret_cast<char*>(&x)+sizeof(double));
|
||||
}
|
||||
# else
|
||||
void big_value(float& x)
|
||||
{
|
||||
memcpy(&x, &float_value, sizeof(float));
|
||||
std::reverse(reinterpret_cast<char*>(&x),
|
||||
reinterpret_cast<char*>(&x)+sizeof(float));
|
||||
}
|
||||
void big_value(double& x)
|
||||
{
|
||||
memcpy(&x, &double_value, sizeof(double));
|
||||
std::reverse(reinterpret_cast<char*>(&x),
|
||||
reinterpret_cast<char*>(&x)+sizeof(double));
|
||||
}
|
||||
void little_value(float& x) {memcpy(&x, &float_value, sizeof(float));}
|
||||
void little_value(double& x) {memcpy(&x, &double_value, sizeof(double));}
|
||||
# endif
|
||||
|
||||
template <class T>
|
||||
void test()
|
||||
{
|
||||
@ -391,11 +354,6 @@ int cpp_main(int, char * [])
|
||||
cout << "uint64_t" << endl;
|
||||
test<uint64_t>();
|
||||
|
||||
cout << "float" << endl;
|
||||
test<float>();
|
||||
cout << "double" << endl;
|
||||
test<double>();
|
||||
|
||||
cout << "UDT 1" << endl;
|
||||
udt_test<user::UDT1>();
|
||||
|
||||
|
@ -57,9 +57,6 @@ template<> struct value_type<long> { typedef long type; };
|
||||
template<> struct value_type<unsigned long> { typedef unsigned long type; };
|
||||
template<> struct value_type<long long> { typedef long long type; };
|
||||
template<> struct value_type<unsigned long long> { typedef unsigned long long type; };
|
||||
template<> struct value_type<float> { typedef float type; };
|
||||
template<> struct value_type<double> { typedef double type; };
|
||||
template<> struct value_type<long double> { typedef long double type; };
|
||||
|
||||
template <class T1, class T2>
|
||||
struct default_construct
|
||||
|
@ -223,38 +223,6 @@ namespace
|
||||
little_uint32_at little_align_uint32;
|
||||
little_uint64_at little_align_uint64;
|
||||
|
||||
big_float32_at big_align_float32;
|
||||
big_float64_at big_align_float64;
|
||||
little_float32_at little_align_float32;
|
||||
little_float64_at little_align_float64;
|
||||
native_float32_at native_align_float32;
|
||||
native_float64_at native_align_float64;
|
||||
|
||||
VERIFY(big_align_float32.data() == reinterpret_cast<const char *>(&big_align_float32));
|
||||
VERIFY(big_align_float64.data() == reinterpret_cast<const char *>(&big_align_float64));
|
||||
|
||||
VERIFY(little_align_float32.data() == reinterpret_cast<const char *>(&little_align_float32));
|
||||
VERIFY(little_align_float64.data() == reinterpret_cast<const char *>(&little_align_float64));
|
||||
|
||||
VERIFY(native_align_float32.data() == reinterpret_cast<const char *>(&native_align_float32));
|
||||
VERIFY(native_align_float64.data() == reinterpret_cast<const char *>(&native_align_float64));
|
||||
|
||||
big_float32_t big_float32;
|
||||
big_float64_t big_float64;
|
||||
little_float32_t little_float32;
|
||||
little_float64_t little_float64;
|
||||
native_float32_t native_float32;
|
||||
native_float64_t native_float64;
|
||||
|
||||
VERIFY(big_float32.data() == reinterpret_cast<const char *>(&big_float32));
|
||||
VERIFY(big_float64.data() == reinterpret_cast<const char *>(&big_float64));
|
||||
|
||||
VERIFY(little_float32.data() == reinterpret_cast<const char *>(&little_float32));
|
||||
VERIFY(little_float64.data() == reinterpret_cast<const char *>(&little_float64));
|
||||
|
||||
VERIFY(native_float32.data() == reinterpret_cast<const char *>(&native_float32));
|
||||
VERIFY(native_float64.data() == reinterpret_cast<const char *>(&native_float64));
|
||||
|
||||
VERIFY(big_8.data() == reinterpret_cast<const char *>(&big_8));
|
||||
VERIFY(big_16.data() == reinterpret_cast<const char *>(&big_16));
|
||||
VERIFY(big_24.data() == reinterpret_cast<const char *>(&big_24));
|
||||
@ -334,20 +302,6 @@ namespace
|
||||
VERIFY( numeric_limits<signed char>::digits == 7 );
|
||||
VERIFY( numeric_limits<unsigned char>::digits == 8 );
|
||||
|
||||
VERIFY_SIZE(sizeof( big_float32_at ), 4 );
|
||||
VERIFY_SIZE(sizeof( big_float64_at ), 8 );
|
||||
VERIFY_SIZE(sizeof(little_float32_at), 4);
|
||||
VERIFY_SIZE(sizeof(little_float64_at), 8);
|
||||
VERIFY_SIZE(sizeof(native_float32_at), 4);
|
||||
VERIFY_SIZE(sizeof(native_float64_at), 8);
|
||||
|
||||
VERIFY_SIZE(sizeof( big_float32_t ), 4 );
|
||||
VERIFY_SIZE(sizeof( big_float64_t ), 8 );
|
||||
VERIFY_SIZE(sizeof(little_float32_t), 4);
|
||||
VERIFY_SIZE(sizeof(little_float64_t), 8);
|
||||
VERIFY_SIZE(sizeof(native_float32_t), 4);
|
||||
VERIFY_SIZE(sizeof(native_float64_t), 8);
|
||||
|
||||
VERIFY_SIZE( sizeof( big_int8_t ), 1 );
|
||||
VERIFY_SIZE( sizeof( big_int16_t ), 2 );
|
||||
VERIFY_SIZE( sizeof( big_int24_t ), 3 );
|
||||
@ -520,42 +474,6 @@ namespace
|
||||
native_uint64_t v31;
|
||||
};
|
||||
|
||||
struct big_float_struct
|
||||
{
|
||||
int16_t v0;
|
||||
big_float32_at v1;
|
||||
};
|
||||
|
||||
struct big_unaligned_float_struct
|
||||
{
|
||||
int16_t v0;
|
||||
big_float32_t v1;
|
||||
};
|
||||
|
||||
struct little_float_struct
|
||||
{
|
||||
int16_t v0;
|
||||
little_float32_at v1;
|
||||
};
|
||||
|
||||
struct little_unaligned_float_struct
|
||||
{
|
||||
int16_t v0;
|
||||
little_float32_t v1;
|
||||
};
|
||||
|
||||
struct native_float_struct
|
||||
{
|
||||
int16_t v0;
|
||||
native_float32_at v1;
|
||||
};
|
||||
|
||||
struct native_unaligned_float_struct
|
||||
{
|
||||
int16_t v0;
|
||||
native_float32_t v1;
|
||||
};
|
||||
|
||||
// aligned test cases
|
||||
|
||||
struct big_aligned_struct
|
||||
@ -586,12 +504,6 @@ namespace
|
||||
VERIFY_SIZE( sizeof(native_u_struct), 39 );
|
||||
VERIFY( sizeof(big_aligned_struct) <= 24 );
|
||||
VERIFY( sizeof(little_aligned_struct) <= 24 );
|
||||
VERIFY_SIZE(sizeof(big_float_struct), 8);
|
||||
VERIFY_SIZE(sizeof(big_unaligned_float_struct), 6);
|
||||
VERIFY_SIZE(sizeof(little_float_struct), 8);
|
||||
VERIFY_SIZE(sizeof(little_unaligned_float_struct), 6);
|
||||
VERIFY_SIZE(sizeof(native_float_struct), 8);
|
||||
VERIFY_SIZE(sizeof(native_unaligned_float_struct), 6);
|
||||
|
||||
if ( saved_err_count == err_count )
|
||||
{
|
||||
@ -604,86 +516,6 @@ namespace
|
||||
|
||||
void check_representation_and_range_and_ops()
|
||||
{
|
||||
// aligned floating point types
|
||||
float big_float32_expected = (std::numeric_limits<float>::max) ();
|
||||
boost::endian::native_to_big_inplace(big_float32_expected);
|
||||
big_float32_at big_float32((std::numeric_limits<float>::max) ());
|
||||
VERIFY(std::memcmp(big_float32.data(),
|
||||
reinterpret_cast<const char*>(&big_float32_expected), sizeof(float)) == 0);
|
||||
|
||||
float little_float32_expected = (std::numeric_limits<float>::max) ();
|
||||
boost::endian::native_to_little_inplace(little_float32_expected);
|
||||
little_float32_at little_float32((std::numeric_limits<float>::max) ());
|
||||
VERIFY(std::memcmp(little_float32.data(),
|
||||
reinterpret_cast<const char*>(&little_float32_expected), sizeof(float)) == 0);
|
||||
|
||||
double big_float64_expected = (std::numeric_limits<double>::max) ();
|
||||
boost::endian::native_to_big_inplace(big_float64_expected);
|
||||
big_float64_at big_float64((std::numeric_limits<double>::max) ());
|
||||
VERIFY(std::memcmp(big_float64.data(),
|
||||
reinterpret_cast<const char*>(&big_float64_expected), sizeof(double)) == 0);
|
||||
|
||||
double little_float64_expected = (std::numeric_limits<double>::max) ();
|
||||
boost::endian::native_to_little_inplace(little_float64_expected);
|
||||
little_float64_at little_float64((std::numeric_limits<double>::max) ());
|
||||
VERIFY(std::memcmp(little_float64.data(),
|
||||
reinterpret_cast<const char*>(&little_float64_expected), sizeof(double)) == 0);
|
||||
|
||||
VERIFY_VALUE_AND_OPS( big_float32_at, float, (std::numeric_limits<float>::max) () );
|
||||
VERIFY_VALUE_AND_OPS( big_float32_at, float, (std::numeric_limits<float>::min) () );
|
||||
VERIFY_VALUE_AND_OPS( big_float64_at, double, (std::numeric_limits<double>::max) () );
|
||||
VERIFY_VALUE_AND_OPS( big_float64_at, double, (std::numeric_limits<double>::min) () );
|
||||
|
||||
VERIFY_VALUE_AND_OPS( little_float32_at, float, (std::numeric_limits<float>::max) () );
|
||||
VERIFY_VALUE_AND_OPS( little_float32_at, float, (std::numeric_limits<float>::min) () );
|
||||
VERIFY_VALUE_AND_OPS( little_float64_at, double, (std::numeric_limits<double>::max) () );
|
||||
VERIFY_VALUE_AND_OPS( little_float64_at, double, (std::numeric_limits<double>::min) () );
|
||||
|
||||
// unaligned floating point types
|
||||
float big_float32un_expected = (std::numeric_limits<float>::max) ();
|
||||
boost::endian::native_to_big_inplace(big_float32un_expected);
|
||||
big_float32_t big_float32un((std::numeric_limits<float>::max) ());
|
||||
VERIFY(std::memcmp(big_float32un.data(),
|
||||
reinterpret_cast<const char*>(&big_float32un_expected), sizeof(float)) == 0);
|
||||
|
||||
float little_float32un_expected = (std::numeric_limits<float>::max) ();
|
||||
boost::endian::native_to_little_inplace(little_float32un_expected);
|
||||
little_float32_t little_float32un((std::numeric_limits<float>::max) ());
|
||||
VERIFY(std::memcmp(little_float32un.data(),
|
||||
reinterpret_cast<const char*>(&little_float32un_expected), sizeof(float)) == 0);
|
||||
|
||||
double big_float64un_expected = (std::numeric_limits<double>::max) ();
|
||||
boost::endian::native_to_big_inplace(big_float64un_expected);
|
||||
big_float64_t big_float64un((std::numeric_limits<double>::max) ());
|
||||
VERIFY(std::memcmp(big_float64un.data(),
|
||||
reinterpret_cast<const char*>(&big_float64un_expected), sizeof(double)) == 0);
|
||||
|
||||
double little_float64un_expected = (std::numeric_limits<double>::max) ();
|
||||
boost::endian::native_to_little_inplace(little_float64un_expected);
|
||||
little_float64_t little_float64un((std::numeric_limits<double>::max) ());
|
||||
VERIFY(std::memcmp(little_float64un.data(),
|
||||
reinterpret_cast<const char*>(&little_float64un_expected), sizeof(double)) == 0);
|
||||
|
||||
VERIFY_VALUE_AND_OPS( big_float32_t, float, (std::numeric_limits<float>::max) () );
|
||||
VERIFY_VALUE_AND_OPS( big_float32_t, float, (std::numeric_limits<float>::min) () );
|
||||
VERIFY_VALUE_AND_OPS( big_float64_t, double, (std::numeric_limits<double>::max) () );
|
||||
VERIFY_VALUE_AND_OPS( big_float64_t, double, (std::numeric_limits<double>::min) () );
|
||||
|
||||
VERIFY_VALUE_AND_OPS( little_float32_t, float, (std::numeric_limits<float>::max) () );
|
||||
VERIFY_VALUE_AND_OPS( little_float32_t, float, (std::numeric_limits<float>::min) () );
|
||||
VERIFY_VALUE_AND_OPS( little_float64_t, double, (std::numeric_limits<double>::max) () );
|
||||
VERIFY_VALUE_AND_OPS( little_float64_t, double, (std::numeric_limits<double>::min) () );
|
||||
|
||||
float a = 1.0F;
|
||||
big_float32_at b(1.0F);
|
||||
big_float32_t c(1.0F);
|
||||
little_float32_at d(1.0F);
|
||||
little_float32_t e(1.0F);
|
||||
VERIFY(a==b);
|
||||
VERIFY(a==c);
|
||||
VERIFY(a==d);
|
||||
VERIFY(a==e);
|
||||
|
||||
// unaligned integer types
|
||||
VERIFY_BIG_REPRESENTATION( big_int8_t );
|
||||
VERIFY_VALUE_AND_OPS( big_int8_t, int_least8_t, 0x7f );
|
||||
|
@ -1,325 +0,0 @@
|
||||
// floating_point_test.cpp -----------------------------------------------------------//
|
||||
|
||||
// Copyright Beman Dawes 2015
|
||||
|
||||
// Distributed under the Boost Software License, Version 1.0.
|
||||
// See http://www.boost.org/LICENSE_1_0.txt
|
||||
|
||||
// See library home page at http://www.boost.org/libs/endian
|
||||
|
||||
//--------------------------------------------------------------------------------------//
|
||||
|
||||
#include <boost/endian/detail/disable_warnings.hpp>
|
||||
|
||||
//#define BOOST_ENDIAN_LOG
|
||||
#include <boost/endian/conversion.hpp>
|
||||
#include <boost/detail/lightweight_main.hpp>
|
||||
#include <boost/endian/detail/lightweight_test.hpp>
|
||||
#include <boost/array.hpp>
|
||||
#include <boost/math/constants/constants.hpp>
|
||||
#include <iostream>
|
||||
#include <iomanip>
|
||||
#include <sstream>
|
||||
#include <algorithm>
|
||||
#include <limits>
|
||||
#include <cstring>
|
||||
|
||||
using namespace boost::endian;
|
||||
using std::cout;
|
||||
using std::endl;
|
||||
using std::hex;
|
||||
using std::dec;
|
||||
using std::numeric_limits;
|
||||
|
||||
|
||||
namespace
|
||||
{
|
||||
|
||||
// to_big() and to_little() provide convenient independent functions for
|
||||
// creating test values of known endianness.
|
||||
|
||||
template <class T>
|
||||
T to_big(T x)
|
||||
{
|
||||
# ifdef BOOST_LITTLE_ENDIAN
|
||||
std::reverse(reinterpret_cast<char*>(&x), reinterpret_cast<char*>(&x) + sizeof(T));
|
||||
# endif
|
||||
return x;
|
||||
}
|
||||
|
||||
template <class T>
|
||||
T to_little(T x)
|
||||
{
|
||||
# ifdef BOOST_BIG_ENDIAN
|
||||
std::reverse(reinterpret_cast<char*>(&x), reinterpret_cast<char*>(&x) + sizeof(T));
|
||||
# endif
|
||||
return x;
|
||||
}
|
||||
|
||||
template <class T>
|
||||
struct test_case
|
||||
{
|
||||
std::string desc;
|
||||
T value; // native value and representation
|
||||
std::string big; // as hex characters; invariant size() == 2*sizeof(T)
|
||||
std::string little; // as hex characters; invariant size() == 2*sizeof(T)
|
||||
// big and little endian expected values are held as strings so representation is
|
||||
// independent of platform endianness and readers do not have to perform mental
|
||||
// gymnastics to reason about what the expected representation is for a platform.
|
||||
|
||||
const test_case& assign(const std::string& desc_, const T& value_,
|
||||
const std::string& big_, const std::string& little_)
|
||||
{
|
||||
desc = desc_;
|
||||
std::memcpy(&value, &value_, sizeof(T)); // use memcpy in case copy assignment or
|
||||
// copy construction alters representation
|
||||
big = big_;
|
||||
little = little_;
|
||||
return *this;
|
||||
}
|
||||
};
|
||||
|
||||
// to_big_inplace() and to_little_inplace() provide convenient independent functions to
|
||||
// aid creating test values of known endianness. They do so in place to avoid the
|
||||
// possibility that floating point assignment or copy construction modifies the
|
||||
// representation, such as for normalization.
|
||||
|
||||
template <class T>
|
||||
void to_big_inplace(T& x)
|
||||
{
|
||||
# ifdef BOOST_LITTLE_ENDIAN
|
||||
std::reverse(reinterpret_cast<char*>(&x), reinterpret_cast<char*>(&x) + sizeof(T));
|
||||
# endif
|
||||
}
|
||||
|
||||
template <class T>
|
||||
void to_little_inplace(T& x)
|
||||
{
|
||||
# ifdef BOOST_BIG_ENDIAN
|
||||
std::reverse(reinterpret_cast<char*>(&x), reinterpret_cast<char*>(&x) + sizeof(T));
|
||||
# endif
|
||||
}
|
||||
|
||||
template <class T>
|
||||
std::string to_hex(const T& x)
|
||||
{
|
||||
const char hex[] = { '0','1','2','3','4','5','6','7','8','9','a','b','c','d','e','f' };
|
||||
std::string tmp;
|
||||
const unsigned char* p = reinterpret_cast<const unsigned char*>(&x);
|
||||
const unsigned char* e = p + sizeof(T);
|
||||
|
||||
for (; p < e; ++p)
|
||||
{
|
||||
tmp += hex[*p >> 4]; // high-order nibble
|
||||
tmp += hex[*p & 0x0f]; // low-order nibble
|
||||
}
|
||||
return tmp;
|
||||
}
|
||||
|
||||
#ifndef BOOST_NO_CXX11_NUMERIC_LIMITS
|
||||
const int n_test_cases = 15;
|
||||
#else
|
||||
const int n_test_cases = 14; // we do not test lowest() for C++0x std libs
|
||||
#endif
|
||||
boost::array<test_case<float>, n_test_cases> float_test_cases;
|
||||
boost::array<test_case<double>, n_test_cases> double_test_cases;
|
||||
|
||||
void build_auto_test_cases()
|
||||
{
|
||||
using namespace boost::math::constants;
|
||||
int i = 0;
|
||||
|
||||
// template for cut-and-paste of new values
|
||||
// float_test_cases[i].assign("", , "", "");
|
||||
// double_test_cases[i++].assign("", , "", "");
|
||||
|
||||
float_test_cases[i].assign("numeric_limits<float>::min()",
|
||||
numeric_limits<float>::min(), "00800000", "00008000");
|
||||
double_test_cases[i++].assign("numeric_limits<double>::min()",
|
||||
numeric_limits<double>::min(), "0010000000000000", "0000000000001000");
|
||||
|
||||
float_test_cases[i].assign("numeric_limits<float>::max()",
|
||||
numeric_limits<float>::max(), "7f7fffff", "ffff7f7f");
|
||||
double_test_cases[i++].assign("numeric_limits<double>::max()",
|
||||
numeric_limits<double>::max(), "7fefffffffffffff", "ffffffffffffef7f");
|
||||
|
||||
# ifndef BOOST_NO_CXX11_NUMERIC_LIMITS
|
||||
float_test_cases[i].assign("numeric_limits<float>::lowest()",
|
||||
numeric_limits<float>::lowest(), "ff7fffff", "ffff7fff");
|
||||
double_test_cases[i++].assign("numeric_limits<double>::lowest()",
|
||||
numeric_limits<double>::lowest(), "ffefffffffffffff", "ffffffffffffefff");
|
||||
# endif
|
||||
|
||||
float_test_cases[i].assign("numeric_limits<float>::epsilon()",
|
||||
numeric_limits<float>::epsilon(), "34000000", "00000034");
|
||||
double_test_cases[i++].assign("numeric_limits<double>::epsilon()",
|
||||
numeric_limits<double>::epsilon(), "3cb0000000000000", "000000000000b03c");
|
||||
|
||||
float_test_cases[i].assign("numeric_limits<float>::round_error()",
|
||||
numeric_limits<float>::round_error(), "3f000000", "0000003f");
|
||||
double_test_cases[i++].assign("numeric_limits<double>::round_error()",
|
||||
numeric_limits<double>::round_error(), "3fe0000000000000", "000000000000e03f");
|
||||
|
||||
float_test_cases[i].assign("numeric_limits<float>::infinity()",
|
||||
numeric_limits<float>::infinity(), "7f800000", "0000807f");
|
||||
double_test_cases[i++].assign("numeric_limits<double>::infinity()",
|
||||
numeric_limits<double>::infinity(), "7ff0000000000000", "000000000000f07f");
|
||||
|
||||
float_test_cases[i].assign("-numeric_limits<float>::infinity()",
|
||||
-numeric_limits<float>::infinity(), "ff800000", "000080ff");
|
||||
double_test_cases[i++].assign("-numeric_limits<double>::infinity()",
|
||||
-numeric_limits<double>::infinity(), "fff0000000000000", "000000000000f0ff");
|
||||
|
||||
float_test_cases[i].assign("numeric_limits<float>::quiet_NaN()",
|
||||
numeric_limits<float>::quiet_NaN(), "7fc00000", "0000c07f");
|
||||
double_test_cases[i++].assign("numeric_limits<double>::quiet_NaN()",
|
||||
numeric_limits<double>::quiet_NaN(), "7ff8000000000000", "000000000000f87f");
|
||||
|
||||
//float_test_cases[i].assign("numeric_limits<float>::signaling_NaN()",
|
||||
// numeric_limits<float>::signaling_NaN(), "7fc00001", "0100c07f");
|
||||
//double_test_cases[i++].assign("numeric_limits<double>::signaling_NaN()",
|
||||
// numeric_limits<double>::signaling_NaN(), "7ff8000000000001", "010000000000f87f");
|
||||
|
||||
float_test_cases[i].assign("numeric_limits<float>::denorm_min()",
|
||||
numeric_limits<float>::denorm_min(), "00000001", "01000000");
|
||||
double_test_cases[i++].assign("numeric_limits<double>::denorm_min()",
|
||||
numeric_limits<double>::denorm_min(), "0000000000000001", "0100000000000000");
|
||||
|
||||
float_test_cases[i].assign("0.0f", 0.0f, "00000000", "00000000");
|
||||
double_test_cases[i++].assign("0.0", 0.0, "0000000000000000", "0000000000000000");
|
||||
|
||||
float_test_cases[i].assign("-0.0f", -0.0f, "80000000", "00000080");
|
||||
double_test_cases[i++].assign("-0.0", -0.0, "8000000000000000", "0000000000000080");
|
||||
|
||||
float_test_cases[i].assign("1.0f", 1.0f, "3f800000", "0000803f");
|
||||
double_test_cases[i++].assign("1.0", 1.0, "3ff0000000000000", "000000000000f03f");
|
||||
|
||||
float_test_cases[i].assign("-1.0f", -1.0f, "bf800000", "000080bf");
|
||||
double_test_cases[i++].assign("-1.0", -1.0, "bff0000000000000", "000000000000f0bf");
|
||||
|
||||
uint32_t vf1 (0x12345678U);
|
||||
float_test_cases[i].assign("native uint32_t 0x12345678U as float",
|
||||
*reinterpret_cast<const float*>(&vf1), "12345678", "78563412");
|
||||
uint64_t vd1 (0x0123456789abcdefULL);
|
||||
double_test_cases[i++].assign("native uint64_t 0x0123456789abcdefULL as double",
|
||||
*reinterpret_cast<const double*>(&vd1), "0123456789abcdef", "efcdab8967452301");
|
||||
|
||||
float_test_cases[i].assign("pi<float>()",
|
||||
pi<float>(), "40490fdb", "db0f4940");
|
||||
double_test_cases[i++].assign("pi<double>()",
|
||||
pi<double>(), "400921fb54442d18", "182d4454fb210940");
|
||||
|
||||
BOOST_ASSERT(i == n_test_cases);
|
||||
}
|
||||
|
||||
|
||||
template <class T>
|
||||
void show_value(const char* desc, const T& value)
|
||||
{
|
||||
cout << " " << desc << " " << value
|
||||
<< ", native 0x" << to_hex(value)
|
||||
<< ", big 0x" << to_hex(native_to_big(value))
|
||||
<< ", little 0x" << to_hex(native_to_little(value)) << "\n";
|
||||
}
|
||||
|
||||
template <class T>
|
||||
void report_limits(const char* type)
|
||||
{
|
||||
using namespace boost::math::constants;
|
||||
cout << "\nHeader <limits> values for std::numeric_limits<" << type << ">\n\n";
|
||||
cout << " is_specialized " << numeric_limits<T>::is_specialized << "\n";
|
||||
cout << " is_signed " << numeric_limits<T>::is_signed << "\n";
|
||||
cout << " is_integer " << numeric_limits<T>::is_integer << "\n";
|
||||
cout << " is_exact " << numeric_limits<T>::is_exact << "\n";
|
||||
cout << " is_iec559 " << numeric_limits<T>::is_iec559 << "\n";
|
||||
cout << " is_bounded " << numeric_limits<T>::is_bounded << "\n";
|
||||
cout << " is_modulo " << numeric_limits<T>::is_modulo << "\n";
|
||||
cout << " traps " << numeric_limits<T>::traps << "\n";
|
||||
cout << " tinyness_before " << numeric_limits<T>::tinyness_before << "\n";
|
||||
cout << " round_style " << numeric_limits<T>::round_style << "\n";
|
||||
cout << " has_infinity " << numeric_limits<T>::has_infinity << "\n";
|
||||
cout << " has_quiet_NaN " << numeric_limits<T>::has_quiet_NaN << "\n";
|
||||
cout << " has_signaling_NaN " << numeric_limits<T>::has_signaling_NaN << "\n";
|
||||
cout << " has_denorm " << numeric_limits<T>::has_denorm << "\n";
|
||||
cout << " digits " << numeric_limits<T>::digits << "\n";
|
||||
cout << " digits10 " << numeric_limits<T>::digits10 << "\n";
|
||||
# ifndef BOOST_NO_CXX11_NUMERIC_LIMITS
|
||||
cout << " max_digits10 " << numeric_limits<T>::max_digits10 << "\n";
|
||||
# endif
|
||||
cout << " radix " << numeric_limits<T>::radix << "\n";
|
||||
cout << " min_exponent " << numeric_limits<T>::min_exponent << "\n";
|
||||
cout << " min_exponent10 " << numeric_limits<T>::min_exponent10 << "\n";
|
||||
cout << " max_exponent " << numeric_limits<T>::max_exponent << "\n";
|
||||
cout << " max_exponent10 " << numeric_limits<T>::max_exponent10 << "\n";
|
||||
show_value("min()", numeric_limits<T>::min());
|
||||
show_value("max()", numeric_limits<T>::max());
|
||||
# ifndef BOOST_NO_CXX11_NUMERIC_LIMITS
|
||||
show_value("lowest()", numeric_limits<T>::lowest());
|
||||
# endif
|
||||
show_value("epsilon()", numeric_limits<T>::epsilon());
|
||||
show_value("round_error()", numeric_limits<T>::round_error());
|
||||
show_value("infinity()", numeric_limits<T>::infinity());
|
||||
show_value("-infinity()", -numeric_limits<T>::infinity());
|
||||
show_value("quiet_NaN()", numeric_limits<T>::quiet_NaN());
|
||||
show_value("signaling_NaN()", numeric_limits<T>::signaling_NaN());
|
||||
show_value("denorm_min()", numeric_limits<T>::denorm_min());
|
||||
show_value("0.0", static_cast<T>(0.0));
|
||||
show_value("-0.0", static_cast<T>(-0.0));
|
||||
show_value("1.0", static_cast<T>(1.0));
|
||||
show_value("-1.0", static_cast<T>(-1.0));
|
||||
show_value("pi()", pi<T>());
|
||||
}
|
||||
|
||||
template <class T>
|
||||
void auto_test(const char* msg, const boost::array<test_case<T>, n_test_cases>& cases)
|
||||
{
|
||||
cout << "auto test " << msg << " ..." << endl;
|
||||
|
||||
for (int i = 0; i < n_test_cases; ++i)
|
||||
{
|
||||
cout << " " << cases[i].desc << endl;
|
||||
BOOST_TEST_EQ(to_hex(native_to_big(cases[i].value)), cases[i].big);
|
||||
BOOST_TEST_EQ(to_hex(native_to_little(cases[i].value)), cases[i].little);
|
||||
BOOST_TEST_MEM_EQ(endian_reverse(endian_reverse(cases[i].value)), cases[i].value);
|
||||
}
|
||||
}
|
||||
|
||||
} // unnamed namespace
|
||||
|
||||
//--------------------------------------------------------------------------------------//
|
||||
|
||||
int cpp_main(int, char *[])
|
||||
{
|
||||
#ifdef BOOST_BIG_ENDIAN
|
||||
cout << "platform is big endian\n";
|
||||
#else
|
||||
cout << "platform is little endian\n";
|
||||
#endif
|
||||
cout << "byte swap intrinsics: " BOOST_ENDIAN_INTRINSIC_MSG << endl;
|
||||
|
||||
#ifdef BOOST_NO_CXX11_NUMERIC_LIMITS
|
||||
cout << "BOOST_NO_CXX11_NUMERIC_LIMITS is defined" << endl;
|
||||
#endif
|
||||
|
||||
|
||||
//#define BOOST_ENDIAN_FORCE_ERROR
|
||||
#ifdef BOOST_ENDIAN_FORCE_ERROR
|
||||
BOOST_TEST_MEM_EQ(1.0f, 1.0);
|
||||
BOOST_TEST_MEM_EQ(1.0f, 1.1f);
|
||||
BOOST_TEST_MEM_EQ(1.0, 1.1);
|
||||
#endif
|
||||
|
||||
build_auto_test_cases();
|
||||
|
||||
report_limits<float>("float");
|
||||
auto_test<float>("float", float_test_cases);
|
||||
|
||||
report_limits<double>("double");
|
||||
auto_test<double>("double", double_test_cases);
|
||||
|
||||
cout << "\n done" << endl;
|
||||
|
||||
return ::boost::endian::report_errors();
|
||||
}
|
||||
|
||||
#include <boost/endian/detail/disable_warnings_pop.hpp>
|
@ -1,86 +0,0 @@
|
||||
// fp_exhaustive_test.cpp ------------------------------------------------------------//
|
||||
|
||||
// Copyright Beman Dawes 2015
|
||||
|
||||
// Distributed under the Boost Software License, Version 1.0.
|
||||
// See http://www.boost.org/LICENSE_1_0.txt
|
||||
|
||||
// See library home page at http://www.boost.org/libs/endian
|
||||
|
||||
//--------------------------------------------------------------------------------------//
|
||||
|
||||
#include <boost/endian/detail/disable_warnings.hpp>
|
||||
|
||||
//#define BOOST_ENDIAN_LOG
|
||||
#include <boost/endian/conversion.hpp>
|
||||
#include <boost/detail/lightweight_main.hpp>
|
||||
#include <boost/endian/detail/lightweight_test.hpp>
|
||||
#include <iostream>
|
||||
#include <iomanip>
|
||||
#include <sstream>
|
||||
#include <algorithm>
|
||||
#include <limits>
|
||||
#include <climits>
|
||||
#include <cstring>
|
||||
|
||||
using namespace boost::endian;
|
||||
using std::cout;
|
||||
using std::endl;
|
||||
using std::hex;
|
||||
using std::dec;
|
||||
using std::numeric_limits;
|
||||
|
||||
|
||||
namespace
|
||||
{
|
||||
} // unnamed namespace
|
||||
|
||||
//--------------------------------------------------------------------------------------//
|
||||
|
||||
int cpp_main(int, char *[])
|
||||
{
|
||||
#ifdef BOOST_BIG_ENDIAN
|
||||
cout << "platform is big endian\n";
|
||||
#else
|
||||
cout << "platform is little endian\n";
|
||||
#endif
|
||||
cout << "byte swap intrinsics: " BOOST_ENDIAN_INTRINSIC_MSG << endl;
|
||||
|
||||
#ifdef BOOST_NO_CXX11_NUMERIC_LIMITS
|
||||
cout << "BOOST_NO_CXX11_NUMERIC_LIMITS is defined" << endl;
|
||||
#endif
|
||||
|
||||
cout << "Iterations: " << endl;
|
||||
|
||||
uint32_t i = 0;
|
||||
do
|
||||
{
|
||||
if (i % 1000000 == 0)
|
||||
cout << i << endl;
|
||||
|
||||
float x = *reinterpret_cast<const float*>(&i);
|
||||
float rtx = endian_reverse(endian_reverse(x));
|
||||
if (!BOOST_TEST_MEM_EQ(x, rtx))
|
||||
{
|
||||
float erx = endian_reverse(x);
|
||||
cout << "i = 0X" << detail::to_hex(i) << "\n";
|
||||
cout << "x = 0X" << detail::to_hex(x) << "\n";
|
||||
cout << "erx = 0X" << detail::to_hex(erx) << "\n";
|
||||
cout << "rtx = 0X" << detail::to_hex(rtx) << "\n";
|
||||
//cout << "i = " << i << " [0X" << hex << i << dec << "], or "
|
||||
// << *reinterpret_cast<const float*>(&i) << " as float\n"
|
||||
// "but endian_reverse(endian_reverse()) round-trip yields "
|
||||
// << endian_reverse(endian_reverse(*reinterpret_cast<const float*>(&i))) << "\n"
|
||||
// ;
|
||||
// erx = endian_reverse(x);
|
||||
break;
|
||||
}
|
||||
++i;
|
||||
} while (i != 0);
|
||||
|
||||
cout << "\n done" << endl;
|
||||
|
||||
return ::boost::endian::report_errors();
|
||||
}
|
||||
|
||||
#include <boost/endian/detail/disable_warnings_pop.hpp>
|
@ -33,10 +33,6 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "experiment", "experiment\ex
|
||||
EndProject
|
||||
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "deprecated_test", "deprecated_test\deprecated_test.vcxproj", "{DA4BC67F-9284-4D2C-81D5-407312C31BD7}"
|
||||
EndProject
|
||||
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "floating_point_test", "floating_point_test\floating_point_test.vcxproj", "{27E8FDC5-9669-4940-B24F-94B21FFEE649}"
|
||||
EndProject
|
||||
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "fp_exhaustive_test", "fp_exhaustive_test\fp_exhaustive_test.vcxproj", "{E19A89FE-D728-4705-A060-B85E7239984C}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|Win32 = Debug|Win32
|
||||
@ -157,18 +153,6 @@ Global
|
||||
{DA4BC67F-9284-4D2C-81D5-407312C31BD7}.Release|Win32.ActiveCfg = Release|Win32
|
||||
{DA4BC67F-9284-4D2C-81D5-407312C31BD7}.Release|Win32.Build.0 = Release|Win32
|
||||
{DA4BC67F-9284-4D2C-81D5-407312C31BD7}.Release|x64.ActiveCfg = Release|Win32
|
||||
{27E8FDC5-9669-4940-B24F-94B21FFEE649}.Debug|Win32.ActiveCfg = Debug|Win32
|
||||
{27E8FDC5-9669-4940-B24F-94B21FFEE649}.Debug|Win32.Build.0 = Debug|Win32
|
||||
{27E8FDC5-9669-4940-B24F-94B21FFEE649}.Debug|x64.ActiveCfg = Debug|Win32
|
||||
{27E8FDC5-9669-4940-B24F-94B21FFEE649}.Release|Win32.ActiveCfg = Release|Win32
|
||||
{27E8FDC5-9669-4940-B24F-94B21FFEE649}.Release|Win32.Build.0 = Release|Win32
|
||||
{27E8FDC5-9669-4940-B24F-94B21FFEE649}.Release|x64.ActiveCfg = Release|Win32
|
||||
{E19A89FE-D728-4705-A060-B85E7239984C}.Debug|Win32.ActiveCfg = Debug|Win32
|
||||
{E19A89FE-D728-4705-A060-B85E7239984C}.Debug|Win32.Build.0 = Debug|Win32
|
||||
{E19A89FE-D728-4705-A060-B85E7239984C}.Debug|x64.ActiveCfg = Debug|Win32
|
||||
{E19A89FE-D728-4705-A060-B85E7239984C}.Release|Win32.ActiveCfg = Release|Win32
|
||||
{E19A89FE-D728-4705-A060-B85E7239984C}.Release|Win32.Build.0 = Release|Win32
|
||||
{E19A89FE-D728-4705-A060-B85E7239984C}.Release|x64.ActiveCfg = Release|Win32
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
|
@ -1,89 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project DefaultTargets="Build" ToolsVersion="14.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<ItemGroup Label="ProjectConfigurations">
|
||||
<ProjectConfiguration Include="Debug|Win32">
|
||||
<Configuration>Debug</Configuration>
|
||||
<Platform>Win32</Platform>
|
||||
</ProjectConfiguration>
|
||||
<ProjectConfiguration Include="Release|Win32">
|
||||
<Configuration>Release</Configuration>
|
||||
<Platform>Win32</Platform>
|
||||
</ProjectConfiguration>
|
||||
</ItemGroup>
|
||||
<PropertyGroup Label="Globals">
|
||||
<ProjectGuid>{27E8FDC5-9669-4940-B24F-94B21FFEE649}</ProjectGuid>
|
||||
<Keyword>Win32Proj</Keyword>
|
||||
<RootNamespace>float_test</RootNamespace>
|
||||
<ProjectName>floating_point_test</ProjectName>
|
||||
</PropertyGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
|
||||
<ConfigurationType>Application</ConfigurationType>
|
||||
<UseDebugLibraries>true</UseDebugLibraries>
|
||||
<PlatformToolset>v140</PlatformToolset>
|
||||
<CharacterSet>Unicode</CharacterSet>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
|
||||
<ConfigurationType>Application</ConfigurationType>
|
||||
<UseDebugLibraries>false</UseDebugLibraries>
|
||||
<PlatformToolset>v140</PlatformToolset>
|
||||
<WholeProgramOptimization>true</WholeProgramOptimization>
|
||||
<CharacterSet>Unicode</CharacterSet>
|
||||
</PropertyGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
|
||||
<ImportGroup Label="ExtensionSettings">
|
||||
</ImportGroup>
|
||||
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
<Import Project="..\common.props" />
|
||||
</ImportGroup>
|
||||
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
<Import Project="..\common.props" />
|
||||
</ImportGroup>
|
||||
<PropertyGroup Label="UserMacros" />
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
|
||||
<LinkIncremental>true</LinkIncremental>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
||||
<LinkIncremental>false</LinkIncremental>
|
||||
</PropertyGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
|
||||
<ClCompile>
|
||||
<PrecompiledHeader>
|
||||
</PrecompiledHeader>
|
||||
<WarningLevel>Level3</WarningLevel>
|
||||
<Optimization>Disabled</Optimization>
|
||||
<PreprocessorDefinitions>WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<SDLCheck>true</SDLCheck>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<SubSystem>Console</SubSystem>
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
||||
<ClCompile>
|
||||
<WarningLevel>Level3</WarningLevel>
|
||||
<PrecompiledHeader>
|
||||
</PrecompiledHeader>
|
||||
<Optimization>MaxSpeed</Optimization>
|
||||
<FunctionLevelLinking>true</FunctionLevelLinking>
|
||||
<IntrinsicFunctions>true</IntrinsicFunctions>
|
||||
<PreprocessorDefinitions>WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<SDLCheck>true</SDLCheck>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<SubSystem>Console</SubSystem>
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
<EnableCOMDATFolding>true</EnableCOMDATFolding>
|
||||
<OptimizeReferences>true</OptimizeReferences>
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="..\..\floating_point_test.cpp" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
|
||||
<ImportGroup Label="ExtensionTargets">
|
||||
</ImportGroup>
|
||||
</Project>
|
@ -1,96 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project DefaultTargets="Build" ToolsVersion="14.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<ItemGroup Label="ProjectConfigurations">
|
||||
<ProjectConfiguration Include="Debug|Win32">
|
||||
<Configuration>Debug</Configuration>
|
||||
<Platform>Win32</Platform>
|
||||
</ProjectConfiguration>
|
||||
<ProjectConfiguration Include="Release|Win32">
|
||||
<Configuration>Release</Configuration>
|
||||
<Platform>Win32</Platform>
|
||||
</ProjectConfiguration>
|
||||
</ItemGroup>
|
||||
<PropertyGroup Label="Globals">
|
||||
<ProjectGuid>{E19A89FE-D728-4705-A060-B85E7239984C}</ProjectGuid>
|
||||
<Keyword>Win32Proj</Keyword>
|
||||
<RootNamespace>fp_exhaustive_test</RootNamespace>
|
||||
</PropertyGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
|
||||
<ConfigurationType>Application</ConfigurationType>
|
||||
<UseDebugLibraries>true</UseDebugLibraries>
|
||||
<PlatformToolset>v140</PlatformToolset>
|
||||
<CharacterSet>Unicode</CharacterSet>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
|
||||
<ConfigurationType>Application</ConfigurationType>
|
||||
<UseDebugLibraries>false</UseDebugLibraries>
|
||||
<PlatformToolset>v140</PlatformToolset>
|
||||
<WholeProgramOptimization>true</WholeProgramOptimization>
|
||||
<CharacterSet>Unicode</CharacterSet>
|
||||
</PropertyGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
|
||||
<ImportGroup Label="ExtensionSettings">
|
||||
</ImportGroup>
|
||||
<ImportGroup Label="Shared">
|
||||
</ImportGroup>
|
||||
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
<Import Project="..\common.props" />
|
||||
</ImportGroup>
|
||||
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
<Import Project="..\common.props" />
|
||||
</ImportGroup>
|
||||
<PropertyGroup Label="UserMacros" />
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
|
||||
<LinkIncremental>true</LinkIncremental>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
||||
<LinkIncremental>false</LinkIncremental>
|
||||
</PropertyGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
|
||||
<ClCompile>
|
||||
<PrecompiledHeader>
|
||||
</PrecompiledHeader>
|
||||
<WarningLevel>Level3</WarningLevel>
|
||||
<Optimization>Disabled</Optimization>
|
||||
<PreprocessorDefinitions>WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<SDLCheck>true</SDLCheck>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<SubSystem>Console</SubSystem>
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
</Link>
|
||||
<PostBuildEvent>
|
||||
<Command />
|
||||
</PostBuildEvent>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
||||
<ClCompile>
|
||||
<WarningLevel>Level3</WarningLevel>
|
||||
<PrecompiledHeader>
|
||||
</PrecompiledHeader>
|
||||
<Optimization>MaxSpeed</Optimization>
|
||||
<FunctionLevelLinking>true</FunctionLevelLinking>
|
||||
<IntrinsicFunctions>true</IntrinsicFunctions>
|
||||
<PreprocessorDefinitions>WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<SDLCheck>true</SDLCheck>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<SubSystem>Console</SubSystem>
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
<EnableCOMDATFolding>true</EnableCOMDATFolding>
|
||||
<OptimizeReferences>true</OptimizeReferences>
|
||||
</Link>
|
||||
<PostBuildEvent>
|
||||
<Command />
|
||||
</PostBuildEvent>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="..\..\fp_exhaustive_test.cpp" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
|
||||
<ImportGroup Label="ExtensionTargets">
|
||||
</ImportGroup>
|
||||
</Project>
|
Reference in New Issue
Block a user