Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-04-19 08:19:39

0001 // Copyright 2023 Matt Borland
0002 // Distributed under the Boost Software License, Version 1.0.
0003 // https://www.boost.org/LICENSE_1_0.txt
0004 
0005 #ifndef BOOST_CHARCONV_DETAIL_BIT_LAYOUTS_HPP
0006 #define BOOST_CHARCONV_DETAIL_BIT_LAYOUTS_HPP
0007 
0008 #include <boost/charconv/detail/config.hpp>
0009 #include <boost/charconv/detail/emulated128.hpp>
0010 #include <cstdint>
0011 #include <cfloat>
0012 
0013 // Layouts of floating point types as specified by IEEE 754
0014 // See page 23 of IEEE 754-2008
0015 
0016 namespace boost { namespace charconv { namespace detail {
0017 
0018 struct ieee754_binary16
0019 {
0020     static constexpr int significand_bits = 10;
0021     static constexpr int exponent_bits = 5;
0022     static constexpr int min_exponent = -14;
0023     static constexpr int max_exponent = 15;
0024     static constexpr int exponent_bias = -15;
0025     static constexpr int decimal_digits = 5;
0026 };
0027 
0028 struct brainfloat16
0029 {
0030     static constexpr int significand_bits = 7;
0031     static constexpr int exponent_bits = 8;
0032     static constexpr int min_exponent = -126;
0033     static constexpr int max_exponent = 127;
0034     static constexpr int exponent_bias = -127;
0035     static constexpr int decimal_digits = 4;
0036 };
0037 
0038 struct ieee754_binary32 
0039 {
0040     static constexpr int significand_bits = 23;
0041     static constexpr int exponent_bits = 8;
0042     static constexpr int min_exponent = -126;
0043     static constexpr int max_exponent = 127;
0044     static constexpr int exponent_bias = -127;
0045     static constexpr int decimal_digits = 9;
0046 };
0047 
0048 struct ieee754_binary64 
0049 {
0050     static constexpr int significand_bits = 52;
0051     static constexpr int exponent_bits = 11;
0052     static constexpr int min_exponent = -1022;
0053     static constexpr int max_exponent = 1023;
0054     static constexpr int exponent_bias = -1023;
0055     static constexpr int decimal_digits = 17;
0056 };
0057 
0058 // 80 bit long double (e.g. x86-64)
0059 #if LDBL_MANT_DIG == 64 && LDBL_MAX_EXP == 16384
0060 
0061 struct IEEEl2bits
0062 {
0063 #if BOOST_CHARCONV_ENDIAN_LITTLE_BYTE
0064     std::uint64_t mantissa_l : 64;
0065     std::uint32_t exponent : 15;
0066     std::uint32_t sign : 1;
0067     std::uint64_t pad : 48;
0068 #else // Big endian
0069     std::uint64_t pad : 48;
0070     std::uint32_t sign : 1;
0071     std::uint32_t exponent : 15;
0072     std::uint64_t mantissa_h : 64;
0073 #endif
0074 };
0075 
0076 struct ieee754_binary80
0077 {
0078     static constexpr int significand_bits = 64; // Fraction is 63 and 1 integer bit
0079     static constexpr int exponent_bits = 15;
0080     static constexpr int min_exponent = -16382;
0081     static constexpr int max_exponent = 16383;
0082     static constexpr int exponent_bias = -16383;
0083     static constexpr int decimal_digits = 18;
0084 };
0085 
0086 #define BOOST_CHARCONV_LDBL_BITS 80
0087 
0088 // 128 bit long double (e.g. s390x, ppcle64)
0089 #elif LDBL_MANT_DIG == 113 && LDBL_MAX_EXP == 16384
0090 
0091 struct IEEEl2bits
0092 {
0093 #if BOOST_CHARCONV_ENDIAN_LITTLE_BYTE
0094     std::uint64_t mantissa_l : 64;
0095     std::uint64_t mantissa_h : 48;
0096     std::uint32_t exponent : 15;
0097     std::uint32_t sign : 1;
0098 #else // Big endian
0099     std::uint32_t sign : 1;
0100     std::uint32_t exponent : 15;
0101     std::uint64_t mantissa_h : 48;
0102     std::uint64_t mantissa_l : 64;
0103 #endif
0104 };
0105 
0106 #define BOOST_CHARCONV_LDBL_BITS 128
0107 
0108 // 64 bit long double (double == long double on ARM)
0109 #elif LDBL_MANT_DIG == 53 && LDBL_MAX_EXP == 1024
0110 
0111 struct IEEEl2bits
0112 {
0113 #if BOOST_CHARCONV_ENDIAN_LITTLE_BYTE
0114     std::uint32_t mantissa_l : 32;
0115     std::uint32_t mantissa_h : 20;
0116     std::uint32_t exponent : 11;
0117     std::uint32_t sign : 1;
0118 #else // Big endian
0119     std::uint32_t sign : 1;
0120     std::uint32_t exponent : 11;
0121     std::uint32_t mantissa_h : 20;
0122     std::uint32_t mantissa_l : 32;
0123 #endif
0124 };
0125 
0126 #define BOOST_CHARCONV_LDBL_BITS 64
0127 
0128 #else // Unsupported long double representation
0129 #  define BOOST_CHARCONV_UNSUPPORTED_LONG_DOUBLE
0130 #  define BOOST_CHARCONV_LDBL_BITS -1
0131 #endif
0132 
0133 struct IEEEbinary128
0134 {
0135 #if BOOST_CHARCONV_ENDIAN_LITTLE_BYTE
0136     std::uint64_t mantissa_l : 64;
0137     std::uint64_t mantissa_h : 48;
0138     std::uint32_t exponent : 15;
0139     std::uint32_t sign : 1;
0140 #else // Big endian
0141     std::uint32_t sign : 1;
0142     std::uint32_t exponent : 15;
0143     std::uint64_t mantissa_h : 48;
0144     std::uint64_t mantissa_l : 64;
0145 #endif
0146 };
0147 
0148 struct ieee754_binary128
0149 {
0150     static constexpr int significand_bits = 112;
0151     static constexpr int exponent_bits = 15;
0152     static constexpr int min_exponent = -16382;
0153     static constexpr int max_exponent = 16383;
0154     static constexpr int exponent_bias = 16383;
0155     static constexpr int decimal_digits = 33;
0156 };
0157 
0158 }}} // Namespaces
0159 
0160 #endif // BOOST_CHARCONV_DETAIL_BIT_LAYOUTS_HPP