Crates.io | fixed_math |
lib.rs | fixed_math |
version | 0.4.1 |
source | src |
created_at | 2023-01-17 21:13:09.953963 |
updated_at | 2023-09-07 21:40:05.29308 |
description | Some math traits and functions for `fixed` point numbers. |
homepage | |
repository | https://github.com/Zentropivity/fixed_math |
max_upload_size | |
id | 761300 |
size | 115,984 |
This library implements analytic/trigonometric functions for fixed point numbers.
Implemented functions:
sqrt
from trait Sqrt
Sqrt
is not implemented for fixed numbers with less than 2 integer bits, but there are functions that work on those types: sqrt_i1
, ...sin_cos
, sin
, cos
, tan
from trait SinCos
SinCos
is not implemented for fixed numbers with less than 8 (TODO 7) integer bits because the there are table values that would overflow on those types.sin_cos_rad
function which is very imprecise; check source code for why, feel free to fix it (its not a priority for me)There are traits and standalone functions, see examples on how to use them.
Check the examples to see about how much error this implementation produces.
Usually sqrt
has an error of around 1-2 Delta.
(Delta = the distance to the next representable number)
sin_cos
may produce bigger errors, around 1-2 decimal places.
You can check or run the benchmarks in benches
.
Here are some conclusions I've got to:
Calculation time for sin_cos varies with the fixed number's byte size.
Notes:
cordic
's sin_cos
on FixedI64
cordic
works with radians, I used the same angle valuessin_cos
of a lot bigger angle on the same number representation size2023-07-30
-`
.o+` --------
`ooo/ OS: Arch Linux x86_64
`+oooo: Host: X570 AORUS ELITE -CF
`+oooooo: Kernel: 6.4.7-arch1-1
-+oooooo+:
`/:-:++oooo+:
`/++++/+++++++: Shell: fish 3.6.1
`/++++++++++++++: Resolution: 3840x2160
`/+++ooooooooooooo/` DE: Hyprland
./ooosssso++osssssso+`
.oossssso-````/ossssss+`
-osssssso. :ssssssso. Terminal: WezTerm
:osssssss/ osssso+++. CPU: AMD Ryzen 7 5800X (16) @ 3.800GHz
/ossssssss/ +ssssooo/- GPU: AMD ATI Radeon RX 7900 XT/7900 XTX
`/ossssso+/:- -:/+osssso+- Memory: 32014MiB
`+sso+:-` `.-/+oso:
`++:. `-/+/
.` `/
Performance is different now and without native cpu features:
With native cpu features : RUSTFLAGS="-C target-cpu=native" cargo bench
:
Notes:
All code in this repository is dual-licensed under either:
at your option.
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.
We use code modified from cordic, licensed as BSD-3-Clause: