mirror of
https://github.com/ElementsProject/elements.git
synced 2026-08-20 13:37:28 +02:00
Convert uses of double-serialization to {En,De}codeDouble
This commit is contained in:
parent
afd964d70b
commit
fff1cae43a
2 changed files with 46 additions and 18 deletions
|
|
@ -7,10 +7,13 @@
|
|||
#include <streams.h>
|
||||
#include <test/fuzz/FuzzedDataProvider.h>
|
||||
#include <test/fuzz/fuzz.h>
|
||||
#include <util/serfloat.h>
|
||||
#include <version.h>
|
||||
|
||||
#include <cassert>
|
||||
#include <cstdint>
|
||||
#include <cmath>
|
||||
#include <limits>
|
||||
|
||||
FUZZ_TARGET(float)
|
||||
{
|
||||
|
|
@ -19,12 +22,17 @@ FUZZ_TARGET(float)
|
|||
{
|
||||
const double d = fuzzed_data_provider.ConsumeFloatingPoint<double>();
|
||||
(void)memusage::DynamicUsage(d);
|
||||
assert(ser_uint64_to_double(ser_double_to_uint64(d)) == d);
|
||||
|
||||
CDataStream stream(SER_NETWORK, INIT_PROTO_VERSION);
|
||||
stream << d;
|
||||
double d_deserialized;
|
||||
stream >> d_deserialized;
|
||||
assert(d == d_deserialized);
|
||||
uint64_t encoded = EncodeDouble(d);
|
||||
if constexpr (std::numeric_limits<double>::is_iec559) {
|
||||
if (!std::isnan(d)) {
|
||||
uint64_t encoded_in_memory;
|
||||
std::copy((const unsigned char*)&d, (const unsigned char*)(&d + 1), (unsigned char*)&encoded_in_memory);
|
||||
assert(encoded_in_memory == encoded);
|
||||
}
|
||||
}
|
||||
double d_deserialized = DecodeDouble(encoded);
|
||||
assert(std::isnan(d) == std::isnan(d_deserialized));
|
||||
assert(std::isnan(d) || d == d_deserialized);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue