factor/vm/float_bits.hpp

46 lines
577 B
C++
Raw Normal View History

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