1
0
mirror of https://github.com/vlang/v.git synced 2023-08-10 21:13:21 +03:00

math: sqrti, powi, factoriali (#12072)

This commit is contained in:
05st
2021-10-08 14:07:44 -05:00
committed by GitHub
parent cd5b304cbf
commit 43931be451
5 changed files with 88 additions and 0 deletions

View File

@ -53,3 +53,16 @@ fn log_factorial_asymptotic_expansion(n int) f64 {
}
return log_factorial + sum
}
// factoriali returns 1 for n <= 0 and -1 if the result is too large for a 64 bit integer
pub fn factoriali(n int) i64 {
if n <= 0 {
return i64(1)
}
if n < 21 {
return i64(factorials_table[n])
}
return i64(-1)
}