1use anyhow::Result;
2use std::sync::atomic::AtomicBool;
3
4static EXACT: AtomicBool = AtomicBool::new(true);
7
8pub fn set_exact_globally(exact: bool) {
11 EXACT.store(exact, std::sync::atomic::Ordering::Relaxed);
12}
13
14pub fn is_exact_globally() -> bool {
15 if cfg!(any(
16 all(
17 feature = "exactarithmetic",
18 feature = "approximatearithmetic"
19 ),
20 all(
21 not(feature = "exactarithmetic"),
22 not(feature = "approximatearithmetic")
23 )
24 )) {
25 EXACT.load(std::sync::atomic::Ordering::Relaxed)
26 } else if cfg!(feature = "exactarithmetic") {
27 true
28 } else {
29 false
30 }
31}
32
33pub trait MaybeExact {
35 type Approximate;
36 type Exact;
37
38 fn is_exact(&self) -> bool;
39
40 fn extract_approx(&self) -> Result<Self::Approximate>;
44
45 fn extract_exact(&self) -> Result<&Self::Exact>;
49}