Expand description
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.
Modules§
- serde
serde
- Additional functionality for serializing/deserializing
DivInt
structs with Serde.
Macros§
- div_int
- A compile-time constructor for
DivInt
literals.
Structs§
- DivInt
- Rational number with a compile-time denominator.
- Inferred
Denominator - A constructor for
DivInt
that infers the denominator.
Traits§
- From
F64Approx - Helper trait for converting
f64
to integer types.