-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
78 additions
and
112 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,14 @@ | ||
/* Crate imports */ | ||
use super::Element; | ||
use crate::token::Function; | ||
|
||
#[derive(Debug, PartialEq, PartialOrd)] | ||
pub struct FunctionCall<'a> { | ||
func: Function, | ||
func: fn(f64) -> f64, | ||
arg: Element<'a>, | ||
} | ||
|
||
impl<'a> FunctionCall<'a> { | ||
pub const fn new(func: Function, arg: Element<'a>) -> Self { | ||
pub const fn new(func: fn(f64) -> f64, arg: Element<'a>) -> Self { | ||
Self { func, arg } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
/* Clippy config */ | ||
#![allow(clippy::pub_use)] | ||
|
||
#[derive(Debug, PartialEq, PartialOrd)] | ||
#[non_exhaustive] | ||
pub enum Token<'a> { | ||
Number(f64), | ||
Operator(Operator), | ||
/// Left parenthesis. | ||
LParen, | ||
/// Right parenthesis. | ||
RParen, | ||
/// Identifiers | ||
Identifier(Identifier<'a>), | ||
} | ||
|
||
#[derive(Debug, PartialEq, PartialOrd)] | ||
pub enum Identifier<'a> { | ||
Function(fn(f64) -> f64), | ||
Constant(f64), | ||
Variable(&'a str), | ||
} | ||
|
||
impl<'a> From<&'a str> for Identifier<'a> { | ||
fn from(value: &'a str) -> Self { | ||
match value { | ||
/* Constants */ | ||
"pi" => Identifier::Constant(core::f64::consts::PI), | ||
"e" => Identifier::Constant(core::f64::consts::E), | ||
/* Functions */ | ||
// sin | ||
"sin" => Identifier::Function(f64::sin), | ||
"sinh" => Identifier::Function(f64::sinh), | ||
"asin" => Identifier::Function(f64::asin), | ||
"asinh" => Identifier::Function(f64::asinh), | ||
// cos | ||
"cos" => Identifier::Function(f64::cos), | ||
"cosh" => Identifier::Function(f64::cosh), | ||
"acos" => Identifier::Function(f64::acos), | ||
"acosh" => Identifier::Function(f64::acosh), | ||
// tan | ||
"tan" => Identifier::Function(f64::tan), | ||
"tanh" => Identifier::Function(f64::tanh), | ||
"atan" => Identifier::Function(f64::atan), | ||
"atanh" => Identifier::Function(f64::atanh), | ||
// log | ||
"ln" => Identifier::Function(f64::ln), | ||
"log" => Identifier::Function(f64::log10), | ||
// roots | ||
"sqrt" => Identifier::Function(f64::sqrt), | ||
"cbrt" => Identifier::Function(f64::cbrt), | ||
// misc | ||
"exp" => Identifier::Function(f64::exp), | ||
"abs" => Identifier::Function(f64::abs), | ||
"floor" => Identifier::Function(f64::floor), | ||
"ceil" => Identifier::Function(f64::ceil), | ||
"round" => Identifier::Function(f64::round), | ||
"trunc" => Identifier::Function(f64::trunc), | ||
/* Variables */ | ||
_ => Identifier::Variable(value), | ||
} | ||
} | ||
} | ||
|
||
#[derive(Debug, Eq, PartialEq, Ord, PartialOrd)] | ||
pub enum Operator { | ||
// Factorial, | ||
Plus, | ||
Minus, | ||
Times, | ||
Divide, | ||
Power, | ||
Modulo, | ||
} |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.