From 9562328016fb0e219184a0ec18a5e6ea8f09d138 Mon Sep 17 00:00:00 2001 From: Sam Anthony Date: Mon, 29 Sep 2025 08:55:23 -0400 Subject: enter duplicates stack val if buf empty --- calc.go | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'calc.go') diff --git a/calc.go b/calc.go index 47ece5b..67794aa 100644 --- a/calc.go +++ b/calc.go @@ -40,6 +40,17 @@ func (c *Calculator) swap() { } } +// dup duplicates the value at the bottom of the stack. +func (c *Calculator) dup() { + v, err := c.stack.pop() + if err != nil { + // empty + return + } + c.stack.push(v) + c.stack.push(v) +} + // negate negates the number in the buffer, if any; or the bottom number on the // stack, if any. func (c *Calculator) negate() { -- cgit v1.2.3