mirror of
https://github.com/sam-astro/Z-Sharp.git
synced 2025-12-11 16:22:12 +00:00
add functions
This commit is contained in:
parent
ba92119cfe
commit
7d7033cd61
61
ZSharp/ZS.h
61
ZSharp/ZS.h
@ -142,5 +142,64 @@ func GetKey(keyName)
|
|||||||
//{
|
//{
|
||||||
// ZS.System.SplitThread(function)
|
// ZS.System.SplitThread(function)
|
||||||
//}
|
//}
|
||||||
|
|
||||||
|
//Function made by Kaputchino
|
||||||
|
|
||||||
|
//return the number of combinaison
|
||||||
|
|
||||||
|
func Comb(n, r)
|
||||||
|
{
|
||||||
|
return Perm(n ,r) / Fac(r)
|
||||||
|
}
|
||||||
|
//return the number of permutation
|
||||||
|
|
||||||
|
func Perm(n, r)
|
||||||
|
{
|
||||||
|
if n < 0
|
||||||
|
{
|
||||||
|
ZS.System.PrintLine("n muss be superior or equal to 0")
|
||||||
|
return -1
|
||||||
|
}
|
||||||
|
if r < 0
|
||||||
|
{
|
||||||
|
ZS.System.PrintLine("r muss be superior or equal to 0")
|
||||||
|
return -1
|
||||||
|
}
|
||||||
|
if r > n
|
||||||
|
{
|
||||||
|
ZS.System.PrintLine("r muss be inferor or equal to n")
|
||||||
|
return -1
|
||||||
|
}
|
||||||
|
return Fac(n) / Fac(n - r)
|
||||||
|
}
|
||||||
|
//return the factorial of a number
|
||||||
|
|
||||||
|
func Fac(x)
|
||||||
|
{
|
||||||
|
int r = 1
|
||||||
|
while x > 1
|
||||||
|
{
|
||||||
|
r = r * x
|
||||||
|
x = x - 1
|
||||||
|
}
|
||||||
|
return r
|
||||||
|
}
|
||||||
|
//return exp(x) by using the taylor method, not extremly accurate
|
||||||
|
|
||||||
|
func TaylorExp(x)
|
||||||
|
{
|
||||||
|
float sum = 0
|
||||||
|
float term = 1
|
||||||
|
int i = 1
|
||||||
|
float sumterm = 1
|
||||||
|
while sum != sumterm
|
||||||
|
{
|
||||||
|
sum = sumterm
|
||||||
|
term = term * x / i
|
||||||
|
i = i + 1
|
||||||
|
sumterm = sumterm + term
|
||||||
|
}
|
||||||
|
return sum
|
||||||
|
}
|
||||||
)"
|
)"
|
||||||
;
|
;
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user