verif-arithmetic 0.1.0

Integer primitives for safety-critical Rust whose central properties are proved inside the crate by exhaustive enumeration: checked and saturating arithmetic, overflow-free mul_div, Q16.16 fixed point, and a refinement-typed Bounded. no_std, zero dependencies.
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
//! The example from `verif-arithmetic`'s `README.md`, compiled and run.
//!
//! The README is the crate's page on crates.io. Pinning its example here means a
//! change that breaks it fails `cargo test` rather than shipping a broken
//! example to every reader. Keep it in step with the first Rust block in
//! `verif-arithmetic/README.md`.

use verif_arithmetic::{checked_add, prove};

#[test]
fn readme_example_holds() {
    // The runtime behaviour...
    assert_eq!(checked_add(200, 55), Some(255));
    assert_eq!(checked_add(u32::MAX, 1), None);

    // ...and the proof that its overflow flag is exact.
    assert!(prove::checked_add_is_total().is_proved());
}