File indexing completed on 2025-04-19 08:19:40
0001
0002
0003
0004
0005 #ifndef BOOST_CHARCONV_DETAIL_ISSIGNALING_HPP
0006 #define BOOST_CHARCONV_DETAIL_ISSIGNALING_HPP
0007
0008 #include <boost/charconv/detail/config.hpp>
0009 #include <boost/charconv/detail/bit_layouts.hpp>
0010 #include <cstdint>
0011 #include <cstring>
0012
0013 namespace boost { namespace charconv { namespace detail {
0014
0015 template <typename T>
0016 inline bool issignaling BOOST_PREVENT_MACRO_SUBSTITUTION (T x) noexcept;
0017
0018 #if BOOST_CHARCONV_LDBL_BITS == 128
0019
0020 struct words128
0021 {
0022 #if BOOST_CHARCONV_ENDIAN_LITTLE_BYTE
0023 std::uint64_t lo;
0024 std::uint64_t hi;
0025 #else
0026 std::uint64_t hi;
0027 std::uint64_t lo;
0028 #endif
0029 };
0030
0031 template <typename T>
0032 inline bool issignaling BOOST_PREVENT_MACRO_SUBSTITUTION (T x) noexcept
0033 {
0034 words128 bits;
0035 std::memcpy(&bits, &x, sizeof(T));
0036
0037 std::uint64_t hi_word = bits.hi;
0038 std::uint64_t lo_word = bits.lo;
0039
0040 hi_word ^= UINT64_C(0x0000800000000000);
0041 hi_word |= (lo_word | -lo_word) >> 63;
0042 return ((hi_word & INT64_MAX) > UINT64_C(0x7FFF800000000000));
0043 }
0044
0045 #endif
0046
0047
0048
0049
0050
0051
0052
0053
0054
0055
0056
0057
0058
0059 #ifdef BOOST_CHARCONV_HAS_FLOAT16
0060
0061 template <>
0062 inline bool issignaling<std::float16_t> BOOST_PREVENT_MACRO_SUBSTITUTION (std::float16_t x) noexcept
0063 {
0064 std::uint16_t bits;
0065 std::memcpy(&bits, &x, sizeof(std::uint16_t));
0066 return bits >= UINT16_C(0x7D00) && bits < UINT16_C(0x7E00);
0067 }
0068
0069 #endif
0070
0071 #ifdef BOOST_CHARCONV_HAS_BRAINFLOAT16
0072
0073 template <>
0074 inline bool issignaling<std::bfloat16_t> BOOST_PREVENT_MACRO_SUBSTITUTION (std::bfloat16_t x) noexcept
0075 {
0076 std::uint16_t bits;
0077 std::memcpy(&bits, &x, sizeof(std::uint16_t));
0078 return bits >= UINT16_C(0x7FA0) && bits < UINT16_C(0x7FC0);
0079 }
0080
0081 #endif
0082
0083 }}}
0084
0085 #endif