numquant/
lib.rs

1//! Lossy conversion from floating point to a smaller integer type with a fixed range.
2//!
3//! ## Quantize an `f64` to a byte and back again
4//! ```
5//! use numquant::{Quantize, Quantized, U8};
6//! let original = 500.0;
7//! // Quantize the value into a byte.
8//! // Quantization supports inputs between 0 and 1000.
9//! let quantized = Quantized::<U8<0, 1000>>::from_f64(original);
10//! // Convert it back to an f64
11//! let dequantized = quantized.to_f64();
12//! // The conversion isn't lossless, but the dequantized value is close to the original:
13//! approx::assert_abs_diff_eq!(original, dequantized, epsilon = U8::<0, 1000>::max_error());
14//! ```
15
16mod int_range;
17pub mod linear;
18mod quantize;
19mod quantized;
20
21pub use int_range::{IntRange, U16, U32, U8};
22pub use quantize::Quantize;
23pub use quantized::Quantized;