summaryrefslogtreecommitdiffstats
path: root/src/interp.c
diff options
context:
space:
mode:
authorAndrés M <andmarti1424@users.noreply.github.com>2021-02-26 16:02:05 -0300
committerGitHub <noreply@github.com>2021-02-26 16:02:05 -0300
commit680ea2379f068a8dfc0b6304b21f222adbcae755 (patch)
treee2e8b75a37d7fac5b0689058241a194a0856f9f8 /src/interp.c
parentceda9c89520768818439ffafd80df564384eb243 (diff)
parentf5bc0daa807c128b853656f9d8b2d7789e4ef262 (diff)
Merge pull request #472 from Epicalert/freeze
Add factorial function
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 a64d3fc..eb924fc 100644
--- a/src/interp.c
+++ b/src/interp.c
@@ -1299,6 +1299,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:
+ {
+ double 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;
}
@@ -3060,6 +3068,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;