{"id":25300114,"url":"https://github.com/deftio/fr_math","last_synced_at":"2026-04-19T23:10:01.384Z","repository":{"id":148290194,"uuid":"140536435","full_name":"deftio/fr_math","owner":"deftio","description":"Fixed Radix Math library for embedded systems (opt for speed)","archived":false,"fork":false,"pushed_at":"2024-04-15T19:04:10.000Z","size":256,"stargazers_count":17,"open_issues_count":0,"forks_count":2,"subscribers_count":1,"default_branch":"master","last_synced_at":"2024-04-15T20:25:14.005Z","etag":null,"topics":["c","embedded","embedded-c","embedded-math","embedded-systems","fixed-point","high-performance","integer-arithmetic","math","microcontroller-firmware","no-floating-point"],"latest_commit_sha":null,"homepage":"","language":"C","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"bsd-2-clause","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/deftio.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null}},"created_at":"2018-07-11T07:14:38.000Z","updated_at":"2023-09-06T14:06:56.000Z","dependencies_parsed_at":null,"dependency_job_id":"e2968d4e-3550-438c-8784-8b2d74cffc8b","html_url":"https://github.com/deftio/fr_math","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/deftio%2Ffr_math","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/deftio%2Ffr_math/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/deftio%2Ffr_math/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/deftio%2Ffr_math/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/deftio","download_url":"https://codeload.github.com/deftio/fr_math/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":238603659,"owners_count":19499490,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["c","embedded","embedded-c","embedded-math","embedded-systems","fixed-point","high-performance","integer-arithmetic","math","microcontroller-firmware","no-floating-point"],"created_at":"2025-02-13T05:38:25.640Z","updated_at":"2026-04-19T23:10:01.369Z","avatar_url":"https://github.com/deftio.png","language":"C","funding_links":[],"categories":[],"sub_categories":[],"readme":"[![License](https://img.shields.io/badge/License-BSD%202--Clause-blue.svg)](https://opensource.org/licenses/BSD-2-Clause)\r\n[![CI](https://github.com/deftio/fr_math/actions/workflows/ci.yml/badge.svg)](https://github.com/deftio/fr_math/actions/workflows/ci.yml)\r\n[![Coverage](https://img.shields.io/badge/coverage-99%25-brightgreen.svg)](#building-and-testing)\r\n[![Docs](https://img.shields.io/badge/docs-online-blue.svg)](https://deftio.github.io/fr_math/)\r\n[![Version](https://img.shields.io/badge/version-2.0.2-blue.svg)](release_notes.md)\r\n\r\n# FR_Math: A C Language Fixed-Point Math Library for Embedded Systems\r\n\r\nFR_Math is a compact, integer-only fixed-point math library built for\r\nsystems where floating point is too slow, too big, or unavailable. Designed for embedded targets ranging from\r\nlegacy 16 MHz 68k processors to modern Cortex-M and RISC-V cores, it\r\nprovides a full suite of math primitives — trigonometry, logarithms,\r\nroots, transforms, and signal generators — while remaining\r\ndeterministic, portable, and small. Unlike traditional fixed-point\r\nlibraries, FR_Math lets the caller choose the binary point per\r\noperation, trading precision and range explicitly instead of locking\r\ninto a single format. Pure C (C99/C11/C17) with an optional C++\r\n2D-transform wrapper. Compiles under Arduino. Zero dependencies\r\nbeyond `\u003cstdint.h\u003e`.\r\n\r\n### Library size (FR_math.c only, `-Os`)\r\n\r\n| Target | Code (text) |\r\n|--------|-------------|\r\n| Cortex-M0 (Thumb-1) | 4.2 KB |\r\n| Cortex-M4 (Thumb-2) | 4.1 KB |\r\n| ESP32 (Xtensa) | 4.6 KB |\r\n| 68k | 5.5 KB |\r\n| x86-64 | 5.8 KB |\r\n| RISC-V 32 (rv32im) | 6.5 KB |\r\n| x86-32 | 7.2 KB |\r\n| MSP430 (16-bit) | 8.4 KB |\r\n| 8051 (SDCC) | 20.4 KB * |\r\n\r\nSizes are code-only (text section). The optional 2D module adds ~1 KB.\r\n\\* 8051 and MSP430 are 8/16-bit — every 32-bit operation expands to multiple instructions.\r\nSee [`docker/`](docker/) for the cross-compile setup.\r\n\r\n### Measured accuracy\r\n\r\nErrors below are measured at Q16.16 (s15.16). All functions accept any\r\nradix — Q16.16 is just the reference point for the table.\r\n\r\n| Function | Max error | Note |\r\n|---|---|---|\r\n| sin / cos | 5 LSB (~7.7e-5) | Exact at 0, 90, 180, 270 |\r\n| sqrt | ≤ 0.5 LSB | Round-to-nearest |\r\n| log2 | ≤ 4 LSB | 65-entry mantissa table |\r\n| pow2 | ≤ 1 LSB (integers exact) | 65-entry fraction table |\r\n| ln, log10 | ≤ 4 LSB | Via FR_MULK28 from log2 |\r\n| hypot (exact) | ≤ 0.5 LSB | 64-bit intermediate |\r\n| hypot_fast (4-seg) | 0.34% | Shift-only, no multiply |\r\n| hypot_fast8 (8-seg) | 0.10% | Shift-only, no multiply |\r\n\r\n### What's in the box\r\n\r\n| Area | Functions |\r\n|---|---|\r\n| Arithmetic | `FR_ADD`, `FR_SUB`, `FR_DIV`, `FR_DIV32`, `FR_MOD`, `FR_FixMuls`, `FR_FixMulSat`, `FR_CHRDX` |\r\n| Utility | `FR_MIN`, `FR_MAX`, `FR_CLAMP`, `FR_ABS`, `FR_SGN` |\r\n| Trig (integer deg) | `FR_Sin`, `FR_Cos`, `FR_Tan`, `FR_SinI`, `FR_CosI`, `FR_TanI` |\r\n| Trig (radian/BAM) | `fr_sin`, `fr_cos`, `fr_tan`, `fr_sin_bam`, `fr_cos_bam`, `fr_sin_deg`, `fr_cos_deg` |\r\n| Inverse trig | `FR_atan`, `FR_atan2`, `FR_asin`, `FR_acos` |\r\n| Log / exp | `FR_log2`, `FR_ln`, `FR_log10`, `FR_pow2`, `FR_EXP`, `FR_POW10`, `FR_EXP_FAST`, `FR_POW10_FAST`, `FR_MULK28` |\r\n| Roots | `FR_sqrt`, `FR_hypot`, `FR_hypot_fast`, `FR_hypot_fast8` |\r\n| Wave generators | `fr_wave_sqr`, `fr_wave_pwm`, `fr_wave_tri`, `fr_wave_saw`, `fr_wave_tri_morph`, `fr_wave_noise` |\r\n| Envelope | `fr_adsr_init`, `fr_adsr_trigger`, `fr_adsr_release`, `fr_adsr_step` |\r\n| 2D transforms | `FR_Matrix2D_CPT` (mul, add, sub, det, inv, setrotate, XFormPtI, XFormPtI16) |\r\n| Formatted output | `FR_printNumD`, `FR_printNumF`, `FR_printNumH`, `FR_numstr` |\r\n\r\n## Quick start\r\n\r\n```bash\r\ngit clone https://github.com/deftio/fr_math.git\r\ncd fr_math\r\nmake lib       # build static library\r\nmake test      # run all tests (coverage, TDD characterization, 2D)\r\n```\r\n\r\n## Quick taste\r\n\r\n```c\r\n#include \"FR_math.h\"\r\n\r\n#define R 16  /* work at radix 16 (s15.16) throughout */\r\n\r\ns32 pi    = FR_NUM(3, 14159, 5, R);       /* pi at radix 16             */\r\ns32 c45   = FR_CosI(45);                  /* cos 45 deg = 0.7071 (s15.16) */\r\ns32 root2 = FR_sqrt(I2FR(2, R), R);       /* sqrt(2)    = 1.4142        */\r\ns32 lg    = FR_log2(I2FR(1000, R), R, R); /* log2(1000) ~ 9.97          */\r\ns32 ex    = FR_EXP(I2FR(1, R), R);        /* e^1        ~ 2.7183        */\r\n```\r\n\r\n## Documentation\r\n\r\nThe full docs ship in two forms — pick whichever fits how you read.\r\n\r\n**Browser (rendered HTML):**\r\n\r\n- **Online:** \u003chttps://deftio.github.io/fr_math/\u003e\r\n- **Local:** [pages/index.html](pages/index.html) — static HTML/CSS/JS, no build step.\r\n\r\n**Terminal / editor (plain markdown):**\r\n\r\n- [docs/README.md](docs/README.md) — same content as plain markdown.\r\n  - [getting-started.md](docs/getting-started.md) | [fixed-point-primer.md](docs/fixed-point-primer.md) | [api-reference.md](docs/api-reference.md)\r\n  - [examples.md](docs/examples.md) | [building.md](docs/building.md) | [releases.md](docs/releases.md)\r\n\r\n## History\r\n\r\nFR_Math has been in service since 2000, originally built for graphics\r\ntransforms on 16 MHz 68k Palm Pilots. It shipped inside Trumpetsoft's\r\n*Inkstorm* on PalmOS, then moved forward through ARM, x86, MIPS,\r\nRISC-V, and various 8/16-bit embedded targets. v2.0.2 is the current\r\nrelease with a full test suite, bit-exact numerical specification, and\r\nCI on every push.\r\n\r\n## License\r\n\r\nBSD-2-Clause — see [LICENSE.txt](LICENSE.txt).\r\n(c) 2000-2026 M. Chatterjee\r\n\r\n## For AI coding agents\r\n\r\n- [llms.txt](llms.txt) — machine-readable API summary\r\n- [agents.md](agents.md) — conventions, build commands, and contribution guide for coding agents\r\n\r\n## Version\r\n\r\n2.0.2 — see [release_notes.md](release_notes.md) for the v1 → v2\r\nmigration guide, numerical fixes, and new functionality.\r\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdeftio%2Ffr_math","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdeftio%2Ffr_math","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdeftio%2Ffr_math/lists"}