Added ** exponentiation

pull/2/head
Mark 2023-03-27 21:25:16 -07:00
parent e5b7aa2d1a
commit 56521cbbcd
Signed by: Mark
GPG Key ID: AD62BB059C2AAEE4
3 changed files with 14 additions and 15 deletions

View File

@ -19,7 +19,6 @@ This is nowhere near complete. Stay tuned.
- Arrows to move cursor - Arrows to move cursor
- Documentation - Documentation
- Branding - Branding
- ** as exponentiation
- Improve tests - Improve tests

View File

@ -309,13 +309,13 @@ mod tests {
good_expr(64f64, "4^3"); good_expr(64f64, "4^3");
good_expr(64f64, "4 ^ 3"); good_expr(64f64, "4 ^ 3");
//good_expr(64f64, "4**3"); good_expr(64f64, "4**3");
//good_expr(64f64, "4 ** 3"); good_expr(64f64, "4 ** 3");
good_expr(-81f64, "-3^4"); good_expr(-81f64, "-3^4");
good_expr(-81f64, "-3 ^ 4"); good_expr(-81f64, "-3 ^ 4");
//good_expr(-81f64, "-3**4"); good_expr(-81f64, "-3**4");
//good_expr(-81f64, "-3 ** 4"); good_expr(-81f64, "-3 ** 4");
good_expr(-81f64, "-(3^4)"); good_expr(-81f64, "-(3^4)");
//good_expr(f64, "3 ^ (-1.4)"); //good_expr(f64, "3 ^ (-1.4)");

View File

@ -234,16 +234,16 @@ impl Operator {
#[inline(always)] #[inline(always)]
pub fn from_string(s: &str) -> Option<Operator> { pub fn from_string(s: &str) -> Option<Operator> {
match s { match s {
"+" => {Some( Operator::Add )}, "+" => {Some( Operator::Add )},
"-" => {Some( Operator::Subtract )}, "-" => {Some( Operator::Subtract )},
"neg" => {Some( Operator::Negative )}, "neg" => {Some( Operator::Negative )},
"*"|"×" => {Some( Operator::Multiply )}, "*"|"×" => {Some( Operator::Multiply )},
"/"|"÷" => {Some( Operator::Divide )}, "/"|"÷" => {Some( Operator::Divide )},
"i*" => {Some( Operator::ImplicitMultiply )}, "i*" => {Some( Operator::ImplicitMultiply )},
"%" => {Some( Operator::Modulo )}, "%" => {Some( Operator::Modulo )},
"mod" => {Some( Operator::ModuloLong )}, "mod" => {Some( Operator::ModuloLong )},
"^" => {Some( Operator::Power )}, "^"|"**" => {Some( Operator::Power )},
"!" => {Some( Operator::Factorial )}, "!" => {Some( Operator::Factorial )},
_ => None _ => None
} }
} }