use std::sync::OnceLock;
pub const MAX_FLOAT_PRECISION: usize = 17;
pub const EXPONENT_LIMIT: f64 = 9e15;
pub const LAYER_REDUCTION_THRESHOLD: f64 = 15.954242509439325;
pub const FIRST_NEG_LAYER: f64 = 1_f64 / 9e15;
pub const NUMBER_EXP_MAX: i32 = 308;
pub const NUMBER_EXP_MIN: i32 = -324;
pub const MAX_ES_IN_A_ROW: u64 = 5;
pub const MAX_POWERS_OF_TEN: usize = (NUMBER_EXP_MAX - NUMBER_EXP_MIN + 1) as usize;
pub const TWO_PI: f64 = std::f64::consts::TAU;
pub const EXPN1: f64 = 0.36787944117144233;
pub const OMEGA: f64 = 0.5671432904097838;
pub const COMPARE_EPSILON: f64 = 1e-10;
static POWERS_OF_TEN_CELL: OnceLock<Vec<f64>> = OnceLock::new();
pub(crate) fn powers_of_ten() -> &'static Vec<f64> {
POWERS_OF_TEN_CELL.get_or_init(|| {
let mut v: Vec<f64> = Vec::new();
for i in (NUMBER_EXP_MIN + 1)..=NUMBER_EXP_MAX {
v.push(format!("1e{i}").parse().unwrap());
}
v
})
}
static IGNORE_COMMAS_CELL: OnceLock<bool> = OnceLock::new();
pub(crate) fn ignore_commas() -> bool {
*IGNORE_COMMAS_CELL.get_or_init(|| true)
}
static COMMAS_ARE_DECIMAL_POINTS_CELL: OnceLock<bool> = OnceLock::new();
pub(crate) fn commas_are_decimal_points() -> bool {
*COMMAS_ARE_DECIMAL_POINTS_CELL.get_or_init(|| false)
}
pub(crate) fn power_of_10(exp: i32) -> f64 {
powers_of_ten()[(exp + 323) as usize]
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn power_of_10_spot_checks() {
assert_eq!(power_of_10(0), 1.0);
assert_eq!(power_of_10(1), 10.0);
assert_eq!(power_of_10(2), 100.0);
assert_eq!(power_of_10(-1), 0.1);
}
#[test]
fn compare_epsilon_value() {
assert_eq!(COMPARE_EPSILON, 1e-10);
}
}