41 lines
1.0 KiB
Markdown
41 lines
1.0 KiB
Markdown
# staticdot
|
|
|
|
Rust library for general purpose fixed point arithmetic.
|
|
|
|
This library exposes the functionality to implement custom fixed point arithmetic
|
|
through the use of macros.
|
|
|
|
The most important macro is `impl_fixed_point`. This macro requires a name for the new types name, a raw type which will store the actual fixed point data
|
|
and the number of bits to use for the fraction.
|
|
The raw type used to store the fixed point data should be a primitive type of either:
|
|
* usize
|
|
* isize
|
|
* u8
|
|
* u16
|
|
* u32
|
|
* u64
|
|
* i8
|
|
* i16
|
|
* i32
|
|
* i64
|
|
|
|
Theoretically any type can be used if it implements the required traits.
|
|
|
|
Quick start example::
|
|
```rust
|
|
impl_fixed_point!(Fixed64_32, i64, 32);
|
|
|
|
fn main() {
|
|
let a = Fixed64_32::ZERO;
|
|
let b = Fixed64_32::from(3);
|
|
|
|
let c = a + b * Fixed64_32::from(4.5);
|
|
|
|
println!("{}", Into::<f32>::into(c));
|
|
}
|
|
```
|
|
|
|
## TODO
|
|
* add support for special functions such as sin(), sqrt(), ln()
|
|
* add macro for converting between different formats
|
|
* make precision retain shifts in operations customizable |