aboutsummaryrefslogtreecommitdiffstats
path: root/func.go
diff options
context:
space:
mode:
Diffstat (limited to 'func.go')
-rw-r--r--func.go18
1 files changed, 18 insertions, 0 deletions
diff --git a/func.go b/func.go
new file mode 100644
index 0000000..914cb61
--- /dev/null
+++ b/func.go
@@ -0,0 +1,18 @@
+package main
+
+import "math"
+
+// parseFunction returns nil is s is not a valid function.
+func parseFunction(s string) func(Stack) {
+ switch s {
+ case "sin":
+ return sin
+ }
+ return nil
+}
+
+func sin(stack Stack) {
+ if len(stack) > 0 {
+ stack[len(stack)-1] = math.Sin(stack[len(stack)-1])
+ }
+}