feat: add way more functions

This commit is contained in:
electria 2026-11-04 15:00:06 -08:00
commit c9d85459f3
Signed by: electria
SSH key fingerprint: SHA256:8LlB3ucPbBHqozqkhsNbaV5oG3SlzzqUj8FZDL6IPQs
3 changed files with 63 additions and 15 deletions

View file

@ -141,20 +141,36 @@ impl Operator {
impl Function {
fn apply_to(&self, n: &mut Float) {
match self {
Self::Sqrt => Float::sqrt_mut(n),
Self::AbsoluteValue => Float::abs_mut(n),
Self::Ln => Float::ln_mut(n),
Self::SquareRoot => Float::sqrt_mut(n),
Self::LogNatural => Float::ln_mut(n),
Self::Log10 => Float::log10_mut(n),
Self::Sine => Float::sin_mut(n),
Self::ArcSine => Float::asin_mut(n),
Self::Cosine => Float::cos_mut(n),
Self::ArcCosine => Float::acos_mut(n),
Self::Tangent => Float::tan_mut(n),
Self::ArcTangent => Float::atan_mut(n),
Self::Secant => Float::sec_mut(n),
Self::CoSecant => Float::csc_mut(n),
Self::Abs => Float::abs_mut(n),
Self::Cosine => Float::cos_mut(n),
Self::ArcCosine => Float::acos_mut(n),
Self::Secant => Float::sec_mut(n),
Self::Tangent => Float::tan_mut(n),
Self::ArcTangent => Float::atan_mut(n),
Self::CoTangent => Float::cot_mut(n),
Self::HyperbolicSin => Float::sinh_mut(n),
Self::ArcHyperbolicSin => Float::asinh_mut(n),
Self::HyperbolicCoSecant => Float::csch_mut(n),
Self::HyperbolicCosine => Float::cosh_mut(n),
Self::ArcHyperbolicCosine => Float::acosh_mut(n),
Self::HyperbolicSecant => Float::csch_mut(n),
Self::HyperbolicTangent => Float::tanh_mut(n),
Self::ArcHyperbolicTangent => Float::atanh_mut(n),
Self::HyperbolicCoTangent => Float::coth_mut(n),
}
}
}

View file

@ -74,18 +74,34 @@ pub enum Operator {
#[derive(Debug, Copy, Clone, PartialEq)]
pub enum Function {
Sqrt,
AbsoluteValue,
Ln,
SquareRoot,
LogNatural,
Log10,
Sine,
ArcSine,
Cosine,
ArcCosine,
Tangent,
ArcTangent,
Secant,
CoSecant,
Abs,
Cosine,
ArcCosine,
Secant,
Tangent,
ArcTangent,
CoTangent,
HyperbolicSin,
ArcHyperbolicSin,
HyperbolicCoSecant,
HyperbolicCosine,
ArcHyperbolicCosine,
HyperbolicSecant,
HyperbolicTangent,
ArcHyperbolicTangent,
HyperbolicCoTangent,
}

View file

@ -38,20 +38,36 @@ impl FromStr for Function {
type Err = String;
fn from_str(s: &str) -> Result<Self, Self::Err> {
match s {
"sqrt" => Ok(Self::Sqrt),
"abs" => Ok(Self::AbsoluteValue),
"ln" => Ok(Self::Ln),
"sqrt" => Ok(Self::SquareRoot),
"ln" => Ok(Self::LogNatural),
"log" => Ok(Self::Log10),
"sin" => Ok(Self::Sine),
"asin" | "arcsin" => Ok(Self::ArcSine),
"cos" => Ok(Self::Cosine),
"acos" | "arccos" => Ok(Self::ArcCosine),
"tan" => Ok(Self::Tangent),
"atan" | "arctan" => Ok(Self::ArcTangent),
"sec" => Ok(Self::Secant),
"csc" => Ok(Self::CoSecant),
"abs" => Ok(Self::Abs),
"cos" => Ok(Self::Cosine),
"acos" | "arccos" => Ok(Self::ArcCosine),
"sec" => Ok(Self::Secant),
"tan" => Ok(Self::Tangent),
"atan" | "arctan" => Ok(Self::ArcTangent),
"cot" => Ok(Self::CoTangent),
"sinh" => Ok(Self::HyperbolicSin),
"asinh" | "arcsinh" => Ok(Self::ArcHyperbolicSin),
"csch" => Ok(Self::HyperbolicCoSecant),
"cosh" => Ok(Self::HyperbolicCosine),
"acosh" | "arccosh" => Ok(Self::ArcHyperbolicCosine),
"sech" => Ok(Self::HyperbolicSecant),
"tanh" => Ok(Self::HyperbolicTangent),
"atanh" | "arctanh" => Ok(Self::ArcHyperbolicTangent),
"coth" => Ok(Self::HyperbolicCoTangent),
_ => Err(s.to_owned()),
}