diff options
Diffstat (limited to 'src/input.rs')
| -rw-r--r-- | src/input.rs | 10 |
1 files changed, 4 insertions, 6 deletions
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>() { |