Skip to main content

Module fixed_point

Module fixed_point 

Source
Expand description

Q16.16 fixed-point math.

A saturating fixed-point number format (i32, 16 fractional bits) for pipelines that can’t afford float math (no FPU, or the accuracy/latency trade-off isn’t worth it): rasterizer transforms, angle math, scanline interpolation. Complements the q7/q15/q31/q63 aliases in crate::types, which are narrower fixed-point formats aimed at CMSIS-DSP-style signal processing rather than screen-space geometry.

Structs§

ScanlineInterp
Per-scanline interpolator for z-buffer depth and (u, v) texture coordinates.

Constants§

FP_ONE
1.0 in Q16.16 representation.
FP_SHIFT
Fractional bit count for Q16.16.
Q16_MAX
Maximum positive value of a Q16.16 number (same as i32::MAX).
Q16_MIN
Minimum value of a Q16.16 number (same as i32::MIN).

Functions§

abs_q16
Absolute value of a Q16.16 number.
angle_to_q16
Convert an angle in degrees to Q16.16 radians.
div_f_q16
Divide a Q16.16 value by an f32 scalar.
div_n_q16
Divide a Q16.16 value by a plain i32 integer. Returns 0 on division by zero.
div_q16
Divide two Q16.16 values. Returns 0 on division by zero.
from_i16_q16
Convert i16 integer -> Q16.16 (shift left 16).
from_q16
Convert Q16.16 -> f32.
lerp_q16
Linear interpolation in Q16.16: a + (b - a) * t / denom.
mul_f_q16
Multiply a Q16.16 value by an f32 scalar.
mul_n_q16
Multiply a Q16.16 value by a plain i32 integer (no fractional scaling).
mul_q16
Multiply two Q16.16 values. Uses i64 intermediate (SMULL on Cortex-M).
q16_to_q31
Reinterpret Q16.16 as Q31 by shifting left 16 bits (use i64 to avoid overflow).
q31_to_q16
Reinterpret a Q31 value as Q16.16 by shifting right 15 bits.
qadd_q16
Saturating add: clamps the result to [i32::MIN, i32::MAX].
qsub_q16
Saturating subtract: clamps the result to [i32::MIN, i32::MAX].
recip_q16
Fast reciprocal approximation: 1.0 / v in Q16.16.
to_i16_q16
Convert Q16.16 -> i16 integer (truncate fractional bits).
to_q16
Convert f32 -> Q16.16 with correct rounding.

Type Aliases§

Q16
Type alias: Q16 is i32 stored in Q16.16 fixed-point format.