Skip to content

Commit 4032211

Browse files
committed
Add doc section about testing
1 parent 21470e9 commit 4032211

1 file changed

Lines changed: 15 additions & 0 deletions

File tree

‎src/posit/mod.rs‎

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,21 @@
2121
//! Suggested reading order: [Posit] and [Decoded] types, [basics] and [constants](consts),
2222
//! [decode] implementation (Posit→Decoded), [encode] implementation (Decoded→Posit),
2323
//! [elementary arithmetic](ops).
24+
//!
25+
//! # Testing
26+
//!
27+
//! Extensive tests are included. When possible, we check all inputs exhaustively (e.g.: adding two
28+
//! 8-bit posits, there are only 256² possible inputs). Whenever this is not feasible (e.g: adding
29+
//! two 64-bit posits), we make use of the [`proptest`] crate, which allows us to
30+
//! probabilistically test inputs from a random distribution.
31+
//!
32+
//! Another key ingredient in the testing process is in the [`rational`] submodule. There, we
33+
//! define some tools to convert to and from *arbitrary precision* rational numbers. Since any
34+
//! non-NaR posit is a rational number, we can test any function in this crate involving posits by
35+
//! simply checking that the output matches the output of the equivalent function using
36+
//! infinite-precision rationals. For instance: to test addition of two posits, we simply check
37+
//! that `rational(a) + rational(b) == rational(a + b)`, i.e. adding the posits yields the same
38+
//! result as adding the arbitrary-precision rationals (modulo rounding, of course).
2439
2540
/// A *posit* floating point number with `N` bits and `ES` exponent bits, using `Int` as its
2641
/// underlying type.

0 commit comments

Comments
 (0)