div-int

Crates.iodiv-int
lib.rsdiv-int
version0.1.2
sourcesrc
created_at2024-10-01 20:25:39.900533
updated_at2024-10-03 21:56:55.866504
descriptionRational numbers with a compile-time denominator.
homepage
repositoryhttps://github.com/MHordecki/div-int
max_upload_size
id1393394
size21,899
Mike Hordecki (MHordecki)

documentation

https://docs.rs/div-int

README

div-int

Crates.io API reference

Rational numbers with a compile-time denominator.

This crate exports the DivInt struct, which is a wrapper around integers that are semantically divided by a compile-time constant. It's designed for embedded applications where floats are sometimes represented as rational numbers with a known denominator.

Example

DivInt<u8, 50> is a number that's internally stored as a u8, but is semantically a rational number which value is the stored number divided by 50:

use div_int::DivInt;

let di: DivInt<u8, 50> = DivInt::from_numerator(15);
assert_eq!(di.numerator(), 15);
assert_eq!(di.to_f64(), 0.3);

Crate features

The crate is no_std by default. Optional features are:

  • serde - adds serialization support.

License: MPL-2.0

Commit count: 14

cargo fmt