mirror of
https://github.com/rm-dr/daisy
synced 2025-08-02 01:34:50 -07:00
Added nounit and tobase functions
This commit is contained in:
@ -28,10 +28,14 @@ pub enum Function {
|
||||
Csch,
|
||||
Sech,
|
||||
Coth,
|
||||
|
||||
NoUnit,
|
||||
ToBase
|
||||
}
|
||||
|
||||
impl Function {
|
||||
pub fn to_string(&self) -> String {
|
||||
|
||||
impl ToString for Function {
|
||||
fn to_string(&self) -> String {
|
||||
match self {
|
||||
Function::Abs => { String::from("abs") },
|
||||
Function::Floor => { String::from("floor") },
|
||||
@ -57,6 +61,45 @@ impl Function {
|
||||
Function::Csch => { String::from("csch") },
|
||||
Function::Sech => { String::from("sech") },
|
||||
Function::Coth => { String::from("coth") },
|
||||
Function::NoUnit => { String::from("nounit") },
|
||||
Function::ToBase => { String::from("tobase") },
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
impl Function {
|
||||
#[inline(always)]
|
||||
pub fn from_string(s: &str) -> Option<Function> {
|
||||
match s {
|
||||
"abs" => {Some(Function::Abs)},
|
||||
"floor" => {Some(Function::Floor)},
|
||||
"ceil" => {Some(Function::Ceil)},
|
||||
"round" => {Some(Function::Round)},
|
||||
"ln" => {Some(Function::NaturalLog)},
|
||||
"log" => {Some(Function::TenLog)},
|
||||
"sin" => {Some(Function::Sin)},
|
||||
"cos" => {Some(Function::Cos)},
|
||||
"tan" => {Some(Function::Tan)},
|
||||
"asin" => {Some(Function::Asin)},
|
||||
"acos" => {Some(Function::Acos)},
|
||||
"atan" => {Some(Function::Atan)},
|
||||
"csc" => {Some(Function::Csc)},
|
||||
"secant" => {Some(Function::Sec)},
|
||||
"cot" => {Some(Function::Cot)},
|
||||
"sinh" => {Some(Function::Sinh)},
|
||||
"cosh" => {Some(Function::Cosh)},
|
||||
"tanh" => {Some(Function::Tanh)},
|
||||
"asinh" => {Some(Function::Asinh)},
|
||||
"acosh" => {Some(Function::Acosh)},
|
||||
"atanh" => {Some(Function::Atanh)},
|
||||
"csch" => {Some(Function::Csch)},
|
||||
"sech" => {Some(Function::Sech)},
|
||||
"coth" => {Some(Function::Coth)},
|
||||
|
||||
"nounit" => {Some(Function::NoUnit)},
|
||||
"tobase" => {Some(Function::ToBase)}
|
||||
_ => None
|
||||
}
|
||||
}
|
||||
}
|
@ -61,7 +61,13 @@ impl Operator {
|
||||
|
||||
#[inline(always)]
|
||||
pub fn from_string(s: &str) -> Option<Operator> {
|
||||
match s {
|
||||
|
||||
let f = Function::from_string(s);
|
||||
if let Some(f) = f {
|
||||
return Some(Operator::Function(f));
|
||||
}
|
||||
|
||||
return match s {
|
||||
"+" => {Some( Operator::Add )},
|
||||
"-" => {Some( Operator::Subtract )},
|
||||
"neg" => {Some( Operator::Negative )},
|
||||
@ -76,32 +82,8 @@ impl Operator {
|
||||
"!" => {Some( Operator::Factorial )},
|
||||
"sqrt"|"rt"|"√" => {Some( Operator::Sqrt )},
|
||||
|
||||
"abs" => {Some( Operator::Function(Function::Abs) )},
|
||||
"floor" => {Some( Operator::Function(Function::Floor) )},
|
||||
"ceil" => {Some( Operator::Function(Function::Ceil) )},
|
||||
"round" => {Some( Operator::Function(Function::Round) )},
|
||||
"ln" => {Some( Operator::Function(Function::NaturalLog) )},
|
||||
"log" => {Some( Operator::Function(Function::TenLog) )},
|
||||
"sin" => {Some( Operator::Function(Function::Sin) )},
|
||||
"cos" => {Some( Operator::Function(Function::Cos) )},
|
||||
"tan" => {Some( Operator::Function(Function::Tan) )},
|
||||
"asin" => {Some( Operator::Function(Function::Asin) )},
|
||||
"acos" => {Some( Operator::Function(Function::Acos) )},
|
||||
"atan" => {Some( Operator::Function(Function::Atan) )},
|
||||
"csc" => {Some( Operator::Function(Function::Csc) )},
|
||||
"secant" => {Some( Operator::Function(Function::Sec) )},
|
||||
"cot" => {Some( Operator::Function(Function::Cot) )},
|
||||
"sinh" => {Some( Operator::Function(Function::Sinh) )},
|
||||
"cosh" => {Some( Operator::Function(Function::Cosh) )},
|
||||
"tanh" => {Some( Operator::Function(Function::Tanh) )},
|
||||
"asinh" => {Some( Operator::Function(Function::Asinh) )},
|
||||
"acosh" => {Some( Operator::Function(Function::Acosh) )},
|
||||
"atanh" => {Some( Operator::Function(Function::Atanh) )},
|
||||
"csch" => {Some( Operator::Function(Function::Csch) )},
|
||||
"sech" => {Some( Operator::Function(Function::Sech) )},
|
||||
"coth" => {Some( Operator::Function(Function::Coth) )},
|
||||
_ => None
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
|
Reference in New Issue
Block a user