This file helps AI coding agents (Claude Code, Copilot, Cursor, Cody, etc.) work effectively with this codebase. For a machine-readable API summary, see llms.txt.
FR_Math is a pure-C fixed-point math library for embedded systems. Integer-only, zero dependencies, caller-selectable radix (binary point).
src/ Core library (this is what ships)
FR_math.h Public API — all macros, function declarations, constants
FR_math.c All function implementations
FR_defs.h Type aliases (s8, s16, s32, u8, u16, u32)
FR_trig_table.h Precomputed sine table
FR_math_2D.h/.cpp Optional C++ 2D transform class
tests/ Test suite (7 programs, run via `make test`)
examples/ Arduino .ino sketches + POSIX example
docs/ Markdown documentation
pages/ HTML documentation (mirrors docs/)
scripts/ Build, release, version sync helpers
tools/ Coefficient generators (Python, C++)
dev/ Development notes and planning (not shipped)
make lib # compile library objects
make test # run all 7 test suites (27+ tests)
make examples # build POSIX example
make clean # remove build artifactsAll tests must pass before committing. Zero compiler warnings required.
- Functions:
FR_prefix for public C functions,fr_for lowercase-style functions - Macros: ALL UPPERCASE with
FR_prefix (e.g.,FR_ADD,FR_CLAMP) - Types: Use
s32,u16, etc. fromFR_defs.h— never rawintorunsigned
Most functions take a radix parameter specifying the binary point position.
Always pass radix explicitly; never hardcode a radix inside library functions.
s32 result = FR_sqrt(I2FR(2, R), R); // R is the caller's chosen radix- Declare in
src/FR_math.hinside theextern "C"block - Implement in
src/FR_math.c - Add tests in
tests/test_full_coverage.c(pass/fail) and/ortests/test_tdd.cpp(characterization) - Update
keywords.txt(KEYWORD2 for functions, LITERAL1 for macros) - Update
llms.txtwith the new function signature - Update
docs/api-reference.mdandpages/guide/api-reference.html
docs/*.md and pages/guide/*.html contain the same content in different
formats. When updating documentation, update both. The HTML files are
hand-authored (no build step).
Single source of truth: FR_MATH_VERSION_HEX in src/FR_math.h.
# After editing FR_MATH_VERSION_HEX:
./scripts/sync_version.sh # propagate to all versioned files
./scripts/sync_version.sh --check # verify everything is in syncVersioned files (all synced automatically):
src/FR_math.h,VERSION,README.md,pages/assets/site.jssrc/FR_math_2D.h,src/FR_math_2D.cpplibrary.properties,library.json,idf_component.yml,llms.txt
- Bump
FR_MATH_VERSION_HEXinsrc/FR_math.h - Run
./scripts/sync_version.sh - Run
./tools/make_release.sh(full validation gate) - Verify
llms.txtandagents.mdare current with any API changes - Commit, tag, push
The library compiles on: AVR (Arduino), ARM Cortex-M0/M4, ESP32,
RISC-V, x86/x64, MSP430, 68k, 8051. Code is 4–8 KB at -Os on
32-bit targets.
FR_Math is published to multiple package registries:
| Registry | Metadata file | Auto-publish trigger |
|---|---|---|
| Arduino Library Manager | library.properties |
GitHub release tag |
| PlatformIO | library.json |
GitHub release tag |
| ESP-IDF Component Registry | idf_component.yml + CMakeLists.txt |
GitHub release tag |
- Don't add floating-point dependencies (the whole point is integer-only)
- Don't use
floatordoublein library source (tests/examples are OK) - Don't change the
extern "C"wrapping inFR_math.h - Don't hardcode a radix inside library functions — always parameterize
- Don't add
#includedependencies beyond<stdint.h>