pub struct Quire<const N: u32, const ES: u32, const SIZE: usize>(/* private fields */);Expand description
A quire, for a posit type with N bits and ES exponent bits, which is SIZE bytes long.
A quire is a fixed-point accumulator that enables sums and dot products of posits to be calculated with no intermediate rounding whatsoever. This has tremendous practical uses, from solving systems of equations to evaluating neural networks.
The SIZE is bounded from below based on the minimum size necessary to hold the product of two
posits. Above this, the more extra space, the more terms can be accumulated without the risk
of overflow (in practice the standard suggests ≈30 extra bits, corresponding to over a billion
terms). It is also required to be a multiple of 8 (64 bits) for performance reasons
(this requirement will be relaxed in the future).
If the quire SIZE is smaller than the minimum size necessary for an N
bit posit with ES exponent bits, or if that size is not a multiple of 8, a compilation
error is raised.
Type aliases are provided at the crate root for the quire types defined in the standard.
§Example
// A 256-bit (32-byte) quire for a posit with 16 bits and 1 exponent bit
type Foo = Quire<16, 1, 32>;
// Compute sums and products in the quire with *no* loss of precision.
let mut quire = q16::ZERO;
quire += p16::MAX;
quire += p16::round_from(0.1);
quire -= p16::MAX;
let result: p16 = (&quire).round_into(); // Only the final step rounds
// Correct result with the quire, no issues with rounding errors.
assert_eq!(result, p16::round_from(0.1));
// The same sum without the quire would give a wrong result, due to double rounding.
let posit = (p16::MAX + p16::round_from(0.1)) - p16::MAX;
assert_eq!(posit, p16::ZERO);Implementations§
Source§impl<const N: u32, const ES: u32, const SIZE: usize> Quire<N, ES, SIZE>
impl<const N: u32, const ES: u32, const SIZE: usize> Quire<N, ES, SIZE>
Sourcepub const PROD_LIMIT: u32
pub const PROD_LIMIT: u32
The minimum number of operations on the quire that can lead to overflow is
2 PROD_LIMIT; any number of [Self::add_prod] calls
smaller than that is guaranteed not to overflow.
§Example
assert_eq!(q32::PROD_LIMIT, 31); // Can do at least 2^31 - 1 products without overflowTrait Implementations§
Source§impl<const N: u32, const ES: u32, Int: Int, const SIZE: usize> AddAssign<&Posit<N, ES, Int>> for Quire<N, ES, SIZE>
impl<const N: u32, const ES: u32, Int: Int, const SIZE: usize> AddAssign<&Posit<N, ES, Int>> for Quire<N, ES, SIZE>
Source§impl<const N: u32, const ES: u32, Int: Int, const SIZE: usize> AddAssign<Posit<N, ES, Int>> for Quire<N, ES, SIZE>
impl<const N: u32, const ES: u32, Int: Int, const SIZE: usize> AddAssign<Posit<N, ES, Int>> for Quire<N, ES, SIZE>
Source§impl<const N: u32, const ES: u32, Int: Int, const SIZE: usize> From<Posit<N, ES, Int>> for Quire<N, ES, SIZE>
impl<const N: u32, const ES: u32, Int: Int, const SIZE: usize> From<Posit<N, ES, Int>> for Quire<N, ES, SIZE>
Source§impl<const N: u32, const ES: u32, Int: Int, const SIZE: usize> RoundFrom<&Quire<N, ES, SIZE>> for Posit<N, ES, Int>
impl<const N: u32, const ES: u32, Int: Int, const SIZE: usize> RoundFrom<&Quire<N, ES, SIZE>> for Posit<N, ES, Int>
Source§fn round_from(value: &Quire<N, ES, SIZE>) -> Self
fn round_from(value: &Quire<N, ES, SIZE>) -> Self
Round a quire back to a posit. This is the final step to do after a series of calculations in the quire, and the only step that actually rounds.
Standard: “qToP”.
§Example
let mut quire = q16::from(p16::MAX);
quire += p16::round_from(0.1);
quire -= p16::MAX;
let result: p16 = (&quire).round_into();
assert_eq!(result, p16::round_from(0.1))