mirror of
https://github.com/fmtlib/fmt.git
synced 2025-01-05 12:55:00 +00:00
Allow bit_cast to work for 80bit long double (#4246)
This commit is contained in:
parent
df249d8ad3
commit
385c01dc7b
@ -419,17 +419,17 @@ template <> constexpr auto num_bits<uint128_fallback>() -> int { return 128; }
|
||||
// and 128-bit pointers to uint128_fallback.
|
||||
template <typename To, typename From, FMT_ENABLE_IF(sizeof(To) > sizeof(From))>
|
||||
inline auto bit_cast(const From& from) -> To {
|
||||
constexpr auto size = static_cast<int>(sizeof(From) / sizeof(unsigned));
|
||||
constexpr auto size = static_cast<int>(sizeof(From) / sizeof(unsigned short));
|
||||
struct data_t {
|
||||
unsigned value[static_cast<unsigned>(size)];
|
||||
unsigned short value[static_cast<unsigned>(size)];
|
||||
} data = bit_cast<data_t>(from);
|
||||
auto result = To();
|
||||
if (const_check(is_big_endian())) {
|
||||
for (int i = 0; i < size; ++i)
|
||||
result = (result << num_bits<unsigned>()) | data.value[i];
|
||||
result = (result << num_bits<unsigned short>()) | data.value[i];
|
||||
} else {
|
||||
for (int i = size - 1; i >= 0; --i)
|
||||
result = (result << num_bits<unsigned>()) | data.value[i];
|
||||
result = (result << num_bits<unsigned short>()) | data.value[i];
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user