Merge pull request #1711 from demett-brcm/avoid-undefined-behaviour
Avoid undefined behaviour
This commit is contained in:
commit
5efb004d59
1 changed files with 5 additions and 1 deletions
|
|
@ -43,6 +43,7 @@
|
||||||
#else
|
#else
|
||||||
#include <cmath>
|
#include <cmath>
|
||||||
#endif
|
#endif
|
||||||
|
#include <cstdint>
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
|
|
||||||
|
|
@ -1162,8 +1163,11 @@ static void OutputDouble(TInfoSink& out, double value, TOutputTraverser::EExtraO
|
||||||
switch (extra) {
|
switch (extra) {
|
||||||
case TOutputTraverser::BinaryDoubleOutput:
|
case TOutputTraverser::BinaryDoubleOutput:
|
||||||
{
|
{
|
||||||
|
uint64_t b;
|
||||||
|
static_assert(sizeof(b) == sizeof(value), "sizeof(uint64_t) != sizeof(double)");
|
||||||
|
memcpy(&b, &value, sizeof(b));
|
||||||
|
|
||||||
out.debug << " : ";
|
out.debug << " : ";
|
||||||
long long b = *reinterpret_cast<long long*>(&value);
|
|
||||||
for (size_t i = 0; i < 8 * sizeof(value); ++i, ++b) {
|
for (size_t i = 0; i < 8 * sizeof(value); ++i, ++b) {
|
||||||
out.debug << ((b & 0x8000000000000000) != 0 ? "1" : "0");
|
out.debug << ((b & 0x8000000000000000) != 0 ? "1" : "0");
|
||||||
b <<= 1;
|
b <<= 1;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue