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.
- Type alias
Q16, plusFP_ONE,Q16_MAX,Q16_MIN - Conversion:
f32 <-> Q16,i16 <-> Q16,q31 <-> Q16 - Arithmetic:
mul_q16,mul_n_q16,mul_f_q16,div_q16,div_n_q16,div_f_q16 - Saturating:
qadd_q16,qsub_q16,abs_q16 - Helpers:
lerp_q16,angle_to_q16,recip_q16 ScanlineInterp— accelerated per-scanline z + (u, v) interpolation
Structs§
- Scanline
Interp - 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
f32scalar. - div_
n_ q16 - Divide a Q16.16 value by a plain
i32integer. Returns 0 on division by zero. - div_q16
- Divide two Q16.16 values. Returns 0 on division by zero.
- from_
i16_ q16 - Convert
i16integer ->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
f32scalar. - mul_
n_ q16 - Multiply a Q16.16 value by a plain
i32integer (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 / vin Q16.16. - to_
i16_ q16 - Convert
Q16.16->i16integer (truncate fractional bits). - to_q16
- Convert
f32->Q16.16with correct rounding.
Type Aliases§
- Q16
- Type alias:
Q16isi32stored in Q16.16 fixed-point format.