Rug, any way to set max exponent value?

⚓ Rust    📅 2026-06-06    👤 surdeus    👁️ 1      

surdeus

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.

5 posts - 2 participants

Read full topic

🏷️ Rust_feed