about summary refs log tree commit diff stats
path: root/cmds.c
diff options
context:
space:
mode:
authorDaniel <steew0x8@protonmail.com>2021-11-06 18:19:38 +0100
committerDaniel <steew0x8@protonmail.com>2021-11-06 18:19:38 +0100
commit2dba790a5b0d1e61acee6da4b85a486b036446ba (patch)
tree419c3c27793c26b31d205259ac5dce223b90e208 /cmds.c
parentfe6314692dbdbf69db8b3e8a3979c1f1d21d621c (diff)
downloadrpncalc-2dba790a5b0d1e61acee6da4b85a486b036446ba.tar.gz
added some functions
Diffstat (limited to 'cmds.c')
-rw-r--r--cmds.c19
1 files changed, 19 insertions, 0 deletions
diff --git a/cmds.c b/cmds.c
index 2a88041..7960834 100644
--- a/cmds.c
+++ b/cmds.c
@@ -16,9 +16,28 @@ stack ffloor(stack stack) {
   return stack;
 }
 
+stack flogB(stack stack) {
+  stack.val[stack.count-2] = log2(stack.val[stack.count-2])/log2(stack.val[stack.count-1]);
+  stack.val[--stack.count] = 0;
+  return stack;
+}
+
+stack fnegate(stack stack) {
+  stack.val[stack.count-1] *= -1;
+  return stack;
+}
+
+stack fpop(stack stack) {
+  stack.val[--stack.count] = 0;
+  return stack;
+}
+
 command CMD_LIST[] = {
+  {"p", &fpop, "pop last element"},
   {"ceil", &fceil, "truncate to the next integer"},
   {"floor", &ffloor, "truncate to the previous integer"},
+  {"log", &flogB, "calculate logarithm in base LAST_NUM of LAST_NUM-1"},
+  {"neg", &fnegate, "change last element's sign"},
   {0, 0, 0}
 };