From 5651ba534258aaa9de658cc4b09eda7ecf792b6a Mon Sep 17 00:00:00 2001 From: Parth Paradkar Date: Thu, 27 Jun 2019 22:46:02 +0530 Subject: [PATCH] math: add tau constant, add factorial function --- math/math.v | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/math/math.v b/math/math.v index d5e9c6745e..7d071a037d 100644 --- a/math/math.v +++ b/math/math.v @@ -8,6 +8,7 @@ const ( E = 2.71828182845904523536028747135266249775724709369995957496696763 Pi = 3.14159265358979323846264338327950288419716939937510582097494459 Phi = 1.61803398874989484820458683436563811772030917980576286213544862 + Tau = 6.28318530717958647692528676655900576839433879875021164194988918 Sqrt2 = 1.41421356237309504880168872420969807856967187537694807317667974 SqrtE = 1.64872127070012814684865078781416357165377610071014801157507931 @@ -128,3 +129,12 @@ pub fn tanh(a f64) f64 { pub fn trunc(a f64) f64 { return C.trunc(a) } + +pub fn factorial(a int) i64 { + mut prod := 1 + for i:= 0; i < a; i++ { + prod = prod * (i+1) + } + return prod +} +