Add implementation of sterlings approximation
All checks were successful
timw4mail/rusty-numbers/pipeline/head This commit looks good
All checks were successful
timw4mail/rusty-numbers/pipeline/head This commit looks good
This commit is contained in:
parent
94f39fff07
commit
272b7360f5
10
src/lib.rs
10
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<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 {
|
||||
|
Loading…
Reference in New Issue
Block a user