From 97397bdaffed7f7bdf97ccde20bbcd41df4e63fb Mon Sep 17 00:00:00 2001 From: Le Philousophe Date: Tue, 5 Mar 2019 19:27:52 +0100 Subject: STREAM: add read/write functions for double LE/BE --- common/stream.h | 58 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) (limited to 'common') diff --git a/common/stream.h b/common/stream.h index dfb7d6c9b2..16264a7f14 100644 --- a/common/stream.h +++ b/common/stream.h @@ -203,6 +203,31 @@ public: writeUint32BE(n); } + /** + * Write the given 64-bit floating point value stored + * in little endian(LSB first) order into the stream. + */ + FORCEINLINE void writeDoubleLE(double value) { + uint64 n; + + memcpy(&n, &value, 8); + + writeUint64LE(n); + } + + + /** + * Write the given 64-bit floating point value stored + * in big endian order into the stream. + */ + FORCEINLINE void writeDoubleBE(double value) { + uint64 n; + + memcpy(&n, &value, 8); + + writeUint64BE(n); + } + /** * Write the given string to the stream. * This writes str.size() characters, but no terminating zero byte. @@ -474,6 +499,39 @@ public: return f; } + + /** + * Read a 64-bit floating point value stored in little endian (LSB first) + * order from the stream and return it. + * Performs no error checking. The return value is undefined + * if a read error occurred (for which client code can check by + * calling err() and eos() ). + */ + FORCEINLINE double readDoubleLE() { + uint64 n = readUint64LE(); + double d; + + memcpy(&d, &n, 8); + + return d; + } + + /** + * Read a 64-bit floating point value stored in big endian + * order from the stream and return it. + * Performs no error checking. The return value is undefined + * if a read error occurred (for which client code can check by + * calling err() and eos() ). + */ + FORCEINLINE double readDoubleBE() { + uint64 n = readUint64BE(); + double d; + + memcpy(&d, &n, 8); + + return d; + } + /** * Read the specified amount of data into a malloc'ed buffer * which then is wrapped into a MemoryReadStream. -- cgit v1.2.3