MCPcopy Create free account
hub / github.com/Exiv2/exiv2 / d2Data

Function d2Data

src/types.cpp:426–456  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

424}
425
426size_t d2Data(byte* buf, double d, ByteOrder byteOrder) {
427 // This algorithm assumes that the internal representation of the double
428 // type is the 8-byte IEEE 754 binary64 format, which is common but not
429 // required by the C++ standard.
430 union {
431 uint64_t ull_;
432 double d_;
433 } u;
434 u.d_ = d;
435 uint64_t m = 0xff;
436 if (byteOrder == littleEndian) {
437 buf[0] = static_cast<byte>(u.ull_ & m);
438 buf[1] = static_cast<byte>((u.ull_ & (m << 8)) >> 8);
439 buf[2] = static_cast<byte>((u.ull_ & (m << 16)) >> 16);
440 buf[3] = static_cast<byte>((u.ull_ & (m << 24)) >> 24);
441 buf[4] = static_cast<byte>((u.ull_ & (m << 32)) >> 32);
442 buf[5] = static_cast<byte>((u.ull_ & (m << 40)) >> 40);
443 buf[6] = static_cast<byte>((u.ull_ & (m << 48)) >> 48);
444 buf[7] = static_cast<byte>((u.ull_ & (m << 56)) >> 56);
445 } else {
446 buf[0] = static_cast<byte>((u.ull_ & (m << 56)) >> 56);
447 buf[1] = static_cast<byte>((u.ull_ & (m << 48)) >> 48);
448 buf[2] = static_cast<byte>((u.ull_ & (m << 40)) >> 40);
449 buf[3] = static_cast<byte>((u.ull_ & (m << 32)) >> 32);
450 buf[4] = static_cast<byte>((u.ull_ & (m << 24)) >> 24);
451 buf[5] = static_cast<byte>((u.ull_ & (m << 16)) >> 16);
452 buf[6] = static_cast<byte>((u.ull_ & (m << 8)) >> 8);
453 buf[7] = static_cast<byte>(u.ull_ & m);
454 }
455 return 8;
456}
457
458void hexdump(std::ostream& os, const byte* buf, size_t len, size_t offset) {
459 const std::string::size_type pos = 8 + 16 * 3 + 2;

Callers 1

toDataFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected