diff options
author | Pieter Wuille <pieter@wuille.net> | 2021-05-16 17:23:17 -0700 |
---|---|---|
committer | Pieter Wuille <pieter@wuille.net> | 2021-05-24 16:04:44 -0700 |
commit | 2be4cd94f4c7d92a4287971233a20d68db81c9c9 (patch) | |
tree | ed74f36c80af1916ba06071bac01f683d7fad629 /src/util/serfloat.h | |
parent | e40224d0c77674348bf0a518365208bc118f39a4 (diff) | |
download | bitcoin-2be4cd94f4c7d92a4287971233a20d68db81c9c9.tar.xz |
Add platform-independent float encoder/decoder
Diffstat (limited to 'src/util/serfloat.h')
-rw-r--r-- | src/util/serfloat.h | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/src/util/serfloat.h b/src/util/serfloat.h new file mode 100644 index 0000000000..4d912b0176 --- /dev/null +++ b/src/util/serfloat.h @@ -0,0 +1,16 @@ +// Copyright (c) 2021 The Bitcoin Core developers +// Distributed under the MIT software license, see the accompanying +// file COPYING or http://www.opensource.org/licenses/mit-license.php. + +#ifndef BITCOIN_UTIL_SERFLOAT_H +#define BITCOIN_UTIL_SERFLOAT_H + +#include <stdint.h> + +/* Encode a double using the IEEE 754 binary64 format. All NaNs are encoded as x86/ARM's + * positive quiet NaN with payload 0. */ +uint64_t EncodeDouble(double f) noexcept; +/* Reverse operation of DecodeDouble. DecodeDouble(EncodeDouble(f))==f unless isnan(f). */ +double DecodeDouble(uint64_t v) noexcept; + +#endif // BITCOIN_UTIL_SERFLOAT_H |