#[derive(Clone, Debug, PartialEq, Eq, Hash)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub enum NamedConst {
Pi,
E,
Sqrt2,
NegPi,
NegE,
NegSqrt2,
Half,
NegHalf,
Third,
Quarter,
}
impl NamedConst {
pub fn value(&self) -> f64 {
match self {
Self::Pi => std::f64::consts::PI,
Self::E => std::f64::consts::E,
Self::Sqrt2 => std::f64::consts::SQRT_2,
Self::NegPi => -std::f64::consts::PI,
Self::NegE => -std::f64::consts::E,
Self::NegSqrt2 => -std::f64::consts::SQRT_2,
Self::Half => 0.5,
Self::NegHalf => -0.5,
Self::Third => 1.0 / 3.0,
Self::Quarter => 0.25,
}
}
pub fn to_pretty(&self) -> &'static str {
match self {
Self::Pi => "π",
Self::E => "e",
Self::Sqrt2 => "√2",
Self::NegPi => "(-π)",
Self::NegE => "(-e)",
Self::NegSqrt2 => "(-√2)",
Self::Half => "(1/2)",
Self::NegHalf => "(-1/2)",
Self::Third => "(1/3)",
Self::Quarter => "(1/4)",
}
}
pub fn to_latex(&self) -> &'static str {
match self {
Self::Pi => r"\pi",
Self::E => "e",
Self::Sqrt2 => r"\sqrt{2}",
Self::NegPi => r"(-\pi)",
Self::NegE => "(-e)",
Self::NegSqrt2 => r"(-\sqrt{2})",
Self::Half => r"\frac{1}{2}",
Self::NegHalf => r"-\frac{1}{2}",
Self::Third => r"\frac{1}{3}",
Self::Quarter => r"\frac{1}{4}",
}
}
}