#[derive(Debug, Clone)]
pub struct Config {
pub step: f64,
pub rel_tol: f64,
pub abs_tol: f64,
pub precision: crate::Precision,
pub floor: f64,
}
impl Default for Config {
fn default() -> Self {
Self::f32_defaults()
}
}
impl Config {
pub fn f32_defaults() -> Self {
Self {
step: 1e-2,
rel_tol: 1e-3,
abs_tol: 1e-4,
floor: 2e-4,
precision: crate::Precision::F32,
}
}
pub fn f64_defaults() -> Self {
Self {
step: 1e-5,
rel_tol: 1e-6,
abs_tol: 1e-10,
floor: 2e-10,
precision: crate::Precision::F64,
}
}
pub fn with_step(mut self, step: f64) -> Self {
self.step = step;
self
}
pub fn with_rel_tol(mut self, rel_tol: f64) -> Self {
self.rel_tol = rel_tol;
self
}
pub fn with_abs_tol(mut self, abs_tol: f64) -> Self {
self.abs_tol = abs_tol;
self
}
pub fn with_precision(mut self, precision: crate::Precision) -> Self {
self.precision = precision;
self
}
pub fn with_floor(mut self, floor: f64) -> Self {
self.floor = floor;
self
}
pub(crate) fn is_finite(&self) -> bool {
self.step.is_finite()
&& self.rel_tol.is_finite()
&& self.abs_tol.is_finite()
&& self.floor.is_finite()
&& self.step > 0.0
}
}