Fix endianness bug in write_digit2_separated

This commit is contained in:
Vladislav Shchapov 2022-01-04 15:04:30 +05:00
parent fc1783fcc6
commit 074cc781cb

View File

@ -558,8 +558,14 @@ inline void write_digit2_separated(char* buf, unsigned a, unsigned b,
auto usep = static_cast<unsigned long long>(sep); auto usep = static_cast<unsigned long long>(sep);
// Add ASCII '0' to each digit byte and insert separators. // Add ASCII '0' to each digit byte and insert separators.
digits |= 0x3030003030003030 | (usep << 16) | (usep << 40); digits |= 0x3030003030003030 | (usep << 16) | (usep << 40);
if (is_big_endian()) {
char tmp[8];
memcpy(tmp, &digits, 8);
std::reverse_copy(tmp, tmp + 8, buf);
} else {
memcpy(buf, &digits, 8); memcpy(buf, &digits, 8);
} }
}
template <typename Period> FMT_CONSTEXPR inline const char* get_units() { template <typename Period> FMT_CONSTEXPR inline const char* get_units() {
if (std::is_same<Period, std::atto>::value) return "as"; if (std::is_same<Period, std::atto>::value) return "as";