From 56521cbbcd6c22c40bb4ae79d91ec073d950bbfc Mon Sep 17 00:00:00 2001 From: Mark Date: Mon, 27 Mar 2023 21:25:16 -0700 Subject: [PATCH] Added ** exponentiation --- README.md | 1 - src/main.rs | 8 ++++---- src/tokens.rs | 20 ++++++++++---------- 3 files changed, 14 insertions(+), 15 deletions(-) diff --git a/README.md b/README.md index 0bbf789..27f69f0 100644 --- a/README.md +++ b/README.md @@ -19,7 +19,6 @@ This is nowhere near complete. Stay tuned. - Arrows to move cursor - Documentation - Branding - - ** as exponentiation - Improve tests diff --git a/src/main.rs b/src/main.rs index 0f0f87c..155189b 100644 --- a/src/main.rs +++ b/src/main.rs @@ -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(-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)"); diff --git a/src/tokens.rs b/src/tokens.rs index e295d6e..76568e1 100644 --- a/src/tokens.rs +++ b/src/tokens.rs @@ -234,16 +234,16 @@ impl Operator { #[inline(always)] pub fn from_string(s: &str) -> Option { match s { - "+" => {Some( Operator::Add )}, - "-" => {Some( Operator::Subtract )}, - "neg" => {Some( Operator::Negative )}, - "*"|"×" => {Some( Operator::Multiply )}, - "/"|"÷" => {Some( Operator::Divide )}, - "i*" => {Some( Operator::ImplicitMultiply )}, - "%" => {Some( Operator::Modulo )}, - "mod" => {Some( Operator::ModuloLong )}, - "^" => {Some( Operator::Power )}, - "!" => {Some( Operator::Factorial )}, + "+" => {Some( Operator::Add )}, + "-" => {Some( Operator::Subtract )}, + "neg" => {Some( Operator::Negative )}, + "*"|"×" => {Some( Operator::Multiply )}, + "/"|"÷" => {Some( Operator::Divide )}, + "i*" => {Some( Operator::ImplicitMultiply )}, + "%" => {Some( Operator::Modulo )}, + "mod" => {Some( Operator::ModuloLong )}, + "^"|"**" => {Some( Operator::Power )}, + "!" => {Some( Operator::Factorial )}, _ => None } }