diff --git a/src/lib.rs b/src/lib.rs index 5d7c946..46f9c62 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -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 { } } +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 {