diff options
| author | Sam Anthony <sam@samanthony.xyz> | 2024-06-25 16:08:00 -0400 |
|---|---|---|
| committer | Sam Anthony <sam@samanthony.xyz> | 2024-06-25 16:08:00 -0400 |
| commit | d1fbef4cb7fb51c519058d2c91f4f667bc7b9658 (patch) | |
| tree | 2f5ca5d3e81134eb44491ea994cb239005cbc15e | |
| parent | bee8ab445a841792a5e8af45a5950c8df6f8ecbf (diff) | |
| download | pfc-d1fbef4cb7fb51c519058d2c91f4f667bc7b9658.zip | |
return error if not enough operands in stack
| -rw-r--r-- | calc.go | 5 |
1 files changed, 2 insertions, 3 deletions
@@ -69,10 +69,9 @@ func (c *Calculator) performOperation(operator byte) error { // operands returns the left and right operands, or error if there are not enough. func (c *Calculator) operands() (lhs, rhs float64, err error) { - if buf, err := c.parseBuffer(); err == nil { - rhs = buf + if rhs, err := c.parseBuffer(); err == nil { lhs, err = c.stack.pop() - return lhs, rhs, nil + return lhs, rhs, err } else if stk, err := c.stack.pop(); err == nil { rhs = stk if lhs, err = c.stack.pop(); err == nil { |