mirror of
https://github.com/boostorg/endian.git
synced 2025-08-01 05:24:39 +02:00
float showing signs of life.
This commit is contained in:
@@ -13,6 +13,7 @@
|
||||
#include <boost/cstdint.hpp>
|
||||
#include <boost/endian/detail/intrinsic.hpp>
|
||||
#include <boost/detail/scoped_enum_emulation.hpp>
|
||||
#include <boost/static_assert.hpp>
|
||||
#include <algorithm>
|
||||
|
||||
//------------------------------------- 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 <class T>
|
||||
|
@@ -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 <boost/cstdint.hpp>
|
||||
#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 <byteswap.h>
|
||||
#define BOOST_ENDIAN_INTRINSIC_BYTE_SWAP_2 bswap_16
|
||||
|
@@ -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();
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user