]> gitweb.factorcode.org Git - factor.git/blob - vm/float_bits.hpp
f2b061dda019a129c00eaa86ade2ab709500bc3b
[factor.git] / vm / float_bits.hpp
1 namespace factor {
2
3 /* Some functions for converting floating point numbers to binary
4 representations and vice versa */
5
6 union double_bits_pun {
7   double x;
8   u64 y;
9 };
10
11 inline static u64 double_bits(double x) {
12   double_bits_pun b;
13   b.x = x;
14   return b.y;
15 }
16
17 inline static double bits_double(u64 y) {
18   double_bits_pun b;
19   b.y = y;
20   return b.x;
21 }
22
23 union float_bits_pun {
24   float x;
25   u32 y;
26 };
27
28 inline static u32 float_bits(float x) {
29   float_bits_pun b;
30   b.x = x;
31   return b.y;
32 }
33
34 inline static float bits_float(u32 y) {
35   float_bits_pun b;
36   b.y = y;
37   return b.x;
38 }
39
40 }