diff --git a/hipparchus-stat/src/main/java/org/hipparchus/stat/fitting/EmpiricalDistribution.java b/hipparchus-stat/src/main/java/org/hipparchus/stat/fitting/EmpiricalDistribution.java index 20c77480b..137936f7d 100644 --- a/hipparchus-stat/src/main/java/org/hipparchus/stat/fitting/EmpiricalDistribution.java +++ b/hipparchus-stat/src/main/java/org/hipparchus/stat/fitting/EmpiricalDistribution.java @@ -578,7 +578,11 @@ public double density(double x) { } final int binIndex = findBin(x); final RealDistribution kernel = getKernel(binStats.get(binIndex)); - return kernel.density(x) * pB(binIndex) / kB(binIndex); + double kernelDensity = kernel.density(x); + if (kernelDensity == 0d) { + return 0d; + } + return kernelDensity * pB(binIndex) / kB(binIndex); } /**