2 * Distributed under the Boost Software License, Version 1.0.
3 * (See accompanying file LICENSE_1_0.txt or copy at
4 * http://www.boost.org/LICENSE_1_0.txt)
6 * Copyright (c) 2018 Andrey Semashev
9 * \file atomic/detail/bitwise_fp_cast.hpp
11 * This header defines \c bitwise_fp_cast used to convert between storage and floating point value types
14 #ifndef BOOST_ATOMIC_DETAIL_BITWISE_FP_CAST_HPP_INCLUDED_
15 #define BOOST_ATOMIC_DETAIL_BITWISE_FP_CAST_HPP_INCLUDED_
18 #include <boost/atomic/detail/config.hpp>
19 #include <boost/atomic/detail/float_sizes.hpp>
20 #include <boost/atomic/detail/bitwise_cast.hpp>
21 #include <boost/atomic/detail/header.hpp>
23 #ifdef BOOST_HAS_PRAGMA_ONCE
32 * \brief The type trait returns the size of the value of the specified floating point type
34 * This size may be less than <tt>sizeof(T)</tt> if the implementation uses padding bytes for a particular FP type. This is
35 * often the case with 80-bit extended double, which is stored in 12 or 16 bytes with padding filled with garbage.
37 template< typename T >
40 static BOOST_CONSTEXPR_OR_CONST std::size_t value = sizeof(T);
43 #if defined(BOOST_ATOMIC_DETAIL_SIZEOF_FLOAT_VALUE)
45 struct value_sizeof< float >
47 static BOOST_CONSTEXPR_OR_CONST std::size_t value = BOOST_ATOMIC_DETAIL_SIZEOF_FLOAT_VALUE;
51 #if defined(BOOST_ATOMIC_DETAIL_SIZEOF_DOUBLE_VALUE)
53 struct value_sizeof< double >
55 static BOOST_CONSTEXPR_OR_CONST std::size_t value = BOOST_ATOMIC_DETAIL_SIZEOF_DOUBLE_VALUE;
59 #if defined(BOOST_ATOMIC_DETAIL_SIZEOF_LONG_DOUBLE_VALUE)
61 struct value_sizeof< long double >
63 static BOOST_CONSTEXPR_OR_CONST std::size_t value = BOOST_ATOMIC_DETAIL_SIZEOF_LONG_DOUBLE_VALUE;
67 template< typename T >
68 struct value_sizeof< const T > : value_sizeof< T > {};
70 template< typename T >
71 struct value_sizeof< volatile T > : value_sizeof< T > {};
73 template< typename T >
74 struct value_sizeof< const volatile T > : value_sizeof< T > {};
77 template< typename To, typename From >
78 BOOST_FORCEINLINE To bitwise_fp_cast(From const& from) BOOST_NOEXCEPT
80 return atomics::detail::bitwise_cast< To, atomics::detail::value_sizeof< From >::value >(from);
84 } // namespace atomics
87 #include <boost/atomic/detail/footer.hpp>
89 #endif // BOOST_ATOMIC_DETAIL_BITWISE_FP_CAST_HPP_INCLUDED_