fix histogram
authorLaurent Mazet <mazet@softndesign.org>
Sun, 28 Sep 2025 11:29:53 +0000 (13:29 +0200)
committerLaurent Mazet <mazet@softndesign.org>
Sun, 28 Sep 2025 11:29:53 +0000 (13:29 +0200)
stat.c

diff --git a/stat.c b/stat.c
index 4e5850ad08d27206c630027e3725c18ae3211e38..f28730efe3298eae3e86a8fc9417b6eb4f1192f9 100644 (file)
--- a/stat.c
+++ b/stat.c
@@ -84,7 +84,10 @@ void compute_statistics (int64_t *points, int nb, int bins)
 
     double gap = (max - min) / bins;
     for (int i = 0; i < nb - 1; i++) {
-        hist[(int)((points[i] - min) * bins / (max -min))]++;
+        int j = (points[i] - min) * bins / (max -min);
+        if (j < 0) j = 0;
+        if (j >= bins) j = bins - 1;
+        hist[j]++;
     }
     hist[bins - 1]++;