Fix 256-bit high bit calculation

This commit is contained in:
Matt Borland
2023-06-30 17:27:52 +02:00
parent 5808c27206
commit dc6ce63e01
2 changed files with 6 additions and 5 deletions

View File

@@ -177,8 +177,9 @@ inline uint128 mask_mantissa(uint256 z) noexcept;
template <typename T>
inline uint128 mask_mantissa(uint256 z) noexcept
{
static constexpr uint128 mask {0x1FFFFFFFFFFFF, UINT64_MAX};
return (z >> 113) & mask;
//static constexpr uint128 mask {0x1FFFFFFFFFFFF, UINT64_MAX};
//return static_cast<uint128>((z >> 113) & mask);
return z.high;
}
#elif BOOST_CHARCONV_LDBL_BITS == 128
@@ -337,7 +338,7 @@ inline ResultType compute_float80(std::int64_t q, Unsigned_Integer w, bool negat
#endif
// Step 8: Value of the most significant bit of z
const auto u = significant_bit<ResultType>(z) == m ? 0 : 1;
const auto u = high_bit(z) == 255 ? 0 : 1;
#ifdef BOOST_CHARCONV_DEBUG_FLOAT128
std::cerr << "u: " << u << std::endl;
#endif

View File

@@ -242,11 +242,11 @@ int high_bit(uint256 v) noexcept
{
if (v.high != 0)
{
return high_bit(v.high);
return 255 - high_bit(v.high);
}
else if (v.low != 0)
{
return high_bit(v.low);
return 127 - high_bit(v.low);
}
return 0;