improve histogram
authorLaurent MAZET <laurent.mazet@thalesgroup.com>
Mon, 29 Sep 2025 13:59:51 +0000 (15:59 +0200)
committerLaurent MAZET <laurent.mazet@thalesgroup.com>
Mon, 29 Sep 2025 13:59:51 +0000 (15:59 +0200)
stat.c

diff --git a/stat.c b/stat.c
index f39d441883857e92773e86d83feed91e164bc764..b7f464391b445c82052a6642fb356a05c381e1e8 100644 (file)
--- a/stat.c
+++ b/stat.c
@@ -1,14 +1,15 @@
 /* statistic module */
 
 #include <assert.h>
-#include <inttypes.h>
 #include <math.h>
 #include <stdio.h>
 #include <stdlib.h>
 
 #include "stat.h"
 
-void compute_statistics (int64_t *points, int nb, int bins)
+#define STEP 20
+
+void compute_statistics (unsigned int *points, int nb, int bins)
 {
 
     printf ("Nb of points = %d\n", nb);
@@ -50,7 +51,7 @@ void compute_statistics (int64_t *points, int nb, int bins)
         int change_done = 0;
         for (int i = 1; i < nb - 1; i++) {
             if (points[i + 1] < points[i]) {
-                int64_t tmp = points[i];
+                unsigned int tmp = points[i];
                 points[i] = points[i + 1];
                 points[i + 1] = tmp;
                 change_done = 1;
@@ -93,6 +94,10 @@ void compute_statistics (int64_t *points, int nb, int bins)
 
     printf ("Histogram (%d)\n", nb);
     for (int i = 0; i < bins; i++) {
+        int h = (STEP * hist[i] + nb / 2 - 1) / nb;
+        for (int j = 0; j < STEP; j++) {
+            printf ("%c", (j < h) ? '#' : ' ');
+        }
         printf (" [%.2lf - %.2lf] = %d\n", min + i * gap, min + (i + 1) * gap, hist[i]);
     }