aboutsummaryrefslogtreecommitdiffstats
path: root/calc.go
diff options
context:
space:
mode:
authorSam Anthony <sam@samanthony.xyz>2024-06-25 16:08:00 -0400
committerSam Anthony <sam@samanthony.xyz>2024-06-25 16:08:00 -0400
commitd1fbef4cb7fb51c519058d2c91f4f667bc7b9658 (patch)
tree2f5ca5d3e81134eb44491ea994cb239005cbc15e /calc.go
parentbee8ab445a841792a5e8af45a5950c8df6f8ecbf (diff)
downloadpfc-d1fbef4cb7fb51c519058d2c91f4f667bc7b9658.zip
return error if not enough operands in stack
Diffstat (limited to 'calc.go')
-rw-r--r--calc.go5
1 files changed, 2 insertions, 3 deletions
diff --git a/calc.go b/calc.go
index e9b46d1..25756fc 100644
--- a/calc.go
+++ b/calc.go
@@ -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 {