]> gitweb.factorcode.org Git - factor.git/blob - vm/float_bits.hpp
float_bits: cleaner way to cast between bits and float/double
[factor.git] / vm / float_bits.hpp
1 namespace factor {
2
3 inline static uint64_t double_bits(double x) {
4   return *(reinterpret_cast<uint64_t*>(&x));
5 }
6
7 inline static double bits_double(uint64_t y) {
8   return *(reinterpret_cast<double*>(&y));
9 }
10
11 inline static uint32_t float_bits(float x) {
12   return *(reinterpret_cast<uint32_t*>(&x));
13 }
14
15 inline static float bits_float(uint32_t y) {
16   return *(reinterpret_cast<float*>(&y));
17 }
18
19 }