qf_math

Quick Float Math — compact, dependency-free C99 float routines as a practical stand-in for vendor libm where flash and predictable cost matter.

Use it when you already work in IEEE-754 single precision and want table-driven trig, logarithms, exponentials, sqrt, hypot, waveform helpers, and an ADSR envelope from one translation unit. Headers document worst-case error targets; the bench below scores each function against C double references and times the matching *f libm calls.

Repo: github.com/deftio/qf_math · No FPU? Sister library fr_math (fixed-point, same conceptual API family).

Accuracy & speed sweep vs libm

This table is generated by tools/qf_math_bench.c --html-table (same grids as make bench). Numbers are from the machine that last ran make docs-pages or the GitHub Actions Pages deploy — not MCU timings.

Generated UTC 2026-05-09 09:09:51Z — 10000-sample grids, 100000 outer × 100-inner timing loops; error vs C double; libm = matching *f call. Compiler: Apple LLVM 21.0.0 (clang-2100.0.123.102).

Accuracy sweep vs libm (float)

FunctionBench noteMaxMeanqf mslibm mslibm ÷ qf
qf_sin()radians; ref = sin in double0.001885% amp0.0007992% amp10.6421.392.01×
qf_cos()radians; ref = cos in double0.001887% amp0.0008006% amp10.4622.702.17×
qf_tan()excludes inputs within 0.05 rad of poles0.4535% amp0.02151% amp29.4228.640.97×
qf_acos()domain [-1, 1]; radians out0.01482% of pi0.002432% of pi94.0522.360.24×
qf_atan2()swept (y,x) magnitudes; ref = atan2 double0.04097% of pi0.01276% of pi28.6325.710.90×
qf_log2()x in (0.001, 100]; absolute Δ vs double8.104e-07 abs2.15e-07 abs19.1922.231.16×
qf_ln()x in (0.001, 100]; absolute Δ vs double6.235e-07 abs1.676e-07 abs25.5522.300.87×
qf_pow2()relative vs double; libm ref = exp2f0.000322% rel3.64e-05% rel22.4816.130.72×
qf_exp()relative vs double on grid0.0003402% rel4.163e-05% rel25.6516.280.63×
qf_sqrt()relative vs double0.0004702% rel0.0001786% rel16.086.270.39×
qf_hypot()relative vs double hypot0.0004676% rel0.0001906% rel13.3513.020.98×
qf_hypot_fast8()qf piecewise-linear; timed vs hypotf reference0.1372% rel0.05112% rel22.8913.170.58×

Error column: amp = % of ±1 output (sin/cos/tan). rel = max relative error vs double × 100. of pi = absolute radian error as % of π (acos, atan2). abs = absolute Δ vs double on the grid (log2, ln). libm ÷ qf uses total loop time; > 1 means qf_math was faster on this host (microbenchmark only; profile on your MCU).

Caveats (read before trusting the table)

Minimal include

#include "qf_math.h"

qf y = qf_sin(1.0f);    /* radians */
qf len = qf_hypot(dx, dy);