Added read/write for float (kind of hacky, assumes IEE)
This commit is contained in:
@@ -35,6 +35,18 @@ namespace io {
|
||||
return value;
|
||||
}
|
||||
|
||||
template <>
|
||||
float read(std::istream& is) {
|
||||
union {
|
||||
uint32_t a;
|
||||
float b;
|
||||
} u;
|
||||
|
||||
u.a = read_bytes<uint32_t>(is, sizeof(uint32_t));
|
||||
|
||||
return u.b;
|
||||
}
|
||||
|
||||
template<>
|
||||
size_t read(std::istream& is) {
|
||||
size_t value = 0;
|
||||
|
||||
@@ -31,6 +31,17 @@ namespace io {
|
||||
write_bytes(os, value, sizeof(T));
|
||||
}
|
||||
|
||||
template <>
|
||||
void write(std::ostream& os, float value) {
|
||||
union {
|
||||
uint32_t a;
|
||||
float b;
|
||||
} u;
|
||||
|
||||
u.b = value;
|
||||
write_bytes(os, u.a, sizeof(uint32_t));
|
||||
}
|
||||
|
||||
// Special implementation for size_t (also uint64_t, so maybe this is not that smart)
|
||||
template <>
|
||||
void write(std::ostream& os, size_t value) {
|
||||
|
||||
Reference in New Issue
Block a user