mirror of
https://github.com/DrBeef/Raze.git
synced 2024-11-15 17:01:51 +00:00
86166f5e67
Revert "- `xs_Float.h`: Add `getint()` getter to `_xs_doubleints` struct." Revert "- SW: When adjusting horizon in `DoPlayerDeathHoriz()`, just use integer horizon values and not Q16.16." Revert "- Duke (RR): Clean up some unnecessary `FixedToFloat()` usage with the `fixedhoriz` `asbuildf()` method." Revert "- `binaryangle.h`: Use `constexpr` on inline functions where it was previously not possible to do so." Revert "- `m_fixed.h`: Use `constexpr` on inline functions where it was previously not possible to do so." Revert "- `xs_Float.h`: Convert header to `constexpr`." This does nor work as it violates the constexpr rules for unions. The code will error out on compilation for accessing an inactive member of a union.
59 lines
1.7 KiB
C
59 lines
1.7 KiB
C
#ifndef __M_FIXED__
|
|
#define __M_FIXED__
|
|
|
|
#include <stdlib.h>
|
|
#include <stdint.h>
|
|
#include "basics.h"
|
|
|
|
|
|
__forceinline constexpr int32_t MulScale(int32_t a, int32_t b, int32_t shift) { return (int32_t)(((int64_t)a * b) >> shift); }
|
|
__forceinline constexpr double MulScaleF(double a, double b, int32_t shift) { return (a * b) * (1. / (uint32_t(1) << shift)); }
|
|
__forceinline constexpr int32_t DMulScale(int32_t a, int32_t b, int32_t c, int32_t d, int32_t shift) { return (int32_t)(((int64_t)a * b + (int64_t)c * d) >> shift); }
|
|
__forceinline constexpr int32_t TMulScale(int32_t a, int32_t b, int32_t c, int32_t d, int32_t e, int32_t f, int32_t shift) { return (int32_t)(((int64_t)a * b + (int64_t)c * d + (int64_t)e * f) >> shift); }
|
|
__forceinline constexpr int32_t DivScale(int32_t a, int32_t b, int shift) { return (int32_t)(((int64_t)a << shift) / b); }
|
|
__forceinline constexpr int64_t DivScaleL(int64_t a, int64_t b, int shift) { return ((a << shift) / b); }
|
|
|
|
#include "xs_Float.h"
|
|
|
|
inline fixed_t FloatToFixed(double f)
|
|
{
|
|
return xs_Fix<16>::ToFix(f);
|
|
}
|
|
|
|
inline constexpr fixed_t IntToFixed(int32_t f)
|
|
{
|
|
return f << FRACBITS;
|
|
}
|
|
|
|
inline constexpr double FixedToFloat(fixed_t f)
|
|
{
|
|
return f * (1/65536.);
|
|
}
|
|
|
|
inline constexpr int32_t FixedToInt(fixed_t f)
|
|
{
|
|
return (f + FRACUNIT/2) >> FRACBITS;
|
|
}
|
|
|
|
inline unsigned FloatToAngle(double f)
|
|
{
|
|
return xs_CRoundToInt((f)* (0x40000000 / 90.));
|
|
}
|
|
|
|
inline constexpr double AngleToFloat(unsigned f)
|
|
{
|
|
return f * (90. / 0x40000000);
|
|
}
|
|
|
|
inline constexpr double AngleToFloat(int f)
|
|
{
|
|
return f * (90. / 0x40000000);
|
|
}
|
|
|
|
#define FLOAT2FIXED(f) FloatToFixed(f)
|
|
#define FIXED2FLOAT(f) float(FixedToFloat(f))
|
|
#define FIXED2DBL(f) FixedToFloat(f)
|
|
|
|
#define ANGLE2DBL(f) AngleToFloat(f)
|
|
|
|
#endif
|