aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorSam Anthony <sam@samanthony.xyz>2023-02-01 19:54:33 -0330
committerSam Anthony <sam@samanthony.xyz>2023-02-01 19:54:33 -0330
commit96b768c55caa756e6fc7e7a690211258519683fa (patch)
treea3829d0c86be89be028aa4519aa0545a70d15dbd /src
parent6e6e7581b4c8575dd379f20a786108ce4edcd9c8 (diff)
downloadpfc-96b768c55caa756e6fc7e7a690211258519683fa.zip
exponentiation operator
Diffstat (limited to 'src')
-rw-r--r--src/lib.rs3
1 files changed, 3 insertions, 0 deletions
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)),
}
}