Fix compiler errors under C++14

This commit is contained in:
Matt Borland
2023-03-15 18:54:46 -07:00
parent a69acf078e
commit 8e51595139
5 changed files with 34 additions and 33 deletions

View File

@@ -36,16 +36,6 @@ struct ieee754_binary32
static constexpr int decimal_digits = 9;
};
#ifdef BOOST_NO_CXX17_INLINE_VARIABLES
// Definitions of in-class constexpr members are allowed but deprecated in C++17
constexpr int ieee754_binary32::significand_bits;
constexpr int ieee754_binary32::exponent_bits;
constexpr int ieee754_binary32::min_exponent;
constexpr int ieee754_binary32::max_exponent;
constexpr int ieee754_binary32::exponent_bias;
constexpr int ieee754_binary32::decimal_digits;
#endif
struct IEEEd2bits
{
#if BOOST_CHARCONV_ENDIAN_LITTLE_BYTE
@@ -71,16 +61,6 @@ struct ieee754_binary64
static constexpr int decimal_digits = 17;
};
#ifdef BOOST_NO_CXX17_INLINE_VARIABLES
// Definitions of in-class constexpr members are allowed but deprecated in C++17
constexpr int ieee754_binary64::significand_bits;
constexpr int ieee754_binary64::exponent_bits;
constexpr int ieee754_binary64::min_exponent;
constexpr int ieee754_binary64::max_exponent;
constexpr int ieee754_binary64::exponent_bias;
constexpr int ieee754_binary64::decimal_digits;
#endif
// 80 bit long double (e.g. x86-64)
#if LDBL_MANT_DIG == 64 && LDBL_MAX_EXP == 16384

View File

@@ -39,6 +39,13 @@
# define BOOST_CHARCONV_GCC5_CONSTEXPR BOOST_CHARCONV_CXX14_CONSTEXPR
#endif
// C++17 allowed for constexpr lambdas
#if defined(__cpp_constexpr) && __cpp_constexpr >= 201603L
# define BOOST_CHARCONV_CXX17_CONSTEXPR constexpr
#else
# define BOOST_CHARCONV_CXX17_CONSTEXPR inline
#endif
// Determine endianness
#if defined(_WIN32)

View File

@@ -339,7 +339,9 @@ struct impl : private FloatTraits, private FloatTraits::format
// Compute xi and deltai.
// 10^kappa <= deltai < 10^(kappa + 1)
const auto deltai = compute_delta(cache, beta);
auto [xi, is_x_integer] = compute_mul(two_fc << beta, cache);
const auto x_result = compute_mul(two_fc << beta, cache);
auto xi = x_result.result;
auto is_x_integer = x_result.is_integer;
// Deal with the unique exceptional cases
// 29711844 * 2^-82
@@ -489,7 +491,7 @@ struct impl : private FloatTraits, private FloatTraits::format
{
BOOST_CHARCONV_ASSERT(n != 0);
BOOST_IF_CONSTEXPR (std::is_same_v<format, ieee754_binary32>)
BOOST_IF_CONSTEXPR (std::is_same<format, ieee754_binary32>::value)
{
constexpr auto mod_inv_5 = UINT32_C(0xcccccccd);
constexpr auto mod_inv_25 = mod_inv_5 * mod_inv_5;
@@ -519,7 +521,7 @@ struct impl : private FloatTraits, private FloatTraits::format
}
else
{
static_assert(std::is_same<format, ieee754_binary64>::value);
static_assert(std::is_same<format, ieee754_binary64>::value, "Type must be binary64");
// Divide by 10^8 and reduce to 32-bits if divisible.
// Since ret_value.significand <= (2^53 * 1000 - 1) / 1000 < 10^16,
@@ -602,7 +604,7 @@ struct impl : private FloatTraits, private FloatTraits::format
}
else
{
static_assert(std::is_same<format, ieee754_binary64>::value);
static_assert(std::is_same<format, ieee754_binary64>::value, "Type must be binary64");
auto r = umul192_upper128(u, cache);
return {r.high, r.low == 0};
}
@@ -616,7 +618,7 @@ struct impl : private FloatTraits, private FloatTraits::format
}
else
{
static_assert(std::is_same<format, ieee754_binary64>::value);
static_assert(std::is_same<format, ieee754_binary64>::value, "Type must be binary64");
return static_cast<std::uint32_t>(cache.high >> (carrier_bits - 1 - beta));
}
}
@@ -632,7 +634,7 @@ struct impl : private FloatTraits, private FloatTraits::format
}
else
{
static_assert(std::is_same<format, ieee754_binary64>::value);
static_assert(std::is_same<format, ieee754_binary64>::value, "Type must be binary64");
auto r = umul192_lower128(two_f, cache);
return {((r.high >> (64 - beta)) & 1) != 0, ((r.high << beta) | (r.low >> (64 - beta))) == 0};
}
@@ -647,7 +649,7 @@ struct impl : private FloatTraits, private FloatTraits::format
}
else
{
static_assert(std::is_same<format, ieee754_binary64>::value);
static_assert(std::is_same<format, ieee754_binary64>::value, "Type must be binary64");
return (cache.high - (cache.high >> (significand_bits + 2))) >> (carrier_bits - significand_bits - 1 - beta);
}
}
@@ -661,7 +663,7 @@ struct impl : private FloatTraits, private FloatTraits::format
}
else
{
static_assert(std::is_same<format, ieee754_binary64>::value);
static_assert(std::is_same<format, ieee754_binary64>::value, "Type must be binary64");
return (cache.high + (cache.high >> (significand_bits + 1))) >> (carrier_bits - significand_bits - 1 - beta);
}
}
@@ -674,7 +676,7 @@ struct impl : private FloatTraits, private FloatTraits::format
}
else
{
static_assert(std::is_same<format, ieee754_binary64>::value);
static_assert(std::is_same<format, ieee754_binary64>::value, "Type must be binary64");
return ((cache.high >> (carrier_bits - significand_bits - 2 - beta)) + 1) / 2;
}
}
@@ -757,7 +759,7 @@ BOOST_FORCEINLINE BOOST_CHARCONV_SAFEBUFFERS auto to_decimal(signed_significand_
// 10^-308. This is indeed of the shortest length, and it is the unique one
// closest to the true value among valid representations of the same length.
static_assert(std::is_same<format, ieee754_binary32>::value ||
std::is_same<format, ieee754_binary64>::value);
std::is_same<format, ieee754_binary64>::value, "Type must be either binary 32 or 64");
if (two_fc == 0)
{
@@ -816,7 +818,7 @@ BOOST_FORCEINLINE BOOST_CHARCONV_SAFEBUFFERS auto to_decimal(signed_significand_
}
else
{
static_assert(tag == decimal_to_binary_rounding::tag_t::right_closed_directed);
static_assert(tag == decimal_to_binary_rounding::tag_t::right_closed_directed, "Tag must be right_closed_direction");
bool shorter_interval {};

View File

@@ -389,6 +389,7 @@ struct compressed_cache_detail
(cache_holder<ieee754_binary64>::max_k - cache_holder<ieee754_binary64>::min_k +
compression_ratio) / compression_ratio;
/*
struct cache_holder_t
{
value128 table[compressed_table_size];
@@ -418,6 +419,17 @@ struct compressed_cache_detail
}
return res;
}();
*/
// TODO: Pre-calculate the tables from above to use with C++14 and below
struct cache_holder_t
{
static value128 table[compressed_table_size];
};
struct pow5_holder_t
{
static std::uint64_t table[compression_ratio];
};
};
#ifdef BOOST_NO_CXX17_INLINE_VARIABLES

View File

@@ -632,7 +632,7 @@ namespace policy_impl {
const auto offset = k - kb;
// Get the base cache.
const value128 base_cache = compressed_cache_detail::cache.table[cache_index];
const value128 base_cache = compressed_cache_detail::cache_holder_t::table[cache_index];
if (offset == 0)
{
@@ -645,7 +645,7 @@ namespace policy_impl {
BOOST_CHARCONV_ASSERT(alpha > 0 && alpha < 64);
// Try to recover the real cache.
const auto pow5 = compressed_cache_detail::pow5.table[offset];
const auto pow5 = compressed_cache_detail::pow5_holder_t::table[offset];
auto recovered_cache = full_multiplication(base_cache.high, pow5);
const auto middle_low = full_multiplication(base_cache.low, pow5);