| 1 | // Copyright 2023 Matt Borland |
| 2 | // Distributed under the Boost Software License, Version 1.0. |
| 3 | // https://www.boost.org/LICENSE_1_0.txt |
| 4 | |
| 5 | #ifndef BOOST_CHARCONV_DETAIL_ISSIGNALING_HPP |
| 6 | #define BOOST_CHARCONV_DETAIL_ISSIGNALING_HPP |
| 7 | |
| 8 | #include <boost/charconv/detail/config.hpp> |
| 9 | #include <boost/charconv/detail/bit_layouts.hpp> |
| 10 | #include <cstdint> |
| 11 | #include <cstring> |
| 12 | |
| 13 | namespace boost { namespace charconv { namespace detail { |
| 14 | |
| 15 | template <typename T> |
| 16 | inline bool issignaling BOOST_PREVENT_MACRO_SUBSTITUTION (T x) noexcept; |
| 17 | |
| 18 | #if BOOST_CHARCONV_LDBL_BITS == 128 || defined(BOOST_CHARCONV_HAS_FLOAT128) |
| 19 | |
| 20 | struct words128 |
| 21 | { |
| 22 | #if BOOST_CHARCONV_ENDIAN_LITTLE_BYTE |
| 23 | std::uint64_t lo; |
| 24 | std::uint64_t hi; |
| 25 | #else |
| 26 | std::uint64_t hi; |
| 27 | std::uint64_t lo; |
| 28 | #endif |
| 29 | }; |
| 30 | |
| 31 | template <typename T> |
| 32 | inline bool issignaling BOOST_PREVENT_MACRO_SUBSTITUTION (T x) noexcept |
| 33 | { |
| 34 | words128 bits; |
| 35 | std::memcpy(&bits, &x, sizeof(T)); |
| 36 | |
| 37 | std::uint64_t hi_word = bits.hi; |
| 38 | std::uint64_t lo_word = bits.lo; |
| 39 | |
| 40 | hi_word ^= UINT64_C(0x0000800000000000); |
| 41 | hi_word |= (lo_word | -lo_word) >> 63; |
| 42 | return ((hi_word & INT64_MAX) > UINT64_C(0x7FFF800000000000)); |
| 43 | } |
| 44 | |
| 45 | #endif |
| 46 | |
| 47 | }}} // Namespaces |
| 48 | |
| 49 | #endif // BOOST_CHARCONV_DETAIL_ISSIGNALING_HPP |
| 50 | |