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:
parent
93d8147048
commit
4d7a806caa
3 changed files with 6 additions and 0 deletions
|
|
@ -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(),
|
||||||
|
|
|
||||||
|
|
@ -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),
|
||||||
|
|
|
||||||
|
|
@ -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,
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue