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