diff options
author | Sadie Powell <sadie@witchery.services> | 2025-05-05 18:00:50 +0100 |
---|---|---|
committer | Sadie Powell <sadie@witchery.services> | 2025-05-05 21:11:51 +0100 |
commit | 937404e3118f10735875ff45a658facbf77e984d (patch) | |
tree | 4d795ce66b449005015785448498a85fe92920ab /modules | |
parent | c5ad774ce5dd51ea2e6e09374901f583b9857d7f (diff) |
Optimise the maths for the jsonrpc oversize integer workaround.
Diffstat (limited to 'modules')
-rw-r--r-- | modules/rpc/jsonrpc.cpp | 6 |
1 files changed, 2 insertions, 4 deletions
diff --git a/modules/rpc/jsonrpc.cpp b/modules/rpc/jsonrpc.cpp index 189e2b3a8..2e8753b8a 100644 --- a/modules/rpc/jsonrpc.cpp +++ b/modules/rpc/jsonrpc.cpp @@ -239,8 +239,7 @@ yyjson_mut_val *JSONRPCServiceInterface::SerializeElement(yyjson_mut_doc *doc, c }, [&doc, &elem](int64_t i) { - auto bits = std::floor(std::log2(abs(i))) + 1; - if (bits <= integer_bits) + if (std::abs(i) < (1LL << integer_bits)) { // We can fit this into an integer. elem = yyjson_mut_int(doc, i); @@ -254,8 +253,7 @@ yyjson_mut_val *JSONRPCServiceInterface::SerializeElement(yyjson_mut_doc *doc, c }, [&doc, &elem](uint64_t u) { - auto bits = std::floor(std::log2(u)) + 1; - if (bits <= integer_bits) + if (u < (1ULL << integer_bits)) { // We can fit this into an integer. elem = yyjson_mut_uint(doc, u); |