8000 Fixed double conversion. · arangodb/arangodb@a43cf14 · GitHub
[go: up one dir, main page]

Skip to content

Commit a43cf14

Browse files
author
maierlars
committed
Fixed double conversion.
1 parent 63fd0b7 commit a43cf14

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

arangod/Zkd/ZkdHelper.cpp

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -429,6 +429,10 @@ struct floating_point {
429429
uint64_t base;
430430
};
431431

432+
std::ostream& operator<<(std::ostream& os, struct floating_point const& fp) {
433+
std::cout << (fp.positive ? "p" : "n") << fp.exp << "E" << fp.base;
434+
return os;
435+
}
432436

433437
auto destruct_double(double x) -> floating_point {
434438
bool positive = true;
@@ -456,20 +460,23 @@ auto construct_double(floating_point const& fp) -> double {
456460

457461
template<>
458462
auto zkd::to_byte_string_fixed_length<double>(double x) -> byte_string {
459-
460463
auto [p, exp, base] = destruct_double(x);
461464

462465
BitWriter bw;
463466
bw.append(p ? Bit::ONE : Bit::ZERO);
464467

468+
if (!p) {
469+
exp ^= (1ul << 11) - 1;
470+
base ^= (1ul << 52) - 1;
471+
}
472+
465473
bw.write_big_endian_bits(exp, 11);
466474
bw.write_big_endian_bits(base, 52);
467475

468476
return std::move(bw).str();
469477
}
470478

471479

472-
473480
template<typename T>
474481
auto zkd::from_byte_string_fixed_length(byte_string_view bs) -> T {
475482
T result = 0;
@@ -496,6 +503,11 @@ auto zkd::from_byte_string_fixed_length<double>(byte_string_view bs) -> double {
496503

497504
auto exp = r.read_big_endian_bits(11);
498505
auto base = r.read_big_endian_bits(52);
506+
if (!isPositive) {
507+
exp ^= (1ul << 11) - 1;
508+
base ^= (1ul << 52) - 1;
509+
}
510+
499511
return construct_double({isPositive, exp, base});
500512
}
501513

0 commit comments

Comments
 (0)
0