diff --git a/example/udt_conversion_example.cpp b/example/udt_conversion_example.cpp index 5ac85ac..b0a6d08 100644 --- a/example/udt_conversion_example.cpp +++ b/example/udt_conversion_example.cpp @@ -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; diff --git a/include/boost/endian/arithmetic.hpp b/include/boost/endian/arithmetic.hpp index cb0168d..d8bcbe6 100644 --- a/include/boost/endian/arithmetic.hpp +++ b/include/boost/endian/arithmetic.hpp @@ -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 big_float32_at; - typedef endian_arithmetic big_float64_at; - - // little endian floating point aligned types - typedef endian_arithmetic little_float32_at; - typedef endian_arithmetic little_float64_at; - - // big endian floating point unaligned types - typedef endian_arithmetic big_float32_t; - typedef endian_arithmetic big_float64_t; - - // little endian floating point unaligned types - typedef endian_arithmetic little_float32_t; - typedef endian_arithmetic little_float64_t; - // big endian signed integer aligned types typedef endian_arithmetic big_int8_at; typedef endian_arithmetic 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(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 diff --git a/include/boost/endian/buffers.hpp b/include/boost/endian/buffers.hpp index b8cf003..572d3bf 100644 --- a/include/boost/endian/buffers.hpp +++ b/include/boost/endian/buffers.hpp @@ -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 big_float32_buf_at; - typedef endian_buffer big_float64_buf_at; - - // aligned little endian floating point buffers - typedef endian_buffer little_float32_buf_at; - typedef endian_buffer little_float64_buf_at; - - // unaligned big endian floating point buffers - typedef endian_buffer big_float32_buf_t; - typedef endian_buffer big_float64_buf_t; - - // unaligned little endian floating point buffers - typedef endian_buffer little_float32_buf_t; - typedef endian_buffer little_float64_buf_t; - // aligned big endian signed integer buffers typedef endian_buffer big_int8_buf_at; typedef endian_buffer 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 diff --git a/include/boost/endian/conversion.hpp b/include/boost/endian/conversion.hpp index 73e9f34..1d89596 100644 --- a/include/boost/endian/conversion.hpp +++ b/include/boost/endian/conversion.hpp @@ -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 @@ -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 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 inline EndianReversible big_to_native(EndianReversible x) BOOST_NOEXCEPT { diff --git a/test/Jamfile.v2 b/test/Jamfile.v2 index efb3f74..16d796a 100644 --- a/test/Jamfile.v2 +++ b/test/Jamfile.v2 @@ -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 : : : always_show_run_output ] +# [ run floating_point_test.cpp : : : always_show_run_output ] ; diff --git a/test/buffer_test.cpp b/test/buffer_test.cpp index 5f4342c..c9742be 100644 --- a/test/buffer_test.cpp +++ b/test/buffer_test.cpp @@ -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); diff --git a/test/conversion_test.cpp b/test/conversion_test.cpp index ada5929..632bc79 100644 --- a/test/conversion_test.cpp +++ b/test/conversion_test.cpp @@ -88,43 +88,6 @@ namespace void little_value(uint64_t& x) {x = static_cast(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(&x), - reinterpret_cast(&x)+sizeof(float)); - } - void little_value(double& x) - { - memcpy(&x, &double_value, sizeof(double)); - std::reverse(reinterpret_cast(&x), - reinterpret_cast(&x)+sizeof(double)); - } -# else - void big_value(float& x) - { - memcpy(&x, &float_value, sizeof(float)); - std::reverse(reinterpret_cast(&x), - reinterpret_cast(&x)+sizeof(float)); - } - void big_value(double& x) - { - memcpy(&x, &double_value, sizeof(double)); - std::reverse(reinterpret_cast(&x), - reinterpret_cast(&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 void test() { @@ -391,11 +354,6 @@ int cpp_main(int, char * []) cout << "uint64_t" << endl; test(); - cout << "float" << endl; - test(); - cout << "double" << endl; - test(); - cout << "UDT 1" << endl; udt_test(); diff --git a/test/endian_operations_test.cpp b/test/endian_operations_test.cpp index 0ee8fbc..cdd0872 100644 --- a/test/endian_operations_test.cpp +++ b/test/endian_operations_test.cpp @@ -57,9 +57,6 @@ template<> struct value_type { typedef long type; }; template<> struct value_type { typedef unsigned long type; }; template<> struct value_type { typedef long long type; }; template<> struct value_type { typedef unsigned long long type; }; -template<> struct value_type { typedef float type; }; -template<> struct value_type { typedef double type; }; -template<> struct value_type { typedef long double type; }; template struct default_construct diff --git a/test/endian_test.cpp b/test/endian_test.cpp index d78a061..82f2092 100644 --- a/test/endian_test.cpp +++ b/test/endian_test.cpp @@ -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(&big_align_float32)); - VERIFY(big_align_float64.data() == reinterpret_cast(&big_align_float64)); - - VERIFY(little_align_float32.data() == reinterpret_cast(&little_align_float32)); - VERIFY(little_align_float64.data() == reinterpret_cast(&little_align_float64)); - - VERIFY(native_align_float32.data() == reinterpret_cast(&native_align_float32)); - VERIFY(native_align_float64.data() == reinterpret_cast(&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(&big_float32)); - VERIFY(big_float64.data() == reinterpret_cast(&big_float64)); - - VERIFY(little_float32.data() == reinterpret_cast(&little_float32)); - VERIFY(little_float64.data() == reinterpret_cast(&little_float64)); - - VERIFY(native_float32.data() == reinterpret_cast(&native_float32)); - VERIFY(native_float64.data() == reinterpret_cast(&native_float64)); - VERIFY(big_8.data() == reinterpret_cast(&big_8)); VERIFY(big_16.data() == reinterpret_cast(&big_16)); VERIFY(big_24.data() == reinterpret_cast(&big_24)); @@ -334,20 +302,6 @@ namespace VERIFY( numeric_limits::digits == 7 ); VERIFY( numeric_limits::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::max) (); - boost::endian::native_to_big_inplace(big_float32_expected); - big_float32_at big_float32((std::numeric_limits::max) ()); - VERIFY(std::memcmp(big_float32.data(), - reinterpret_cast(&big_float32_expected), sizeof(float)) == 0); - - float little_float32_expected = (std::numeric_limits::max) (); - boost::endian::native_to_little_inplace(little_float32_expected); - little_float32_at little_float32((std::numeric_limits::max) ()); - VERIFY(std::memcmp(little_float32.data(), - reinterpret_cast(&little_float32_expected), sizeof(float)) == 0); - - double big_float64_expected = (std::numeric_limits::max) (); - boost::endian::native_to_big_inplace(big_float64_expected); - big_float64_at big_float64((std::numeric_limits::max) ()); - VERIFY(std::memcmp(big_float64.data(), - reinterpret_cast(&big_float64_expected), sizeof(double)) == 0); - - double little_float64_expected = (std::numeric_limits::max) (); - boost::endian::native_to_little_inplace(little_float64_expected); - little_float64_at little_float64((std::numeric_limits::max) ()); - VERIFY(std::memcmp(little_float64.data(), - reinterpret_cast(&little_float64_expected), sizeof(double)) == 0); - - VERIFY_VALUE_AND_OPS( big_float32_at, float, (std::numeric_limits::max) () ); - VERIFY_VALUE_AND_OPS( big_float32_at, float, (std::numeric_limits::min) () ); - VERIFY_VALUE_AND_OPS( big_float64_at, double, (std::numeric_limits::max) () ); - VERIFY_VALUE_AND_OPS( big_float64_at, double, (std::numeric_limits::min) () ); - - VERIFY_VALUE_AND_OPS( little_float32_at, float, (std::numeric_limits::max) () ); - VERIFY_VALUE_AND_OPS( little_float32_at, float, (std::numeric_limits::min) () ); - VERIFY_VALUE_AND_OPS( little_float64_at, double, (std::numeric_limits::max) () ); - VERIFY_VALUE_AND_OPS( little_float64_at, double, (std::numeric_limits::min) () ); - - // unaligned floating point types - float big_float32un_expected = (std::numeric_limits::max) (); - boost::endian::native_to_big_inplace(big_float32un_expected); - big_float32_t big_float32un((std::numeric_limits::max) ()); - VERIFY(std::memcmp(big_float32un.data(), - reinterpret_cast(&big_float32un_expected), sizeof(float)) == 0); - - float little_float32un_expected = (std::numeric_limits::max) (); - boost::endian::native_to_little_inplace(little_float32un_expected); - little_float32_t little_float32un((std::numeric_limits::max) ()); - VERIFY(std::memcmp(little_float32un.data(), - reinterpret_cast(&little_float32un_expected), sizeof(float)) == 0); - - double big_float64un_expected = (std::numeric_limits::max) (); - boost::endian::native_to_big_inplace(big_float64un_expected); - big_float64_t big_float64un((std::numeric_limits::max) ()); - VERIFY(std::memcmp(big_float64un.data(), - reinterpret_cast(&big_float64un_expected), sizeof(double)) == 0); - - double little_float64un_expected = (std::numeric_limits::max) (); - boost::endian::native_to_little_inplace(little_float64un_expected); - little_float64_t little_float64un((std::numeric_limits::max) ()); - VERIFY(std::memcmp(little_float64un.data(), - reinterpret_cast(&little_float64un_expected), sizeof(double)) == 0); - - VERIFY_VALUE_AND_OPS( big_float32_t, float, (std::numeric_limits::max) () ); - VERIFY_VALUE_AND_OPS( big_float32_t, float, (std::numeric_limits::min) () ); - VERIFY_VALUE_AND_OPS( big_float64_t, double, (std::numeric_limits::max) () ); - VERIFY_VALUE_AND_OPS( big_float64_t, double, (std::numeric_limits::min) () ); - - VERIFY_VALUE_AND_OPS( little_float32_t, float, (std::numeric_limits::max) () ); - VERIFY_VALUE_AND_OPS( little_float32_t, float, (std::numeric_limits::min) () ); - VERIFY_VALUE_AND_OPS( little_float64_t, double, (std::numeric_limits::max) () ); - VERIFY_VALUE_AND_OPS( little_float64_t, double, (std::numeric_limits::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 ); diff --git a/test/floating_point_test.cpp b/test/floating_point_test.cpp deleted file mode 100644 index 917a16e..0000000 --- a/test/floating_point_test.cpp +++ /dev/null @@ -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 - -//#define BOOST_ENDIAN_LOG -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -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 - T to_big(T x) - { -# ifdef BOOST_LITTLE_ENDIAN - std::reverse(reinterpret_cast(&x), reinterpret_cast(&x) + sizeof(T)); -# endif - return x; - } - - template - T to_little(T x) - { -# ifdef BOOST_BIG_ENDIAN - std::reverse(reinterpret_cast(&x), reinterpret_cast(&x) + sizeof(T)); -# endif - return x; - } - - template - 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 - void to_big_inplace(T& x) - { -# ifdef BOOST_LITTLE_ENDIAN - std::reverse(reinterpret_cast(&x), reinterpret_cast(&x) + sizeof(T)); -# endif - } - - template - void to_little_inplace(T& x) - { -# ifdef BOOST_BIG_ENDIAN - std::reverse(reinterpret_cast(&x), reinterpret_cast(&x) + sizeof(T)); -# endif - } - - template - 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(&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, n_test_cases> float_test_cases; - boost::array, 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::min()", - numeric_limits::min(), "00800000", "00008000"); - double_test_cases[i++].assign("numeric_limits::min()", - numeric_limits::min(), "0010000000000000", "0000000000001000"); - - float_test_cases[i].assign("numeric_limits::max()", - numeric_limits::max(), "7f7fffff", "ffff7f7f"); - double_test_cases[i++].assign("numeric_limits::max()", - numeric_limits::max(), "7fefffffffffffff", "ffffffffffffef7f"); - -# ifndef BOOST_NO_CXX11_NUMERIC_LIMITS - float_test_cases[i].assign("numeric_limits::lowest()", - numeric_limits::lowest(), "ff7fffff", "ffff7fff"); - double_test_cases[i++].assign("numeric_limits::lowest()", - numeric_limits::lowest(), "ffefffffffffffff", "ffffffffffffefff"); -# endif - - float_test_cases[i].assign("numeric_limits::epsilon()", - numeric_limits::epsilon(), "34000000", "00000034"); - double_test_cases[i++].assign("numeric_limits::epsilon()", - numeric_limits::epsilon(), "3cb0000000000000", "000000000000b03c"); - - float_test_cases[i].assign("numeric_limits::round_error()", - numeric_limits::round_error(), "3f000000", "0000003f"); - double_test_cases[i++].assign("numeric_limits::round_error()", - numeric_limits::round_error(), "3fe0000000000000", "000000000000e03f"); - - float_test_cases[i].assign("numeric_limits::infinity()", - numeric_limits::infinity(), "7f800000", "0000807f"); - double_test_cases[i++].assign("numeric_limits::infinity()", - numeric_limits::infinity(), "7ff0000000000000", "000000000000f07f"); - - float_test_cases[i].assign("-numeric_limits::infinity()", - -numeric_limits::infinity(), "ff800000", "000080ff"); - double_test_cases[i++].assign("-numeric_limits::infinity()", - -numeric_limits::infinity(), "fff0000000000000", "000000000000f0ff"); - - float_test_cases[i].assign("numeric_limits::quiet_NaN()", - numeric_limits::quiet_NaN(), "7fc00000", "0000c07f"); - double_test_cases[i++].assign("numeric_limits::quiet_NaN()", - numeric_limits::quiet_NaN(), "7ff8000000000000", "000000000000f87f"); - - //float_test_cases[i].assign("numeric_limits::signaling_NaN()", - // numeric_limits::signaling_NaN(), "7fc00001", "0100c07f"); - //double_test_cases[i++].assign("numeric_limits::signaling_NaN()", - // numeric_limits::signaling_NaN(), "7ff8000000000001", "010000000000f87f"); - - float_test_cases[i].assign("numeric_limits::denorm_min()", - numeric_limits::denorm_min(), "00000001", "01000000"); - double_test_cases[i++].assign("numeric_limits::denorm_min()", - numeric_limits::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(&vf1), "12345678", "78563412"); - uint64_t vd1 (0x0123456789abcdefULL); - double_test_cases[i++].assign("native uint64_t 0x0123456789abcdefULL as double", - *reinterpret_cast(&vd1), "0123456789abcdef", "efcdab8967452301"); - - float_test_cases[i].assign("pi()", - pi(), "40490fdb", "db0f4940"); - double_test_cases[i++].assign("pi()", - pi(), "400921fb54442d18", "182d4454fb210940"); - - BOOST_ASSERT(i == n_test_cases); - } - - - template - 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 - void report_limits(const char* type) - { - using namespace boost::math::constants; - cout << "\nHeader values for std::numeric_limits<" << type << ">\n\n"; - cout << " is_specialized " << numeric_limits::is_specialized << "\n"; - cout << " is_signed " << numeric_limits::is_signed << "\n"; - cout << " is_integer " << numeric_limits::is_integer << "\n"; - cout << " is_exact " << numeric_limits::is_exact << "\n"; - cout << " is_iec559 " << numeric_limits::is_iec559 << "\n"; - cout << " is_bounded " << numeric_limits::is_bounded << "\n"; - cout << " is_modulo " << numeric_limits::is_modulo << "\n"; - cout << " traps " << numeric_limits::traps << "\n"; - cout << " tinyness_before " << numeric_limits::tinyness_before << "\n"; - cout << " round_style " << numeric_limits::round_style << "\n"; - cout << " has_infinity " << numeric_limits::has_infinity << "\n"; - cout << " has_quiet_NaN " << numeric_limits::has_quiet_NaN << "\n"; - cout << " has_signaling_NaN " << numeric_limits::has_signaling_NaN << "\n"; - cout << " has_denorm " << numeric_limits::has_denorm << "\n"; - cout << " digits " << numeric_limits::digits << "\n"; - cout << " digits10 " << numeric_limits::digits10 << "\n"; -# ifndef BOOST_NO_CXX11_NUMERIC_LIMITS - cout << " max_digits10 " << numeric_limits::max_digits10 << "\n"; -# endif - cout << " radix " << numeric_limits::radix << "\n"; - cout << " min_exponent " << numeric_limits::min_exponent << "\n"; - cout << " min_exponent10 " << numeric_limits::min_exponent10 << "\n"; - cout << " max_exponent " << numeric_limits::max_exponent << "\n"; - cout << " max_exponent10 " << numeric_limits::max_exponent10 << "\n"; - show_value("min()", numeric_limits::min()); - show_value("max()", numeric_limits::max()); -# ifndef BOOST_NO_CXX11_NUMERIC_LIMITS - show_value("lowest()", numeric_limits::lowest()); -# endif - show_value("epsilon()", numeric_limits::epsilon()); - show_value("round_error()", numeric_limits::round_error()); - show_value("infinity()", numeric_limits::infinity()); - show_value("-infinity()", -numeric_limits::infinity()); - show_value("quiet_NaN()", numeric_limits::quiet_NaN()); - show_value("signaling_NaN()", numeric_limits::signaling_NaN()); - show_value("denorm_min()", numeric_limits::denorm_min()); - show_value("0.0", static_cast(0.0)); - show_value("-0.0", static_cast(-0.0)); - show_value("1.0", static_cast(1.0)); - show_value("-1.0", static_cast(-1.0)); - show_value("pi()", pi()); - } - -template -void auto_test(const char* msg, const boost::array, 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"); - auto_test("float", float_test_cases); - - report_limits("double"); - auto_test("double", double_test_cases); - - cout << "\n done" << endl; - - return ::boost::endian::report_errors(); -} - -#include diff --git a/test/fp_exhaustive_test.cpp b/test/fp_exhaustive_test.cpp deleted file mode 100644 index 1774c98..0000000 --- a/test/fp_exhaustive_test.cpp +++ /dev/null @@ -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 - -//#define BOOST_ENDIAN_LOG -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -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(&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(&i) << " as float\n" - // "but endian_reverse(endian_reverse()) round-trip yields " - // << endian_reverse(endian_reverse(*reinterpret_cast(&i))) << "\n" - // ; -// erx = endian_reverse(x); - break; - } - ++i; - } while (i != 0); - - cout << "\n done" << endl; - - return ::boost::endian::report_errors(); -} - -#include diff --git a/test/msvc/endian.sln b/test/msvc/endian.sln index 2de57fc..5ea8aec 100644 --- a/test/msvc/endian.sln +++ b/test/msvc/endian.sln @@ -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 diff --git a/test/msvc/floating_point_test/floating_point_test.vcxproj b/test/msvc/floating_point_test/floating_point_test.vcxproj deleted file mode 100644 index 73c1cad..0000000 --- a/test/msvc/floating_point_test/floating_point_test.vcxproj +++ /dev/null @@ -1,89 +0,0 @@ - - - - - Debug - Win32 - - - Release - Win32 - - - - {27E8FDC5-9669-4940-B24F-94B21FFEE649} - Win32Proj - float_test - floating_point_test - - - - Application - true - v140 - Unicode - - - Application - false - v140 - true - Unicode - - - - - - - - - - - - - - - true - - - false - - - - - - Level3 - Disabled - WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions) - true - - - Console - true - - - - - Level3 - - - MaxSpeed - true - true - WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions) - true - - - Console - true - true - true - - - - - - - - - \ No newline at end of file diff --git a/test/msvc/fp_exhaustive_test/fp_exhaustive_test.vcxproj b/test/msvc/fp_exhaustive_test/fp_exhaustive_test.vcxproj deleted file mode 100644 index 85e9b89..0000000 --- a/test/msvc/fp_exhaustive_test/fp_exhaustive_test.vcxproj +++ /dev/null @@ -1,96 +0,0 @@ - - - - - Debug - Win32 - - - Release - Win32 - - - - {E19A89FE-D728-4705-A060-B85E7239984C} - Win32Proj - fp_exhaustive_test - - - - Application - true - v140 - Unicode - - - Application - false - v140 - true - Unicode - - - - - - - - - - - - - - - - - true - - - false - - - - - - Level3 - Disabled - WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions) - true - - - Console - true - - - - - - - - Level3 - - - MaxSpeed - true - true - WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions) - true - - - Console - true - true - true - - - - - - - - - - - - \ No newline at end of file