diff options
| author | Sam Anthony <sam@samanthony.xyz> | 2023-02-12 13:25:00 -0330 |
|---|---|---|
| committer | Sam Anthony <sam@samanthony.xyz> | 2023-02-12 13:25:00 -0330 |
| commit | 99a8712464793c2120c2bf880e87fbbab65475ad (patch) | |
| tree | 7e1b6a74b857c7d0bb949a62baa12bb34af2a896 | |
| parent | 9083671a6ccda8393359f27948bf3007b9535ca8 (diff) | |
| download | pfc-0.6.2.zip | |
push constant in buffer to stack before performing operationv0.6.2
| -rw-r--r-- | Cargo.lock | 2 | ||||
| -rw-r--r-- | Cargo.toml | 2 | ||||
| -rw-r--r-- | src/input.rs | 10 |
3 files changed, 6 insertions, 8 deletions
@@ -113,7 +113,7 @@ dependencies = [ [[package]] name = "pfc" -version = "0.6.1" +version = "0.6.2" dependencies = [ "crossterm", "tui", @@ -1,6 +1,6 @@ [package] name = "pfc" -version = "0.6.1" +version = "0.6.2" edition = "2021" [dependencies] diff --git a/src/input.rs b/src/input.rs index 462e43c..f1431c5 100644 --- a/src/input.rs +++ b/src/input.rs @@ -46,8 +46,6 @@ impl Calculator { return Signal::None; } - // Push a character into the input buffer. If the character is an operator, - // the particular operation is performed. fn push_to_buffer(&mut self, c: char) { if c == '.' && !self.input_buffer.contains('.') { if self.input_buffer.len() == 0 { @@ -55,8 +53,10 @@ impl Calculator { } self.input_buffer.push(c); } else if let Ok(op) = Operator::parse(c) { - if self.input_buffer.len() > 0 { - self.stack.push(self.input_buffer.parse::<f64>().unwrap()); + if let Ok(c) = Constant::parse(&self.input_buffer) { + self.stack.push(c.value()); + } else if let Ok(f) = self.input_buffer.parse::<f64>() { + self.stack.push(f); } self.input_buffer = String::new(); self.perform_operation(op); @@ -65,8 +65,6 @@ impl Calculator { } } - // Swap the bottom of the stack and the input buffer. If the input buffer - // is empty, this simply pops from the stack into the input buffer. fn swap(&mut self) { if let Some(st) = self.stack.pop() { if let Ok(bu) = self.input_buffer.parse::<f64>() { |