use anyhow::Result;
use std::sync::atomic::AtomicBool;
static EXACT: AtomicBool = AtomicBool::new(true);
pub fn set_exact_globally(exact: bool) {
EXACT.store(exact, std::sync::atomic::Ordering::Relaxed);
}
pub fn is_exact_globally() -> bool {
if cfg!(any(
all(
feature = "exactarithmetic",
feature = "approximatearithmetic"
),
all(
not(feature = "exactarithmetic"),
not(feature = "approximatearithmetic")
)
)) {
EXACT.load(std::sync::atomic::Ordering::Relaxed)
} else if cfg!(feature = "exactarithmetic") {
true
} else {
false
}
}
pub trait MaybeExact {
type Approximate;
type Exact;
fn is_exact(&self) -> bool;
fn approx_ref(&self) -> Result<&Self::Approximate>;
fn exact_ref(&self) -> Result<&Self::Exact>;
fn approx(self) -> Result<Self::Approximate>;
fn exact(self) -> Result<Self::Exact>;
fn try_to_exact(exact: Self::Exact) -> Result<Self> where Self: Sized;
fn try_to_approx(approx: Self::Approximate) -> Result<Self> where Self: Sized;
}