From 19367b04cdabb504b664de41540f4b278652b958 Mon Sep 17 00:00:00 2001 From: NunoSempere Date: Fri, 2 Feb 2024 18:03:56 +0100 Subject: [PATCH] look through histogram function to convince myself of correctness --- squiggle_more.c | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/squiggle_more.c b/squiggle_more.c index 1168845..5eb10ab 100644 --- a/squiggle_more.c +++ b/squiggle_more.c @@ -242,9 +242,8 @@ void array_print_histogram(double* xs, int n_samples, int n_bins) { return; } - double min_value = xs[0], max_value = xs[0]; - // Find the minimum and maximum values from the samples + double min_value = xs[0], max_value = xs[0]; for (int i = 0; i < n_samples; i++) { if (xs[i] < min_value) { min_value = xs[i]; @@ -260,8 +259,7 @@ void array_print_histogram(double* xs, int n_samples, int n_bins) { } // Calculate bin width - double range = max_value - min_value; - double bin_width = range / n_bins; + double bin_width = (max_value - min_value) / n_bins; // Fill the bins with sample counts for (int i = 0; i < n_samples; i++) { @@ -339,10 +337,7 @@ void array_print_90_ci_histogram(double* xs, int n_samples, int n_bins){ if (min_value == max_value) { max_value++; } - - // Calculate bin width - double range = max_value - min_value; - double bin_width = range / n_bins; + double bin_width = (max_value - min_value) / n_bins; // Fill the bins with sample counts int below_min = 0, above_max = 0; @@ -399,7 +394,6 @@ void array_print_90_ci_histogram(double* xs, int n_samples, int n_bins){ // Free the allocated memory for bins free(bins); - } /* Algebra manipulations */