1 /* 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) 5 * 6 * Copyright (c) 2018 Andrey Semashev 7 */ 8 /*! 9 * \file atomic/detail/bitwise_fp_cast.hpp 10 * 11 * This header defines \c bitwise_fp_cast used to convert between storage and floating point value types 12 */ 13 14 #ifndef BOOST_ATOMIC_DETAIL_BITWISE_FP_CAST_HPP_INCLUDED_ 15 #define BOOST_ATOMIC_DETAIL_BITWISE_FP_CAST_HPP_INCLUDED_ 16 17 #include <cstddef> 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> 22 23 #ifdef BOOST_HAS_PRAGMA_ONCE 24 #pragma once 25 #endif 26 27 namespace boost { 28 namespace atomics { 29 namespace detail { 30 31 /*! 32 * \brief The type trait returns the size of the value of the specified floating point type 33 * 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. 36 */ 37 template< typename T > 38 struct value_sizeof 39 { 40 static BOOST_CONSTEXPR_OR_CONST std::size_t value = sizeof(T); 41 }; 42 43 #if defined(BOOST_ATOMIC_DETAIL_SIZEOF_FLOAT_VALUE) 44 template< > 45 struct value_sizeof< float > 46 { 47 static BOOST_CONSTEXPR_OR_CONST std::size_t value = BOOST_ATOMIC_DETAIL_SIZEOF_FLOAT_VALUE; 48 }; 49 #endif 50 51 #if defined(BOOST_ATOMIC_DETAIL_SIZEOF_DOUBLE_VALUE) 52 template< > 53 struct value_sizeof< double > 54 { 55 static BOOST_CONSTEXPR_OR_CONST std::size_t value = BOOST_ATOMIC_DETAIL_SIZEOF_DOUBLE_VALUE; 56 }; 57 #endif 58 59 #if defined(BOOST_ATOMIC_DETAIL_SIZEOF_LONG_DOUBLE_VALUE) 60 template< > 61 struct value_sizeof< long double > 62 { 63 static BOOST_CONSTEXPR_OR_CONST std::size_t value = BOOST_ATOMIC_DETAIL_SIZEOF_LONG_DOUBLE_VALUE; 64 }; 65 #endif 66 67 template< typename T > 68 struct value_sizeof< const T > : value_sizeof< T > {}; 69 70 template< typename T > 71 struct value_sizeof< volatile T > : value_sizeof< T > {}; 72 73 template< typename T > 74 struct value_sizeof< const volatile T > : value_sizeof< T > {}; 75 76 77 template< typename To, typename From > bitwise_fp_cast(From const & from)78BOOST_FORCEINLINE To bitwise_fp_cast(From const& from) BOOST_NOEXCEPT 79 { 80 return atomics::detail::bitwise_cast< To, atomics::detail::value_sizeof< From >::value >(from); 81 } 82 83 } // namespace detail 84 } // namespace atomics 85 } // namespace boost 86 87 #include <boost/atomic/detail/footer.hpp> 88 89 #endif // BOOST_ATOMIC_DETAIL_BITWISE_FP_CAST_HPP_INCLUDED_ 90