1 /* PSPP - a program for statistical analysis.
2 Copyright (C) 2004 Free Software Foundation, Inc.
4 This program is free software: you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation, either version 3 of the License, or
7 (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program. If not, see <http://www.gnu.org/licenses/>. */
19 #include <gsl/gsl_histogram.h>
21 #include "histogram.h"
22 #include "chart-geometry.h"
26 histogram_create(double bins, double x_min, double x_max)
31 double upper_limit, lower_limit;
33 gsl_histogram *hist = gsl_histogram_alloc(bins);
35 bin_width = chart_rounded_tick((x_max - x_min)/ bins);
36 bin_width_2 = bin_width / 2.0;
38 n = ceil( x_max / (bin_width_2) ) ;
39 if ( ! (n % 2 ) ) n++;
40 upper_limit = n * bin_width_2;
42 n = floor( x_min / (bin_width_2) ) ;
43 if ( ! (n % 2 ) ) n--;
44 lower_limit = n * bin_width_2;
46 gsl_histogram_set_ranges_uniform(hist, lower_limit, upper_limit);