Building & Testing

FR_Math has no dependencies beyond a C99 compiler and <stdint.h>. The provided build system wraps make with a few convenience scripts.

Requirements

There is no Autotools, no CMake, no Ninja, no package-manager integration. The library is small enough that the Makefile fits on one screen.

Makefile targets

TargetWhat it builds
make (default)Library + examples.
make libLibrary only (build/libfrmath.a).
make examplesExample programs into build/.
make testBuild every test binary and run the full suite.
make coverageBuild with -ftest-coverage -fprofile-arcs, run tests, emit lcov report.
make cleanRemove build/.
make cleanallRemove build/ plus editor backups.

All builds land in build/. Nothing is written inside src/.

Convenience scripts

scripts/build.sh

One-shot clean rebuild.

./scripts/build.sh              # wipe build/, build lib + examples + tests, run tests
./scripts/build.sh --no-test    # skip running the test suite
./scripts/build.sh --lib        # library only

Returns non-zero on any failure. Suitable for use from a watch script or a pre-commit hook.

scripts/coverage_report.sh

Full gcov/lcov pipeline.

./scripts/coverage_report.sh

Cleans build/, instruments every source, runs every test binary (including test_tdd for the characterization suite), and emits an HTML report under build/coverage/index.html. Also prints per-file line coverage to the console so you can copy the numbers into badge updates or release notes.

tools/make_release.sh

Guided release pipeline. Handles everything from local validation through PR, merge, tagging, GitHub Release, and package-registry publishing (PlatformIO and ESP-IDF). Each outward-facing step pauses for confirmation.

./tools/make_release.sh              # full guided release
./tools/make_release.sh --validate   # local validation only
./tools/make_release.sh --skip-cross # skip cross-compile step

In full mode the pipeline runs 17 steps: extract version, sync manifests, strict compile + tests + coverage + badges, cross-compile sanity, commit pipeline-generated changes, check git state, push branch, open PR, wait for CI, merge PR, switch to master, verify on master, tag, wait for GitHub Release, publish to PlatformIO, publish to ESP-IDF, done.

With --validate, only the local validation steps run (steps 1–4) — nothing is pushed, tagged, or published.

See release_management.md for the full step-by-step reference.

The test suite

Tests live under tests/ and are split into seven binaries to keep compile times low:

BinaryWhat it checks
fr_testRadix conversions, FR_ADD, FR_FixMuls, rounding (legacy harness).
test_comprehensiveTrig (degree, radian, BAM), log/exp, sqrt, hypot.
test_2d2D transforms, determinants, inverses.
test_overflowOverflow sentinels, saturation, edge radixes.
test_fullFull-coverage dark-corner cases and round-trips.
test_2d_completeExtended 2D: matrix composition, inverse, point transforms.
test_tddCharacterization tests pinned to bit-exact reference values.

The suite covers 99% of the library source. Every public symbol is exercised at least once.

Running a single binary

make test-comprehensive
./build/test_comprehensive

# or all of them at once
make test

Running the TDD pins after a change

test_tdd.cpp is a characterization suite. It records exact bit patterns for a sample of inputs and fails loudly if those patterns drift. Any change that modifies the numerical behavior of the library will break this suite — that’s the point.

If you intended to change the numerical behavior (e.g. you improved a polynomial approximation), update the pinned values in tests/test_tdd.cpp and note the change in release_notes.md along with any updates to the API reference precision entries.

Cross-compilation

The library has no CPU-specific code. It compiles and runs identically on all of the targets listed below. The only requirement is an integer pipeline and <stdint.h> (or define FR_NO_STDINT for bare-metal toolchains that lack it — FR_defs.h provides fallback typedefs). You do not need a floating-point unit, and you do not need libm.

TargetToolchainTested?
x86 / x86_64 Linuxgcc, clang, tccCI + Docker.
macOS arm64 / x86_64Apple clangCI.
Windows x86_64MSVC, clang-cl, MinGWManual.
AArch64 (ARM64)aarch64-linux-gnu-gccDocker.
ARM32 / Thumbarm-none-eabi-gcc, IAR, KeilDocker.
RP2040 (Cortex-M0+)arm-none-eabi-gccDocker.
STM32 (Cortex-M4)arm-none-eabi-gccDocker.
RISC-V rv64 / rv32riscv64-linux-gnu-gcc, riscv64-unknown-elf-gccDocker.
AVR (ATmega328P, ATtiny85)avr-gccDocker.
Arduino (AVR, SAMD, etc.)arduino-cliManual.
MSP430msp430-gccDocker.
Motorola 68km68k-linux-gnu-gccDocker.
Motorola 68HC11m68hc11-gccDocker.
PowerPCpowerpc-linux-gnu-gccDocker.
MIPS32mipsel-linux-gnu-gccDocker.
Xtensa LX106 (ESP8266)xtensa-lx106-elf-gccDocker.
Xtensa LX7 (ESP32-S3)xtensa-esp-elf-gccDocker (Espressif toolchain).
8051sdccManual.

Code size (.text section, compiled with -Os)

Sizes are for FR_math.c compiled with -Os. Lean = -DFR_LEAN -DFR_NO_PRINT (radian trig, inv trig, log/exp, sqrt). Core = -DFR_CORE_ONLY (+ degree trig, BAM tan, log10, hypot). Full = all features (+ print, waves, ADSR). With -ffunction-sections and linker --gc-sections, only the functions your application references are linked, so real flash usage will be smaller.

TargetLeanCoreFull
Xtensa LX7 (ESP32-S3)2.9 KB4.2 KB5.3 KB
Cortex-M4 (STM32)3.3 KB4.4 KB5.5 KB
Cortex-M0 (RP2040)3.4 KB4.5 KB5.7 KB
ARM Thumb3.4 KB4.7 KB5.9 KB
RISC-V rv644.0 KB5.5 KB6.8 KB
RISC-V rv324.1 KB5.5 KB6.8 KB
Xtensa LX106 (ESP8266)4.2 KB5.8 KB7.3 KB
ARM324.3 KB5.8 KB7.7 KB
68k4.4 KB6.2 KB7.8 KB
MIPS324.7 KB6.6 KB8.7 KB
x86-64 (GCC)4.6 KB6.1 KB8.0 KB
AArch64 (ARM64)4.8 KB6.6 KB8.7 KB
x86-325.3 KB7.2 KB9.2 KB
PowerPC5.8 KB8.0 KB10.4 KB
MSP430 (16-bit)7.8 KB10.7 KB12.8 KB
AVR (ATmega328P)9.2 KB12.8 KB15.4 KB
68HC1113.3 KB18.4 KB22.6 KB

Lean build options

Compile-time #define guards let you strip optional subsystems for ROM-constrained targets. Define them before including FR_math.h (or pass -D on the compiler command line):

DefineWhat it removesTypical savings
FR_LEANDegree trig, BAM tan, angle converters, FR_log10, FR_hypot, waves + ADSR~3.7 KB
FR_CORE_ONLYPrint + waves (shorthand for both below)~1.9 KB
FR_NO_PRINTFR_printNumF, FR_printNumD, FR_printNumH, FR_numstr~1.3 KB
FR_NO_WAVESfr_wave_* (6 shapes), fr_adsr_* (ADSR envelope), FR_HZ2BAM_INC~0.6 KB

FR_LEAN keeps only radian trig (sin, cos, tan), inverse trig, sqrt, log2, ln, exp, pow2, and arithmetic — comparable to libfixmath’s API at 4.7 KB text. FR_LEAN implies FR_NO_WAVES.

FR_CORE_ONLY is a convenience shorthand that defines both FR_NO_PRINT and FR_NO_WAVES in one step.

/* Example: headless sensor node — math only, no print, no audio */
#define FR_CORE_ONLY
#include "FR_math.h"

With -ffunction-sections and linker --gc-sections, the linker will also strip any unused functions automatically, so these guards are most useful when you include the library as a single .c file or static archive without section-level dead-code elimination.

To regenerate this table, run the Docker cross-build (requires the xelp Docker image):

scripts/crossbuild_sizes.sh

Example: RISC-V

riscv32-unknown-elf-gcc -Os -ffunction-sections -fdata-sections \
  -march=rv32imc -mabi=ilp32 \
  -Isrc -c src/FR_math.c -o FR_math.o

riscv32-unknown-elf-size FR_math.o

Example: AVR

avr-gcc -Os -mmcu=atmega328p \
  -Isrc -c src/FR_math.c -o FR_math.avr.o

avr-size FR_math.avr.o

Example: Arduino

arduino-cli compile --fqbn arduino:avr:uno examples/arduino_smoke

# Or try the focused examples:
arduino-cli compile --fqbn arduino:avr:uno examples/basic-math
arduino-cli compile --fqbn arduino:avr:uno examples/trig-functions
arduino-cli compile --fqbn arduino:avr:uno examples/wave-generators

See the code size table above for exact numbers. With linker dead-code elimination, only the functions you call are linked.

CI

GitHub Actions runs on every push and every PR. The workflow file is .github/workflows/ci.yml. It builds with strict warnings, runs make test, and caches nothing — each run starts from a clean checkout.

The CI status badge on the README links directly to the latest run.

Release checklist

  1. Create a feature branch and bump FR_MATH_VERSION_HEX in src/FR_math.h.
  2. Run ./scripts/sync_version.sh to propagate the version to all manifests (Arduino, PlatformIO, ESP-IDF, docs).
  3. Update release_notes.md, docs/releases.md, and pages/releases.html by hand.
  4. Verify llms.txt and agents.md reflect any API changes.
  5. Commit everything and run ./tools/make_release.sh. The script handles validation, PR, CI wait, merge, tagging, GitHub Release creation (via release.yml), and publishing to PlatformIO and ESP-IDF registries.

Arduino Library Manager indexes from GitHub tags automatically once the library is registered.

See Releases for the list of tagged versions and their highlights.