Skip to content

NormalDist.overlap() returns incorrect values when one distribution has an extremely large mean, violating both its doc and mathematical correctness. #140941

@T90REAL

Description

@T90REAL

Bug report

Bug description:

The test is as following:

from statistics import NormalDist

nd1 = NormalDist(1.3e+303, 1.0)  # Extreme but valid mu

nd2_a = NormalDist(0.0, 1.0)
print(f"sigma2=1:   {nd1.overlap(nd2_a)}")   # 0.0 (correct by chance)

nd2_b = NormalDist(0.0, 100.0)
print(f"sigma2=100: {nd1.overlap(nd2_b)}")   # 1.0 (WRONG!)

nd2_c = NormalDist(0.0, 372.0)
print(f"sigma2=372: {nd1.overlap(nd2_c)}")   # nan (violates API)
sigma2=1:   0.0
sigma2=100: 1.0
sigma2=372: nan

It outputs nan.

CPython versions tested on:

3.12

Operating systems tested on:

Linux

Metadata

Metadata

Assignees

Labels

stdlibStandard Library Python modules in the Lib/ directorytype-bugAn unexpected behavior, bug, or error

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions