Expand description
Compact sin/cos lookup for Q0.12 angles.
A Q0.12 angle represents one full revolution in a 12-bit
unsigned: 0..4096 maps linearly onto 0°..360°. This
matches the PSX GTE’s ONE / 4096 angle precision. The lookup
table stays compact at 256 entries, and sin_q12 linearly
interpolates between entries so every Q0.12 angle step produces a
distinct result when the table slope permits it.
Values are Q1.12 fixed-point: 4096 = 1.0, -4096 = -1.0.
§Example
ⓘ
// Rotate point (x, y) by `angle` around origin.
let s = sin_q12(angle);
let c = cos_q12(angle);
let xr = (x * c - y * s) >> 12;
let yr = (x * s + y * c) >> 12;Integer multiplication before the shift keeps the arithmetic
inside i32; >> 12 drops the Q1.12 fractional bits after the
multiplies combine.
Constants§
- SIN_
TABLE - 256-entry sine table, Q1.12 fixed-point (one revolution).