>From 1338258a0d6a76bbe30bf03b90acff4559c24120 Mon Sep 17 00:00:00 2001 From: Taylor R Campbell Date: Thu, 13 Dec 2018 02:46:27 +0000 Subject: [PATCH] Use a lerp that never overshoots when determining bin boundaries. In binary80 arithmetic, the bins for the log-logistic distribution, which has a very fat tail, were computed with a value that overshot the bounds, leading to a NaN intermediate. One defensive way to avoid this would be to change the cdf_* and sf_* functions for distributions of bounded support -- like log-logistic, which is supported only on (0, +\infty) -- to return -/+inf for points outside the bounds. But for testing purposes it might be better not to work defensively like that because it might mask upstream problems. --- src/test/test_prob_distr.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/test/test_prob_distr.c b/src/test/test_prob_distr.c index 002497e08..16919e0f4 100644 --- a/src/test/test_prob_distr.c +++ b/src/test/test_prob_distr.c @@ -1002,14 +1002,14 @@ bin_cdfs(const struct dist *dist, double lo, double hi, double *logP, size_t n) logP[0] = log(CDF(x_1) - 0); /* 0 = CDF(-inf) */ for (i = 1; i < n2; i++) { x_0 = x_1; - x_1 = lo + i*w; + x_1 = (i <= n/2 ? lo + i*w : hi - (n - 2 - i)*w); logP[i] = log(CDF(x_1) - CDF(x_0)); } x_0 = hi; logP[n - 1] = log(SF(x_0) - 0); /* 0 = SF(+inf) = 1 - CDF(+inf) */ for (i = 1; i < n - n2; i++) { x_1 = x_0; - x_0 = hi - i*w; + x_0 = (i <= n/2 ? hi - i*w : lo + (n - 2 - i)*w); logP[n - i - 1] = log(SF(x_0) - SF(x_1)); } #undef SF -- 2.19.1