File tree Expand file tree Collapse file tree 1 file changed +12
-0
lines changed Expand file tree Collapse file tree 1 file changed +12
-0
lines changed Original file line number Diff line number Diff line change @@ -318,6 +318,17 @@ double getDouble(const byte* buf, ByteOrder byteOrder) {
318318 // This algorithm assumes that the internal representation of the double
319319 // type is the 8-byte IEEE 754 binary64 format, which is common but not
320320 // required by the C++ standard.
321+ #ifdef __cpp_lib_bit_cast
322+ if (byteOrder == littleEndian)
323+ return std::bit_cast<double >(static_cast <uint64_t >(buf[7 ]) << 56 | static_cast <uint64_t >(buf[6 ]) << 48 |
324+ static_cast <uint64_t >(buf[5 ]) << 40 | static_cast <uint64_t >(buf[4 ]) << 32 |
325+ static_cast <uint64_t >(buf[3 ]) << 24 | static_cast <uint64_t >(buf[2 ]) << 16 |
326+ static_cast <uint64_t >(buf[1 ]) << 8 | static_cast <uint64_t >(buf[0 ]));
327+ return std::bit_cast<double >(static_cast <uint64_t >(buf[0 ]) << 56 | static_cast <uint64_t >(buf[1 ]) << 48 |
328+ static_cast <uint64_t >(buf[2 ]) << 40 | static_cast <uint64_t >(buf[3 ]) << 32 |
329+ static_cast <uint64_t >(buf[4 ]) << 24 | static_cast <uint64_t >(buf[5 ]) << 16 |
330+ static_cast <uint64_t >(buf[6 ]) << 8 | static_cast <uint64_t >(buf[7 ]));
331+ #else
321332 union {
322333 uint64_t ull_;
323334 double d_;
@@ -335,6 +346,7 @@ double getDouble(const byte* buf, ByteOrder byteOrder) {
335346 static_cast <uint64_t >(buf[6 ]) << 8 | static_cast <uint64_t >(buf[7 ]);
336347 }
337348 return u.d_ ;
349+ #endif
338350}
339351
340352size_t us2Data (byte* buf, uint16_t s, ByteOrder byteOrder) {
You can’t perform that action at this time.
0 commit comments