Fast-posit: Software implementation of the Posit floating point format
โ Rust ๐ 2025-09-27 ๐ค surdeus ๐๏ธ 8Hi! fast-posit is a software implementation of the posit arithmetic standard. It aims to be complete, correct, and fast.
For those who don't know, the TL;DR is that "posits" are an alternative to IEEE floats that offer several advantages. I list some of those in the readme, but for those who are interested in these sort of things (alternative number systems for HPC and AI and the like) I firmly recommend reading about posits: there's an older overview and a more recent book.
The version at the moment (0.1.2) is not feature complete, but it does have the basics down: the four basic arithmetic operations (+ - ร รท), quire sums, conversion to/from floats, ints, and other posits, etc. The aim is to have the full posit standard for 1.0.0.
// Create posits from ints, IEEE floats, strings, constants, or a raw bit representation.
let a = p32::round_from(2.71_f64);
let b = p32::round_from(42_i32);
let c = p32::MIN_POSITIVE;
// Do maths
assert!(p16::round_from(3.14) * p16::from(2) == p16::round_from(6.28));
assert!(p16::MIN_POSITIVE < 1e-15.round_into());
// Do sums 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();
// 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);
In terms of performance, I believe it is faster (or at least as fast) as any freely available implementation of posit arithmetic. I include some microbenchmarks, and some tests against external libraries.
It's extensively tested, exhaustively where possibly, and probabilistically where not.
It's no_std and has no non-dev dependencies.
Let me know what you think! I'm especially keen on hearing about people with previous experience with posits; feedback is welcome!
1 post - 1 participant
๐ท๏ธ Rust_feed