summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/endian_str.cpp38
1 files changed, 38 insertions, 0 deletions
diff --git a/src/endian_str.cpp b/src/endian_str.cpp
index 15aaa36a3f..bc2f4b149c 100644
--- a/src/endian_str.cpp
+++ b/src/endian_str.cpp
@@ -43,8 +43,22 @@ namespace //anonymous
memcpy(&ret, &f, 4);
return ret;
}
+
+ void pun_int_to_double(double& d, uint64_t i)
+ {
+ memcpy(&d, &i, 8);
+ }
+
+ uint64_t pun_double_to_int(double f)
+ {
+ uint64_t ret;
+ memcpy(&ret, &f, 8);
+ return ret;
+ }
}
+//------------------------------------------------------------------------------
+
void read_little(std::istream& is, uint8_t& x)
{
is.get(reinterpret_cast<char&>(x));
@@ -94,6 +108,13 @@ void read_little(std::istream& is, float& x)
pun_int_to_float(x, tmp);
}
+void read_little(std::istream& is, double& x)
+{
+ uint64_t tmp;
+ read_little(is, tmp);
+ pun_int_to_double(x, tmp);
+}
+
//------------------------------------------------------------------------------
void read_big(std::istream& is, uint8_t& x)
@@ -145,6 +166,13 @@ void read_big(std::istream& is, float& x)
pun_int_to_float(x, tmp);
}
+void read_big(std::istream& is, double& x)
+{
+ uint64_t tmp;
+ read_big(is, tmp);
+ pun_int_to_double(x, tmp);
+}
+
//------------------------------------------------------------------------------
void write_little(std::ostream& os, uint8_t x)
@@ -194,6 +222,11 @@ void write_little(std::ostream& os, float x)
write_little(os, pun_float_to_int(x));
}
+void write_little(std::ostream& os, double x)
+{
+ write_little(os, pun_double_to_int(x));
+}
+
//------------------------------------------------------------------------------
void write_big(std::ostream& os, uint8_t x)
@@ -243,4 +276,9 @@ void write_big(std::ostream& os, float x)
write_big(os, pun_float_to_int(x));
}
+void write_big(std::ostream& os, double x)
+{
+ write_big(os, pun_double_to_int(x));
+}
+
}