aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSam Anthony <sam@samanthony.xyz>2024-06-25 16:16:00 -0400
committerSam Anthony <sam@samanthony.xyz>2024-06-25 16:16:00 -0400
commitee56cc539398a7fc1664f39cf16428fa13c262c9 (patch)
tree8c92fd514a1119d4b57cedb4b94606b1790c005e
parentd1fbef4cb7fb51c519058d2c91f4f667bc7b9658 (diff)
downloadpfc-ee56cc539398a7fc1664f39cf16428fa13c262c9.zip
clean up operands()
-rw-r--r--calc.go16
1 files changed, 8 insertions, 8 deletions
diff --git a/calc.go b/calc.go
index 25756fc..2fb1699 100644
--- a/calc.go
+++ b/calc.go
@@ -69,16 +69,16 @@ 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 rhs, err := c.parseBuffer(); err == nil {
+ if rhs, err = c.parseBuffer(); err == nil {
lhs, err = c.stack.pop()
- return lhs, rhs, err
- } else if stk, err := c.stack.pop(); err == nil {
- rhs = stk
- if lhs, err = c.stack.pop(); err == nil {
- return lhs, rhs, nil
+ return
+ } else if rhs, err = c.stack.pop(); err == nil {
+ lhs, err = c.stack.pop()
+ if err != nil { // missing lhs
+ c.stack.push(rhs)
}
- c.stack.push(rhs)
- } // not enough operands
+ return
+ }
return 0, 0, OperandErr{}
}