You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
LogNormal Variance loses precision for small σ and returns 0 below σ≈1e-8 #84
Math.Exp(σ²) - 1.0 cancels catastrophically for small σ²: relative error grows like ε/σ², and once σ² < ~1.1e-16 the result is exactly 0.
Measured on net10.0 with the expression copied verbatim (expected = ExpM1(σ²)·exp(2μ+σ²)):
σ
Variance
expected
rel. error
1e-9
0
1e-18
100 %
1e-8
0
1e-16
100 %
1e-7
9.992e-15
1.0000e-14
8e-4
1e-6
1.0000889e-12
1.0000000e-12
8.9e-5
Independent of logMean, so LogNormal(5, 1e-8) reports Variance == 0 and StandardDeviation == 0 while Mean ≈ 148.
Why it matters
Same defect class as the recently fixed #49 (Triangular variance cancellation) and #52 (Exponential CDF near zero). Users modelling tight multiplicative noise (log-scale σ of 1e-6…1e-9) get a variance wrong in the leading digits, or zero. The cure is already in the project: Shared/SpecialFunctions.cs:149 has a cancellation-free ExpM1, and it is already linked into the LogNormal project.
Priority: Low. This is a numerical-precision defect limited to very small log-scale σ (below about 1e-6). The fix is one line using the SpecialFunctions.ExpM1 already linked into the project.
Area / suggested assignment: Distribution providers (Essentials.DistributionProviders.LogNormal).
Activity
matt-edmondson commentedon Oct 6, 2026
Triage
SpecialFunctions.ExpM1already linked into the project.Essentials.DistributionProviders.LogNormal).Generated by Claude Code
Compute LogNormal variance with ExpM1 so a small sigma keeps its digi…