public: add float_bits_t union to access float as 32-bit signed or unsigned integer

This commit is contained in:
Alibek Omarov 2023-03-13 03:46:20 +03:00
parent da5ec56567
commit 412c635499
1 changed files with 38 additions and 0 deletions

View File

@ -22,6 +22,8 @@ GNU General Public License for more details.
#endif
#include "build.h"
#include "xash3d_types.h"
#include "const.h"
#include "com_model.h"
#include "studio.h"
@ -135,6 +137,42 @@ GNU General Public License for more details.
#define PlaneDiff(point,plane) (((plane)->type < 3 ? (point)[(plane)->type] : DotProduct((point), (plane)->normal)) - (plane)->dist)
#define bound( min, num, max ) ((num) >= (min) ? ((num) < (max) ? (num) : (max)) : (min))
// horrible cast but helps not breaking strict aliasing in mathlib
// as union type punning should be fine in C but not in C++
// so don't carry over this to C++ code
typedef union
{
float fl;
uint32_t u;
int32_t i;
} float_bits_t;
static inline uint32_t FloatAsUint( float v )
{
float_bits_t bits = { v };
return bits.u;
}
static inline int32_t FloatAsInt( float v )
{
float_bits_t bits = { v };
return bits.i;
}
static inline float IntAsFloat( int32_t i )
{
float_bits_t bits;
bits.i = i;
return bits.fl;
}
static inline float UintAsFloat( uint32_t u )
{
float_bits_t bits;
bits.u = u;
return bits.fl;
}
float rsqrt( float number );
float anglemod( float a );
word FloatToHalf( float v );