OpenSNES
Modern Open-Source SNES Development SDK
Loading...
Searching...
No Matches
math.h
Go to the documentation of this file.
1
50
51#ifndef OPENSNES_MATH_H
52#define OPENSNES_MATH_H
53
54#include <snes/types.h>
55
56/* Removed on 2026-10-05 (1.0 plan, lot C): ease_in_quad, ease_out_quad.
57 * The replacements are in docs/UPGRADING.md; `make check-upgrade` names them. */
58
59/*============================================================================
60 * Fixed-Point Type and Macros
61 *============================================================================*/
62
69typedef s16 fixed;
70
86#define FIX(x) ((fixed)(s16)((u16)(x) << 8))
87
100#define UNFIX(x) ((s16)((x) >> 8))
101
112#define UNFIX_ROUND(x) ((s16)(((s32)(x) + 128) >> 8)) /* 32-bit sum: x + 128 overflowed s16 from 127.5 (until 2026-10-03) */
113
119#define FIX_FRAC(x) ((u8)((x) & 0xFF))
120
132#define FIX_MAKE(i, f) ((fixed)(((i) << 8) | (f)))
133
134/*============================================================================
135 * Fixed-Point Arithmetic
136 *============================================================================*/
137
166
183
184/*============================================================================
185 * Trigonometry (Lookup Tables)
186 *============================================================================*/
187
204
217
218/*============================================================================
219 * Integer Math (Safe Alternatives)
220 *============================================================================*/
221
240
254u16 div16(u16 dividend, u16 divisor);
255
267u16 mod16(u16 dividend, u16 divisor);
268
269/*============================================================================
270 * Utility Functions
271 *============================================================================*/
272
280
290
309
310/*============================================================================
311 * Square Root and Inverse Trigonometry
312 *============================================================================*/
313
337
361
399
400/*============================================================================
401 * Easing Curves (B6 final, 2026-05-22)
402 *============================================================================*/
403
425
435
436#endif /* OPENSNES_MATH_H */
static u16 b
Definition main.c:156
static u16 a
Definition main.c:156
signed short s16
16-bit signed integer (-32768 to 32767)
Definition types.h:50
unsigned short u16
16-bit unsigned integer (0 to 65535)
Definition types.h:53
unsigned char u8
8-bit unsigned integer (0 to 255)
Definition types.h:47
fixed fixCos(u8 angle)
Get cosine value for angle.
fixed fixClamp(fixed x, fixed min, fixed max)
Clamp value to range.
fixed fixSqrt(fixed x)
Square root in 8.8 fixed-point.
u16 div16(u16 dividend, u16 divisor)
Safe 16-bit division.
u8 easeOutQuad(u8 t)
Ease-out quadratic: 1 - (1-t)² curve, output [0, 255].
u16 sqrt16(u16 n)
Integer square root.
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.
u8 atan2_8(s16 dy, s16 dx)
8-bit two-argument arctangent
s16 fixed
8.8 signed fixed-point type
Definition math.h:69
fixed fixDiv(fixed a, fixed b)
Divide two fixed-point values.
u16 mod16(u16 dividend, u16 divisor)
Get remainder of division.
fixed fixLerp(fixed a, fixed b, u16 t)
Linear interpolation.
u16 mul16(u16 a, u16 b)
Safe 16-bit multiplication.
u8 easeInQuad(u8 t)
Ease-in quadratic: t² curve, output [0, 255].
static u16 angle
Mode 7 ground: 9-tile prefab track (original art).
Definition main.c:46
OpenSNES Standard Types.