summaryrefslogtreecommitdiffstats
path: root/src/interp.c
diff options
context:
space:
mode:
authorEpicalert <epicalert@protonmail.com>2020-11-26 23:23:52 +0800
committerEpicalert <epicalert@protonmail.com>2020-11-26 23:23:52 +0800
commitb53100eb6c3d22390f917be7cc943658074ca4ac (patch)
tree0e30fb7fcccb7098586dcbf7a332065b53d26ebd /src/interp.c
parentbdd936a12c68f74419e3307760439335e1b18133 (diff)
add new function @fact
Diffstat (limited to 'src/interp.c')
-rw-r--r--src/interp.c9
1 files changed, 9 insertions, 0 deletions
diff --git a/src/interp.c b/src/interp.c
index f2d7bfd..7b81f13 100644
--- a/src/interp.c
+++ b/src/interp.c
@@ -1289,6 +1289,14 @@ double eval(register struct ent * ent, register struct enode * e) {
case MAGENTA: return ((double) COLOR_MAGENTA);
case CYAN: return ((double) COLOR_CYAN);
case WHITE: return ((double) COLOR_WHITE);
+ case FACT:
+ {
+ int total = eval(ent, e->e.o.left);
+ for (int i = eval(ent, e->e.o.left) - 1; i > 0; i--) {
+ total *= i;
+ }
+ return total > 0 ? total : 1;
+ }
default: sc_error ("Illegal numeric expression");
exprerr = 1;
}
@@ -3045,6 +3053,7 @@ void decompile(register struct enode *e, int priority) {
for (s = "@default_color"; (line[linelim++] = *s++); );
linelim--;
break;
+ case FACT: one_arg("@fact(", e); break;
default:
decompile(e->e.o.left, mypriority);
line[linelim++] = e->op;