aboutsummaryrefslogtreecommitdiff
path: root/bc_funcs/std.bc
diff options
context:
space:
mode:
authorMango0x45 <thomasvoss@live.com>2021-01-05 10:16:29 +0000
committerMango0x45 <thomasvoss@live.com>2021-01-05 10:16:29 +0000
commit1b6264627c67fbbd0d99902aa18ce045cff24319 (patch)
treee248b508e12fc59273eb96cc43d8d9ea2dfa29e2 /bc_funcs/std.bc
parent4fd5dd089a227e4e05aac5608631ee478a3c4c00 (diff)
downloadsteve-bot-1b6264627c67fbbd0d99902aa18ce045cff24319.tar
steve-bot-1b6264627c67fbbd0d99902aa18ce045cff24319.tar.gz
steve-bot-1b6264627c67fbbd0d99902aa18ce045cff24319.tar.bz2
steve-bot-1b6264627c67fbbd0d99902aa18ce045cff24319.tar.lz
steve-bot-1b6264627c67fbbd0d99902aa18ce045cff24319.tar.xz
steve-bot-1b6264627c67fbbd0d99902aa18ce045cff24319.tar.zst
steve-bot-1b6264627c67fbbd0d99902aa18ce045cff24319.zip
Add factorial function
Diffstat (limited to 'bc_funcs/std.bc')
-rw-r--r--bc_funcs/std.bc19
1 files changed, 19 insertions, 0 deletions
diff --git a/bc_funcs/std.bc b/bc_funcs/std.bc
index a369505..6bc58b1 100644
--- a/bc_funcs/std.bc
+++ b/bc_funcs/std.bc
@@ -3,3 +3,22 @@ define abs(x) {
x *= -1
return x
}
+
+define fact(x) {
+ auto r
+
+ if (x < 0) {
+ print "Error: Negative factorial\n"
+ return 0
+ }
+
+ if (x % 1 != 0) {
+ print "Error: Non-integer factorial\n"
+ return 0
+ }
+
+ r = 1
+ for (i = 2; i <= x; i++)
+ r *= i
+ return r
+}