2016-03-01 15:47:10 +00:00
|
|
|
// "Build Engine & Tools" Copyright (c) 1993-1997 Ken Silverman
|
|
|
|
// Ken Silverman's official web site: "http://www.advsys.net/ken"
|
|
|
|
// See the included license file "BUILDLIC.TXT" for license info.
|
|
|
|
//
|
|
|
|
// This file is based on pragmas.h from Ken Silverman's original Build
|
|
|
|
// source code release and contains routines that were originally
|
|
|
|
// inline assembly but are not now.
|
|
|
|
|
|
|
|
#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
|
|
|
|
|
|
|
|
#include "xs_Float.h"
|
|
|
|
|
|
|
|
#define MAKESAFEDIVSCALE(x) \
|
|
|
|
inline SDWORD SafeDivScale##x (SDWORD a, SDWORD b) \
|
|
|
|
{ \
|
|
|
|
if ((DWORD)abs(a) >> (31-x) >= (DWORD)abs (b)) \
|
|
|
|
return (a^b)<0 ? FIXED_MIN : FIXED_MAX; \
|
|
|
|
return DivScale##x (a, b); \
|
|
|
|
}
|
|
|
|
|
|
|
|
MAKESAFEDIVSCALE(1)
|
|
|
|
MAKESAFEDIVSCALE(2)
|
|
|
|
MAKESAFEDIVSCALE(3)
|
|
|
|
MAKESAFEDIVSCALE(4)
|
|
|
|
MAKESAFEDIVSCALE(5)
|
|
|
|
MAKESAFEDIVSCALE(6)
|
|
|
|
MAKESAFEDIVSCALE(7)
|
|
|
|
MAKESAFEDIVSCALE(8)
|
|
|
|
MAKESAFEDIVSCALE(9)
|
|
|
|
MAKESAFEDIVSCALE(10)
|
|
|
|
MAKESAFEDIVSCALE(11)
|
|
|
|
MAKESAFEDIVSCALE(12)
|
|
|
|
MAKESAFEDIVSCALE(13)
|
|
|
|
MAKESAFEDIVSCALE(14)
|
|
|
|
MAKESAFEDIVSCALE(15)
|
|
|
|
MAKESAFEDIVSCALE(16)
|
|
|
|
MAKESAFEDIVSCALE(17)
|
|
|
|
MAKESAFEDIVSCALE(18)
|
|
|
|
MAKESAFEDIVSCALE(19)
|
|
|
|
MAKESAFEDIVSCALE(20)
|
|
|
|
MAKESAFEDIVSCALE(21)
|
|
|
|
MAKESAFEDIVSCALE(22)
|
|
|
|
MAKESAFEDIVSCALE(23)
|
|
|
|
MAKESAFEDIVSCALE(24)
|
|
|
|
MAKESAFEDIVSCALE(25)
|
|
|
|
MAKESAFEDIVSCALE(26)
|
|
|
|
MAKESAFEDIVSCALE(27)
|
|
|
|
MAKESAFEDIVSCALE(28)
|
|
|
|
MAKESAFEDIVSCALE(29)
|
|
|
|
MAKESAFEDIVSCALE(30)
|
|
|
|
#undef MAKESAFEDIVSCALE
|
|
|
|
|
|
|
|
inline SDWORD SafeDivScale31 (SDWORD a, SDWORD b)
|
|
|
|
{
|
|
|
|
if ((DWORD)abs(a) >= (DWORD)abs (b))
|
|
|
|
return (a^b)<0 ? FIXED_MIN : FIXED_MAX;
|
|
|
|
return DivScale31 (a, b);
|
|
|
|
}
|
|
|
|
|
|
|
|
inline SDWORD SafeDivScale32 (SDWORD a, SDWORD b)
|
|
|
|
{
|
|
|
|
if ((DWORD)abs(a) >= (DWORD)abs (b) >> 1)
|
|
|
|
return (a^b)<0 ? FIXED_MIN : FIXED_MAX;
|
|
|
|
return DivScale32 (a, b);
|
|
|
|
}
|
|
|
|
|
|
|
|
#define FixedMul MulScale16
|
|
|
|
#define FixedDiv SafeDivScale16
|
|
|
|
|
2016-03-30 14:30:22 +00:00
|
|
|
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
|
|
|
|
2016-03-30 14:30:22 +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
|
|
|
|
2016-04-01 10:22:16 +00:00
|
|
|
inline double AngleToFloat(int f)
|
|
|
|
{
|
|
|
|
return f * (90. / 0x40000000);
|
|
|
|
}
|
|
|
|
|
2016-03-30 14:30:22 +00:00
|
|
|
#define FLOAT2FIXED(f) FloatToFixed(f)
|
|
|
|
#define FIXED2FLOAT(f) float(FixedToFloat(f))
|
|
|
|
#define FIXED2DBL(f) FixedToFloat(f)
|
2016-03-01 15:47:10 +00:00
|
|
|
|
2016-03-30 14:30:22 +00:00
|
|
|
#define ANGLE2DBL(f) AngleToFloat(f)
|
2016-03-01 15:47:10 +00:00
|
|
|
|
|
|
|
#endif
|