Rust library for general purpose fixed point arithmetic
Go to file
Sven Vogel 3295b67070 implementation can be customized through macro 2023-05-04 18:20:14 +02:00
.idea added basic fixed point 2023-04-23 21:05:02 +02:00
src implementation can be customized through macro 2023-05-04 18:20:14 +02:00
.gitignore added basic fixed point 2023-04-23 21:05:02 +02:00
Cargo.toml added basic fixed point 2023-04-23 21:05:02 +02:00
LICENSE Initial commit 2023-04-22 10:21:38 +00:00
README.md implementation can be customized through macro 2023-05-04 18:20:14 +02:00

README.md

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::

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