From 9e96faf4c1db2b7350ffd698d5b7fdf4c4382d5a Mon Sep 17 00:00:00 2001 From: Beman Date: Sat, 11 May 2013 08:13:55 -0400 Subject: [PATCH] float showing signs of life. --- include/boost/endian/converters.hpp | 24 ++++++++++++++++------- include/boost/endian/detail/intrinsic.hpp | 7 ------- test/converter_test.cpp | 4 ++++ 3 files changed, 21 insertions(+), 14 deletions(-) diff --git a/include/boost/endian/converters.hpp b/include/boost/endian/converters.hpp index 3c79ea3..112fd2a 100644 --- a/include/boost/endian/converters.hpp +++ b/include/boost/endian/converters.hpp @@ -13,6 +13,7 @@ #include #include #include +#include #include //------------------------------------- synopsis ---------------------------------------// @@ -37,14 +38,9 @@ namespace endian // reverse_bytes overloads for floating point types as requested by Vicente // Botet and others. - // TODO: Need implementation - // TODO: Need to verify the return does not invoke undefined behavior (as might happen - // if there are unutterable floating point values, such as happens with the unutterable - // pointer values that cause an immediate abort on some legacy architectures // TODO: Track progress of Floating-Point Typedefs Having Specified Widths proposal (N3626) - // and add boost equivalent from Paul, Chris, John, if available - inline float reverse_bytes(float x) BOOST_NOEXCEPT; - inline double reverse_bytes(double x) BOOST_NOEXCEPT; + inline float reverse_bytes(float x) BOOST_NOEXCEPT; + //inline double reverse_bytes(double x) BOOST_NOEXCEPT; // general reverse_bytes function template to meet requests for UDT support by Vicente // Botet and others. @@ -155,6 +151,20 @@ namespace endian # endif } + inline float reverse_bytes(float x) BOOST_NOEXCEPT + { + BOOST_STATIC_ASSERT_MSG(sizeof(float) == sizeof(uint32_t), + "boost::endian only supprts sizeof(float) == 4; please report error to boost mailing list"); + uint32_t tmp = reverse_bytes(*(const uint32_t*)&x); + return *(const float*)&tmp; + } + + //inline double reverse_bytes(double x) BOOST_NOEXCEPT + //{ + // BOOST_STATIC_ASSERT_MSG(sizeof(double) == sizeof(uint64_t), + // "boost::endian only supprts sizeof(double) == 8; please report error to boost mailing list"); + //} + // general reverse_bytes function template implementation approach using std::reverse // suggested by Mathias Gaunard template diff --git a/include/boost/endian/detail/intrinsic.hpp b/include/boost/endian/detail/intrinsic.hpp index 63f6c72..1bf95ba 100644 --- a/include/boost/endian/detail/intrinsic.hpp +++ b/include/boost/endian/detail/intrinsic.hpp @@ -1,6 +1,5 @@ // Copyright (C) 2012 David Stone // Distributed under the Boost Software License, Version 1.0. -// See accompanying file LICENSE_1_0.txt or copy at // http://www.boost.org/LICENSE_1_0.txt // // See http://www.boost.org/libs/endian/ for documentation. @@ -15,12 +14,6 @@ # include #endif - -#undef BOOST_ENDIAN_NO_INTRINSICS -#undef BOOST_ENDIAN_INTRINSIC_BYTE_SWAP_2 -#undef BOOST_ENDIAN_INTRINSIC_BYTE_SWAP_4 -#undef BOOST_ENDIAN_INTRINSIC_BYTE_SWAP_8 - #if (defined __GNUC__ || defined __clang__) #include #define BOOST_ENDIAN_INTRINSIC_BYTE_SWAP_2 bswap_16 diff --git a/test/converter_test.cpp b/test/converter_test.cpp index a5f60d0..b349c65 100644 --- a/test/converter_test.cpp +++ b/test/converter_test.cpp @@ -306,6 +306,10 @@ int cpp_main(int, char * []) test_conditional_reverse_bytes(); test_compile_time_convert_bytes(); test_runtime_convert_bytes(); + + BOOST_TEST(be::reverse_bytes(1.0F) != 1.0F); + BOOST_TEST(be::reverse_bytes(be::reverse_bytes(1.0F)) == 1.0F); + return ::boost::report_errors(); }