Crates.io | stirling_approximation |
lib.rs | stirling_approximation |
version | 0.1.0 |
source | src |
created_at | 2023-07-20 13:50:15.996177 |
updated_at | 2023-07-20 13:50:15.996177 |
description | Stirling's approximation to factorials |
homepage | |
repository | https://github.com/lucasmelodev1/stirling-approximation.git |
max_upload_size | |
id | 921300 |
size | 4,429 |
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
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);