Skip to main content
← PSoXide SDK guides and examples · SDK f2fec1c301f1 · All Cargo features enabled; check feature gates before use.

Module sincos

Module sincos 

Source
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).

Functions§

atan2_q12
Q0.12 angle of the vector (x, y): the inverse of sin_q12 / cos_q12, so atan2_q12(sin, cos) round-trips an angle.
cos_q12
cos(angle_q12) as a Q1.12 value, implemented as sin(angle + 90°). Input wraps modulo 4096.
sin_q12
sin(angle_q12) as a Q1.12 value. Input wraps modulo 4096.