Add implementation of sterlings approximation
All checks were successful
timw4mail/rusty-numbers/pipeline/head This commit looks good

This commit is contained in:
Timothy Warren 2020-03-04 16:53:31 -05:00
parent 94f39fff07
commit 272b7360f5

View File

@ -3,6 +3,9 @@
//! Playin' with Numerics in Rust
#![forbid(unsafe_code)]
use std::f64::consts::PI;
use std::f64::consts::E;
#[cfg_attr(tarpaulin, skip)]
pub mod bigint;
pub mod num;
@ -173,6 +176,13 @@ pub fn factorial(n: usize) -> Option<u128> {
}
}
pub fn approx_factorial(n: f64) -> f64 {
let power = (n / E).powf(n);
let root = (PI * 2.0 * n).sqrt();
power * root
}
#[cfg(test)]
#[cfg_attr(tarpaulin, skip)]
mod tests {