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