Blob Blame History Raw
From 25f017dc28435f5df19b0de7c7f1a6e06374e04b Mon Sep 17 00:00:00 2001
From: Thomas Lin Pedersen <thomasp85@gmail.com>
Date: Thu, 14 Nov 2019 09:35:00 +0100
Subject: [PATCH] Fix #16 Do a simple and inefficient double rounding on big
 endian architecture

---
 src/encode.cpp | 8 ++++++++
 1 file changed, 8 insertions(+)

diff --git a/src/encode.cpp b/src/encode.cpp
index 4906de5..be564a2 100644
--- a/src/encode.cpp
+++ b/src/encode.cpp
@@ -7,10 +7,18 @@ static char hex8[] = "000102030405060708090A0B0C0D0E0F101112131415161718191A1B1C
 static char buffer[] = "#000000";
 static char buffera[] = "#00000000";
 
+#ifdef __BIG_ENDIAN__ 
+#include <cmath>
+inline int double2int(double d) {
+  return (int)std::round(d);
+}
+#else
 inline int double2int(double d) {
   d += 6755399441055744.0;
   return reinterpret_cast<int&>(d);
 }
+#endif
+
 inline int cap0255(int x) {
   return x < 0 ? 0 : (x > 255 ? 255 : x);
 }