I am coding an algorithm to compute large Bernoulli numbers. This algorithm requires factorials of very large values in floating point. The algorithm works for up to about Bernoulli(44_000_000) but fails for 45_000_000. I have found that the issue is the conversion of Integer to Float fails if the conversion results in an exponent of 2^30-1 or greater (results in an infinity). This does not look like a max precision problem but a max exponent problem. I am fairly new to Rust and do not know how to report issues to crate owners. Some test code is below:
use rug::{Float, Complete};
use rug::{Integer};
use rug::integer::IntegerExt64;
fn main() {
let fact = Integer::factorial(44_000_000).complete();
let sb = fact.significant_bits_64();
let fact_float = Float::with_val_64(sb, fact);
println!("fact_float 44m finite? {}", fact_float.is_finite());
let fact = Integer::factorial(45_000_000).complete();
let sb = fact.significant_bits_64();
let fact_float = Float::with_val_64(sb, fact);
println!("fact_float 45m finite? {}", fact_float.is_finite());
}
I have also tried floating point factorial function but it so slow that I can't test large values, but they probably will fail any way.
I realize that log gamma would generate a smaller number but what I need is the large number for the Bernoulli calculation. The algorithm chosen produces a fraction (num/den). Bernoulli numerators grow dramatically as the Bernoulli numbers increase. Algorithm used is a Zeta and Staudt_Claussen algorithm that computes the numerator in floating point and truncates the final answer to an integer. The factorial is one component of the numerator computation.
Click the link under "Repository" on the right-hand side to go to the source repository for the crate on GitHub, GitLab, Codeberg, or the like (in this case, https://gitlab.com/tspiteri/rug)
Create an issue in the web interface there. For GitLab, issues are listed under "Plan" > "Work Items" in the menu on the left-hand side.