std1.0.0-beta-7 SafeC docs

Module dsp::fixed

#include <std/dsp/fixed.h> source

DSP / Fixed-Point Arithmetic (Q8.24) Q8.24: 8 integer bits, 24 fractional bits, stored as a 32-bit signed int. Matches 24-bit audio sample depth for sub-sample precision.

Newtypes

Fixed

Functions

fixed_from_intConvert integer to Fixed (shift left by 24).
fixed_from_floatConvert double to Fixed (multiply by 2^24 and truncate).
fixed_to_intConvert Fixed to integer (arithmetic right shift by 24 — rounds toward -∞).
fixed_to_floatConvert Fixed to double.
fixed_addAddition and subtraction (same scale, just add/sub the raw values).
fixed_sub
fixed_mulMultiplication: (a * b) >> 24 using 64-bit intermediate.
fixed_divDivision: (a << 24) / b using 64-bit intermediate.
fixed_absAbsolute value.
fixed_negNegation.
fixed_sqrtInteger square root (Newton-Raphson, 4 iterations). Argument must be >= 0.

Macros

FIXED_ONE1.0 in Q8.24
FIXED_HALF0.5 in Q8.24
FIXED_PIπ ≈ 3.14159265 in Q8.24 (3.14159265 * 16777216 ≈ 52707178)