feat: support sqrt

other roots may prove to be quite a challenge,
since I would need to parse the syntax `root(base, value)`
This commit is contained in:
electria 2026-07-16 11:31:57 -07:00
commit 4d7a806caa
Signed by: electria
SSH key fingerprint: SHA256:8LlB3ucPbBHqozqkhsNbaV5oG3SlzzqUj8FZDL6IPQs
3 changed files with 6 additions and 0 deletions

View file

@ -40,6 +40,8 @@ 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::Sqrt => n.sqrt_mut(),
Function::Sine => n.sin_mut(), Function::Sine => n.sin_mut(),
Function::ArcSine => n.asin_mut(), Function::ArcSine => n.asin_mut(),
Function::Cosine => n.cos_mut(), Function::Cosine => n.cos_mut(),

View file

@ -32,6 +32,8 @@ impl FromStr for Function {
type Err = String; type Err = String;
fn from_str(s: &str) -> Result<Self, Self::Err> { fn from_str(s: &str) -> Result<Self, Self::Err> {
match s { match s {
"sqrt" => Ok(Self::Sqrt),
"sin" => Ok(Self::Sine), "sin" => Ok(Self::Sine),
"asin" => Ok(Self::ArcSine), "asin" => Ok(Self::ArcSine),
"cos" => Ok(Self::Cosine), "cos" => Ok(Self::Cosine),

View file

@ -40,6 +40,8 @@ enum Operator {
#[derive(Debug, Copy, Clone, PartialEq)] #[derive(Debug, Copy, Clone, PartialEq)]
enum Function { enum Function {
Sqrt,
Sine, Sine,
ArcSine, ArcSine,
Cosine, Cosine,