Fix math overflow crash in computing profiling statistics
This commit is contained in:
parent
3856fdd827
commit
ddaf2407a9
1 changed files with 13 additions and 5 deletions
|
|
@ -94,16 +94,24 @@ namespace psemek::util
|
|||
// https://en.wikipedia.org/wiki/Maximum_entropy_probability_distribution#Other_examples
|
||||
// https://en.wikipedia.org/wiki/Truncated_normal_distribution
|
||||
|
||||
float const mu = mean();
|
||||
float const sigma = stddev();
|
||||
T const mu = mean();
|
||||
T const sigma = stddev();
|
||||
|
||||
if (sigma == T{0})
|
||||
return mu;
|
||||
|
||||
float const alpha = (min - mu) / sigma;
|
||||
float const beta = (max - mu) / sigma;
|
||||
T const alpha = (min - mu) / sigma;
|
||||
T const beta = (max - mu) / sigma;
|
||||
|
||||
return mu + sigma * detail::normal_cdf_inv(std::lerp(detail::normal_cdf(alpha), detail::normal_cdf(beta), p));
|
||||
T const t = std::lerp(detail::normal_cdf(alpha), detail::normal_cdf(beta), p);
|
||||
|
||||
if (t <= T{0})
|
||||
return min;
|
||||
|
||||
if (t >= T{1})
|
||||
return max;
|
||||
|
||||
return mu + sigma * detail::normal_cdf_inv(t);
|
||||
}
|
||||
|
||||
friend base_statistics merge(base_statistics const & s1, base_statistics const & s2)
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue