aboutsummaryrefslogtreecommitdiffstats
path: root/calc.go
diff options
context:
space:
mode:
authorSam Anthony <sam@samanthony.xyz>2025-09-29 08:55:23 -0400
committerSam Anthony <sam@samanthony.xyz>2025-09-29 08:55:23 -0400
commit9562328016fb0e219184a0ec18a5e6ea8f09d138 (patch)
treef23e25ec88a875eb9f2aa1a87ca2d3c302b6c85a /calc.go
parent0e9a7e9508a5c7c0107aa2475b7e6770e25857c5 (diff)
downloadpfc-9562328016fb0e219184a0ec18a5e6ea8f09d138.zip
enter duplicates stack val if buf empty
Diffstat (limited to 'calc.go')
-rw-r--r--calc.go11
1 files changed, 11 insertions, 0 deletions
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() {