{"id":13713603,"url":"https://github.com/13rac1/fastmath","last_synced_at":"2025-06-28T11:34:40.649Z","repository":{"id":57533808,"uuid":"201207541","full_name":"13rac1/fastmath","owner":"13rac1","description":"Golang 8/16 bit math functions for when speed matters more than precision","archived":false,"fork":false,"pushed_at":"2021-03-06T21:40:53.000Z","size":17,"stargazers_count":15,"open_issues_count":0,"forks_count":1,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-06-20T14:13:56.056Z","etag":null,"topics":["fastled","fastled-library","go","golang","golang-library","math","tinygo","wasm","webassembly"],"latest_commit_sha":null,"homepage":"https://pkg.go.dev/github.com/13rac1/fastmath","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/13rac1.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2019-08-08T07:52:29.000Z","updated_at":"2025-05-31T11:18:07.000Z","dependencies_parsed_at":"2022-09-26T18:21:17.999Z","dependency_job_id":null,"html_url":"https://github.com/13rac1/fastmath","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/13rac1/fastmath","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/13rac1%2Ffastmath","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/13rac1%2Ffastmath/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/13rac1%2Ffastmath/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/13rac1%2Ffastmath/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/13rac1","download_url":"https://codeload.github.com/13rac1/fastmath/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/13rac1%2Ffastmath/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":262422714,"owners_count":23308741,"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":["fastled","fastled-library","go","golang","golang-library","math","tinygo","wasm","webassembly"],"created_at":"2024-08-02T23:01:40.270Z","updated_at":"2025-06-28T11:34:40.624Z","avatar_url":"https://github.com/13rac1.png","language":"Go","readme":"# FastMath for Go\n\n\u003e \"I can make things very fast if they don’t have to be correct.\" — Russ Cox\n\n8 and 16 bit math functions for when speed matters more than precision.\nPotential use cases include LED displays, 2D/3D graphics, and games.\n\n* Designed for use with [TinyGo][tinygo] and/or [WebAssembly][go-wasm].\n* Based on the [FastLED][fastled] [lib8tion][lib8ation-src] library.\n\n[tinygo]:https://tinygo.org/\n[go-wasm]:https://github.com/golang/go/wiki/WebAssembly\n[fastled]:http://fastled.io/\n[lib8ation-src]:https://raw.githubusercontent.com/FastLED/FastLED/dcbf3993/lib8tion/trig8.h\n\n## Functions\n\n* `Sin8()` / `Sin16()`\n* `Cos8()` / `Cos16()`\n* `Random8()` / `Random16()`\n* `Random8Limit()` / `Random16Limit()`\n* `Random8Range()` / `Random16Range()`\n* `Random16SetSeed()` / `Random16GetSeed()` / `Random16AddEntropy()`\n* `Scale8()` / `Scale8Video()`\n* `NScale8x3()` / `NScale8x3Video()` - Scale three 8 bit integers at the same time.\n* `Scale16()` / `Scale16By8()`\n* `QAdd8()` / `QSub8()` / `QMul8()` - Saturating non-overflowing math functions.\n* `Abs8()`\n* `Sqrt16()`\n\nNote: Functionality already well handled by the Go runtime has not be re-implemented.\n\n## Approximation Error\n\nComputer-based math functions have an error delta verses the pure mathematical\nresults. The Golang Standard Library's math functions are precise up to 64 bit\nfloats. The math functions provided by this library sacrifice additional\nprecision for speed by working with small integers.\n\n* `Sin8()` - Max Error: 1.63%, Average Error: 0.78%\n* `Sin16()` - Max Error: 0.34%, Average Error: 0.19%\n\n## Benchmarks\n\nRun on a Intel(R) Core(TM) i7-7600U CPU @ 2.80GHz.\n\n```bash\nBenchmarkStdLibFallbackSqrt-4   20000000                 50.7 ns/op\nBenchmarkStdLibDefaultSqrt-4    2000000000               0.30 ns/op\nBenchmarkSqrt16-4               200000000                9.12 ns/op\nBenchmarkStdLibRandom8-4        50000000                 25.6 ns/op\nBenchmarkRandom8-4              1000000000               2.12 ns/op\nBenchmarkStdLibSin8-4           50000000                 20.8 ns/op\nBenchmarkSin8-4                 300000000                4.07 ns/op\nBenchmarkStdLibSin16-4          50000000                 20.0 ns/op\nBenchmarkSin16-4                2000000000               0.94 ns/op\n```\n\n`Random8()`, `Sin8()` and `Sin16()` are significantly faster than using the\nequivalent Go Standard Library's Math package functions.\n\n`Sqrt16()` is compared against both the default compiled `math.Sqrt()` and a\ncopy of the fallback Standard Library `sqrt()` function. The default version is\noptimized by the Go compiler into a single instruction on the AMD64\narchitecture, so the fallback version is used for a fair comparison.\n\n## TODO\n\n* Should `Sin8()` be a lookup table? Why is it 4ns/op vs `Sin16()`@0.9ns/op?\n* Add ARM assembly implementations from upstream, benchmark difference.\n\n## License\n\nLicensed MIT\n\n© 2019 Brad Erickson\n\nBased on FastLED MIT-licensed code:\n\n© 2013 FastLED\n\nParts of test-only BSD code:\n\n© 2009 The Go Authors\n","funding_links":[],"categories":["Repositories"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2F13rac1%2Ffastmath","html_url":"https://awesome.ecosyste.ms/projects/github.com%2F13rac1%2Ffastmath","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2F13rac1%2Ffastmath/lists"}