Skip to main content

wickra_verify_core/
config.rs

1//! Verification tolerances.
2//!
3//! Two floats count as equal when `|a - b| <= atol + rtol * max(|a|, |b|)` — the
4//! same mixed absolute/relative rule `numpy.allclose` uses. A pure absolute
5//! tolerance would reject large-magnitude metrics that differ only in the last
6//! representable digit; a pure relative one would reject values legitimately near
7//! zero. The defaults are deliberately tight: they absorb the last-bit float
8//! noise of two independent but deterministic computations of the *same* report,
9//! nothing more. A doctored metric moves far more than `1e-6` relative.
10
11use serde::{Deserialize, Serialize};
12
13/// Absolute tolerance component (default `1e-9`).
14pub const DEFAULT_ATOL: f64 = 1e-9;
15/// Relative tolerance component (default `1e-6`).
16pub const DEFAULT_RTOL: f64 = 1e-6;
17
18/// The comparison tolerances a [`Verifier`](crate::Verifier) is built with.
19#[derive(Debug, Clone, Copy, PartialEq, Serialize, Deserialize)]
20pub struct Config {
21    /// Absolute tolerance.
22    #[serde(default = "default_atol")]
23    pub atol: f64,
24    /// Relative tolerance.
25    #[serde(default = "default_rtol")]
26    pub rtol: f64,
27}
28
29fn default_atol() -> f64 {
30    DEFAULT_ATOL
31}
32
33fn default_rtol() -> f64 {
34    DEFAULT_RTOL
35}
36
37impl Default for Config {
38    fn default() -> Self {
39        Self {
40            atol: DEFAULT_ATOL,
41            rtol: DEFAULT_RTOL,
42        }
43    }
44}