From 96b768c55caa756e6fc7e7a690211258519683fa Mon Sep 17 00:00:00 2001 From: Sam Anthony Date: Wed, 1 Feb 2023 19:54:33 -0330 Subject: exponentiation operator --- src/lib.rs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/lib.rs b/src/lib.rs index 79210fc..c623af2 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -31,6 +31,7 @@ impl Calculator { Operator::Sub => self.stack.push(lhs - rhs), Operator::Mul => self.stack.push(lhs * rhs), Operator::Div => self.stack.push(lhs / rhs), + Operator::Exp => self.stack.push(lhs.powf(rhs)), } } } @@ -40,6 +41,7 @@ pub enum Operator { Sub, Mul, Div, + Exp, } impl Operator { @@ -49,6 +51,7 @@ impl Operator { '-' => Ok(Self::Sub), '*' => Ok(Self::Mul), '/' => Ok(Self::Div), + '^' => Ok(Self::Exp), _ => Err(ParseOperatorError(c)), } } -- cgit v1.2.3