3 releases

0.1.2 Oct 3, 2024
0.1.1 Oct 1, 2024
0.1.0 Oct 1, 2024

#603 in Data structures

Download history 225/week @ 2024-09-26 213/week @ 2024-10-03 20/week @ 2024-10-10 3/week @ 2024-10-17

346 downloads per month

MPL-2.0 license

25KB
355 lines

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


lib.rs:

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. Read more.

Dependencies

~325–600KB
~11K SLoC