feat: add some trig functions

This commit is contained in:
electria 2026-07-15 22:09:23 -07:00
commit f22011e59e
Signed by: electria
SSH key fingerprint: SHA256:8LlB3ucPbBHqozqkhsNbaV5oG3SlzzqUj8FZDL6IPQs
2 changed files with 18 additions and 0 deletions

View file

@ -42,7 +42,13 @@ fn collapse_toplevel(nodes: &mut Vec<Node>, mut end: usize) {
match &mut nodes[start..end][index + 1] { match &mut nodes[start..end][index + 1] {
Node::Number(n) => match variant { Node::Number(n) => match variant {
Function::Sine => n.sin_mut(), Function::Sine => n.sin_mut(),
Function::ArcSine => n.asin_mut(),
Function::Cosine => n.cos_mut(), Function::Cosine => n.cos_mut(),
Function::ArcCosine => n.acos_mut(),
Function::Tangent => n.tan_mut(),
Function::ArcTangent => n.atan_mut(),
Function::Secant => n.sec_mut(),
Function::CoSecant => n.csc_mut(),
}, },
_ => panic!("function is missing an argument"), _ => panic!("function is missing an argument"),
}; };

View file

@ -55,14 +55,26 @@ impl TryFrom<char> for Operator {
#[derive(Clone, Debug, PartialEq)] #[derive(Clone, Debug, PartialEq)]
enum Function { enum Function {
Sine, Sine,
ArcSine,
Cosine, Cosine,
ArcCosine,
Tangent,
ArcTangent,
Secant,
CoSecant,
} }
impl FromStr for Function { impl FromStr for Function {
type Err = (); type Err = ();
fn from_str(s: &str) -> Result<Self, Self::Err> { fn from_str(s: &str) -> Result<Self, Self::Err> {
match s { match s {
"sin" => Ok(Self::Sine), "sin" => Ok(Self::Sine),
"asin" => Ok(Self::ArcSine),
"cos" => Ok(Self::Cosine), "cos" => Ok(Self::Cosine),
"acos" => Ok(Self::ArcCosine),
"tan" => Ok(Self::Tangent),
"atan" => Ok(Self::ArcTangent),
"sec" => Ok(Self::Secant),
"csc" => Ok(Self::CoSecant),
_ => Err(()), _ => Err(()),
} }
} }