Skip to content

bug: Binomial::entropy returns Some(0.0) at n = u64::MAX, and panics on a debug build #449

Description

@FBruzzesi

Binomial::entropy() at n = u64::MAX returns Some(0.0). On a debug build the same call panics with attempt to add with overflow instead.

Every other n I tried returns a finite value, and the other moments at the same parameters are fine: mean and variance both return the expected finite numbers at n = u64::MAX. So this looks specific to entropy.

Environment: statrs main at 10cf6d610c1b8febc0b0606a443eb5e9d6ac8b7d, rustc 1.97.1, aarch64-apple-darwin

Reproducer

use statrs::distribution::Binomial;
use statrs::statistics::Distribution;

fn main() {
    let dist = Binomial::new(0.5, u64::MAX).unwrap();
    println!("{:?}", dist.entropy());
}
$ cargo run --release
Some(0.0)

$ cargo run
thread 'main' panicked at src/distribution/binomial/mod.rs:222:17:
attempt to add with overflow

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions