From 1e6b57251aed3546af5fce2333e6ee34f28b1982 Mon Sep 17 00:00:00 2001 From: Claude Code Date: Tue, 30 Dec 2025 06:36:00 -0500 Subject: [PATCH] Fix BigFloat support by generalizing procf type constraint MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The `procf` function had a hardcoded `s::Float64` type constraint that caused a MethodError when using BigFloat with 位 >= 6 (which uses the ad_rand algorithm). Changed to `s::Real` to support arbitrary precision. Added BigFloat tests to prevent regression. 馃 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 --- src/PoissonRandom.jl | 2 +- test/runtests.jl | 24 ++++++++++++++++++++++++ 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/src/PoissonRandom.jl b/src/PoissonRandom.jl index 2b01e9e..8c4509b 100644 --- a/src/PoissonRandom.jl +++ b/src/PoissonRandom.jl @@ -82,7 +82,7 @@ function ad_rand(rng::AbstractRNG, 位::Real) end # Procedure F -function procf(位::Real, K::Int, s::Float64) +function procf(位::Real, K::Int, s::Real) # can be pre-computed, but does not seem to affect performance INV_SQRT_2PI = inv(sqrt(2pi)) 蠅 = INV_SQRT_2PI / s diff --git a/test/runtests.jl b/test/runtests.jl index a172671..f5efbca 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -89,3 +89,27 @@ println("testing mixed random sampler") for 位 in [5.0, 10.0, 15.0, 20.0, 30.0] test_samples(pois_rand, Distributions.Poisson(位), n_tsamples) end + +@testset "BigFloat support" begin + @testset "count_rand with BigFloat (位 < 6)" begin + for _ in 1:100 + result = pois_rand(BigFloat(3.0)) + @test result isa Integer + @test result >= 0 + end + end + @testset "ad_rand with BigFloat (位 >= 6)" begin + for _ in 1:100 + result = pois_rand(BigFloat(15.0)) + @test result isa Integer + @test result >= 0 + end + end + @testset "statistical validity with BigFloat" begin + n = 10000 + 位 = BigFloat(10.0) + samples = [pois_rand(位) for _ in 1:n] + sample_mean = mean(samples) + @test abs(sample_mean - Float64(位)) < 3 * sqrt(Float64(位)) + end +end