mirror of
https://github.com/Mauler125/r5sdk.git
synced 2025-02-09 19:15:03 +01:00
Floating point bitwise functions are now inline, also implemented a 'PopCount' function, which replicates the '__popcnt' instruction, but does not require the CPU to feature the instruction. This was mainly added as the SDK launcher doesn't check the CPU for SSSe3/popcnt, as it doesn't involve any instruction sets past SSE2.
53 lines
1.3 KiB
C
53 lines
1.3 KiB
C
#ifndef MATHLIB_FBITS_H
|
|
#define MATHLIB_FBITS_H
|
|
//=============================================================================//
|
|
//
|
|
// Purpose: look for NANs, infinities, and underflows.
|
|
//
|
|
//=============================================================================//
|
|
|
|
//-----------------------------------------------------------------------------
|
|
// This follows the ANSI/IEEE 754-1985 standard
|
|
//-----------------------------------------------------------------------------
|
|
inline unsigned long& FloatBits(float& f)
|
|
{
|
|
return *reinterpret_cast<unsigned long*>(&f);
|
|
}
|
|
|
|
inline unsigned long const& FloatBits(float const& f)
|
|
{
|
|
return *reinterpret_cast<unsigned long const*>(&f);
|
|
}
|
|
|
|
inline float BitsToFloat(unsigned long i)
|
|
{
|
|
return *reinterpret_cast<float*>(&i);
|
|
}
|
|
|
|
inline bool IsFinite(float f)
|
|
{
|
|
return ((FloatBits(f) & 0x7F800000) != 0x7F800000);
|
|
}
|
|
|
|
inline unsigned long FloatAbsBits(float f)
|
|
{
|
|
return FloatBits(f) & 0x7FFFFFFF;
|
|
}
|
|
|
|
inline float FloatMakePositive(float f)
|
|
{
|
|
return fabsf(f); // was since 2002: BitsToFloat( FloatBits(f) & 0x7FFFFFFF ); fixed in 2010
|
|
}
|
|
|
|
inline float FloatNegate(float f)
|
|
{
|
|
return -f; //BitsToFloat( FloatBits(f) ^ 0x80000000 );
|
|
}
|
|
|
|
#define FLOAT32_NAN_BITS (unsigned int)0x7FC00000 // NaN!
|
|
#define FLOAT32_NAN BitsToFloat( FLOAT32_NAN_BITS )
|
|
|
|
#define VEC_T_NAN FLOAT32_NAN
|
|
|
|
#endif // MATHLIB_FBITS_H
|