gzdoom/src/m_fixed.h

67 lines
1.2 KiB
C
Raw Normal View History

2016-03-01 15:47:10 +00:00
#ifndef __M_FIXED__
#define __M_FIXED__
#include <stdlib.h>
#include "doomtype.h"
#if defined(__GNUC__) && defined(__i386__) && !defined(__clang__)
#include "gccinlines.h"
#elif defined(_MSC_VER) && defined(_M_IX86)
#include "mscinlines.h"
#else
#include "basicinlines.h"
#endif
__forceinline void fillshort(void *buff, unsigned int count, WORD clear)
2016-03-01 15:47:10 +00:00
{
SWORD *b2 = (SWORD *)buff;
for (unsigned int i = 0; i != count; ++i)
{
b2[i] = clear;
}
2016-03-01 15:47:10 +00:00
}
#include "xs_Float.h"
inline SDWORD FixedDiv (SDWORD a, SDWORD b)
{
if ((DWORD)abs(a) >> (31-16) >= (DWORD)abs (b))
return (a^b)<0 ? FIXED_MIN : FIXED_MAX;
return DivScale16 (a, b);
2016-03-01 15:47:10 +00:00
}
#define FixedMul MulScale16
inline fixed_t FloatToFixed(double f)
{
return xs_Fix<16>::ToFix(f);
}
inline double FixedToFloat(fixed_t f)
{
return f / 65536.;
}
2016-03-01 15:47:10 +00:00
inline unsigned FloatToAngle(double f)
{
return xs_CRoundToInt((f)* (0x40000000 / 90.));
}
inline double AngleToFloat(unsigned f)
{
return f * (90. / 0x40000000);
}
2016-03-01 15:47:10 +00:00
inline double AngleToFloat(int f)
{
return f * (90. / 0x40000000);
}
#define FLOAT2FIXED(f) FloatToFixed(f)
#define FIXED2FLOAT(f) float(FixedToFloat(f))
#define FIXED2DBL(f) FixedToFloat(f)
2016-03-01 15:47:10 +00:00
#define ANGLE2DBL(f) AngleToFloat(f)
2016-03-01 15:47:10 +00:00
#endif