From 38a8f30267df395708eed55b23e26ec529fe90fe Mon Sep 17 00:00:00 2001 From: Kamil Date: Sun, 24 Oct 2021 18:23:04 +0000 Subject: [PATCH] added factorial --- maths/math_functions.nu | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/maths/math_functions.nu b/maths/math_functions.nu index f029123..1a72fc1 100644 --- a/maths/math_functions.nu +++ b/maths/math_functions.nu @@ -22,6 +22,11 @@ def delta [ a: number, b: number, c: number ] { ( $b ** 2 ) - ( 4 * $a * $c) } +#factorial of a given number, works fine only for n<21 (integer range) +def fact [num:number] { + if $num >= 0 { if $num < 2 {$num} {seq 2 $num | math product} } { echo 'Error: can only calculate non-negative integers'} +} + #TODO: # -sin, cos, tan table for 0-90 degrees # -radians to degrees and reversed