use std::collections::BTreeMap;
#[macro_export]
macro_rules! assert_interval {
($var:expr, $a:expr, $b:expr) => {
assert!(
($a..=$b).contains(&$var),
"Invalid value for `{}`. Must be in the interval [{}, {}].",
stringify!($var),
$a,
$b,
);
};
}
pub(crate) fn _format_float(float: f64, precision: usize) -> String {
let scientific_notation_threshold = 0.1_f64.powf(precision as f64 - 1.0);
match scientific_notation_threshold >= float {
true => format!("{float:.precision$e}"),
false => format!("{float:.precision$}"),
}
}
pub(crate) fn summary_from_keys(keys: &[&'static str]) -> BTreeMap<&'static str, f64> {
keys.iter().map(|k| (*k, 0.0)).collect()
}