From 68a2852043043c55fa31543beec14eb2f508d8b6 Mon Sep 17 00:00:00 2001 From: Joshua Ashton Date: Fri, 7 Aug 2020 04:09:15 +0100 Subject: [PATCH] Implement ReverseBytes for double properly --- src/util/ByteUtil.h | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/util/ByteUtil.h b/src/util/ByteUtil.h index bc4c0ee..64579a5 100644 --- a/src/util/ByteUtil.h +++ b/src/util/ByteUtil.h @@ -2,6 +2,7 @@ #include #include +#include namespace Feather { @@ -28,6 +29,8 @@ namespace Feather inline int32_t ReverseBytes(int32_t n) { return int32_t(ReverseBytes(uint32_t(n))); } inline int64_t ReverseBytes(int64_t n) { return int64_t(ReverseBytes(uint64_t(n))); } - // FIXME: this maybe very wrong - inline double ReverseBytes(double d) { return (double)ReverseBytes((uint64_t)d); } + template + inline T ReverseBytesBitcast(T n) { return std::bit_cast(ReverseBytes(std::bit_cast(n))); } + + inline double ReverseBytes(double n) { return ReverseBytesBitcast(n); } } \ No newline at end of file