1 unstable release

0.1.0 Jul 20, 2023

#11 in #factorial

MIT license

4KB

Stirling's Approximation

Provide 2 functions (to_f64 and to_bigdecimal) that calculates the factorial of a number using the Stirling's Approximation formula.

This formula let you calculate the factorial with a very good precision for big numbers, and is not recursive, which saves a lot of computation time.

The formula is the following: n! = sqrt(2 * PI * n) * (n / E) ^ n

Example

use stirling_approximation;

let factorial = stirling_approximation::to_f64(10);
let high_precision_factorial = stirling_approximation::to_bigdecimal(10);

println!("The factorial of 10 is: {}", factorial);
println!("The high precision factorial of 10 is: {}", high_precision_factorial);

lib.rs:

Stirling's Approximation

Provide 2 functions (to_f64 and to_bigdecimal) that calculates the factorial of a number using the Stirling's Approximation formula.

This formula let you calculate the factorial with a very good precision for big numbers, and is not recursive, which saves a lot of computation time.

The formula is the following: n! = sqrt(2 * PI * n) * (n / E) ^ n

Example

use stirling_approximation;

let factorial = stirling_approximation::to_f64(10);
let high_precision_factorial = stirling_approximation::to_bigdecimal(10);

println!("The factorial of 10 is: {}", factorial);
println!("The high precision factorial of 10 is: {}", high_precision_factorial);

Dependencies

~1MB
~26K SLoC