Loading...
Searching...
No Matches
math.h
Go to the documentation of this file.
1
44#ifndef OPENSNES_MATH_H
45#define OPENSNES_MATH_H
46
47#include <snes/types.h>
48
49/*============================================================================
50 * Fixed-Point Type and Macros
51 *============================================================================*/
52
59typedef s16 fixed;
60
71#define FIX(x) ((fixed)((x) << 8))
72
83#define UNFIX(x) ((s16)((x) >> 8))
84
95#define UNFIX_ROUND(x) ((s16)(((x) + 128) >> 8))
96
102#define FIX_FRAC(x) ((u8)((x) & 0xFF))
103
115#define FIX_MAKE(i, f) ((fixed)(((i) << 8) | (f)))
116
117/*============================================================================
118 * Fixed-Point Arithmetic
119 *============================================================================*/
120
137
154
155/*============================================================================
156 * Trigonometry (Lookup Tables)
157 *============================================================================*/
158
173
186
187/*============================================================================
188 * Integer Math (Safe Alternatives)
189 *============================================================================*/
190
207
217u16 div16(u16 dividend, u16 divisor);
218
226u16 mod16(u16 dividend, u16 divisor);
227
228/*============================================================================
229 * Utility Functions
230 *============================================================================*/
231
239
249
265
266#endif /* OPENSNES_MATH_H */
static u16 b
Definition main.c:157
static u16 a
Definition main.c:157
signed short s16
16-bit signed integer (-32768 to 32767)
Definition types.h:49
unsigned short u16
16-bit unsigned integer (0 to 65535)
Definition types.h:52
unsigned char u8
8-bit unsigned integer (0 to 255)
Definition types.h:46
fixed fixCos(u8 angle)
Get cosine value for angle.
fixed fixClamp(fixed x, fixed min, fixed max)
Clamp value to range.
u16 div16(u16 dividend, u16 divisor)
Safe 16-bit division.
fixed fixLerp(fixed a, fixed b, u8 t)
Linear interpolation.
fixed fixAbs(fixed x)
Absolute value of fixed-point.
fixed fixMul(fixed a, fixed b)
Multiply two fixed-point values.
fixed fixSin(u8 angle)
Get sine value for angle.
s16 fixed
8.8 signed fixed-point type
Definition math.h:59
fixed fixDiv(fixed a, fixed b)
Divide two fixed-point values.
u16 mod16(u16 dividend, u16 divisor)
Get remainder of division.
u16 mul16(u16 a, u16 b)
Safe 16-bit multiplication.
OpenSNES Standard Types.