factor/vm/float_bits.hpp

41 lines
607 B
C++
Raw Normal View History

namespace factor {
2009-05-04 02:46:13 -04:00
2009-05-02 05:04:19 -04:00
/* Some functions for converting floating point numbers to binary
representations and vice versa */
2009-05-04 05:50:24 -04:00
union double_bits_pun {
double x;
uint64_t y;
2009-05-04 05:50:24 -04:00
};
2009-05-02 05:04:19 -04:00
inline static uint64_t double_bits(double x) {
double_bits_pun b;
b.x = x;
return b.y;
2009-05-02 05:04:19 -04:00
}
inline static double bits_double(uint64_t y) {
double_bits_pun b;
b.y = y;
return b.x;
2009-05-02 05:04:19 -04:00
}
2009-05-04 05:50:24 -04:00
union float_bits_pun {
float x;
uint32_t y;
2009-05-04 05:50:24 -04:00
};
2009-05-02 05:04:19 -04:00
inline static uint32_t float_bits(float x) {
float_bits_pun b;
b.x = x;
return b.y;
2009-05-02 05:04:19 -04:00
}
inline static float bits_float(uint32_t y) {
float_bits_pun b;
b.y = y;
return b.x;
2009-05-02 05:04:19 -04:00
}
2009-05-04 02:46:13 -04:00
}