/* PSPP - a program for statistical analysis.
- Copyright (C) 1997-9, 2000, 2007, 2009 Free Software Foundation, Inc.
+ Copyright (C) 1997-9, 2000, 2007, 2009, 2010 Free Software Foundation, Inc.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
- if ( chart == GFT_HIST && var_is_numeric (v) )
+ if ( chart == GFT_HIST && var_is_numeric (v) && ft->n_valid > 0)
{
double d[frq_n_stats];
struct histogram *hist ;
/* Calculate percentiles. */
+ assert (ft->n_valid > 0);
+
for (i = 0; i < n_percentiles; i++)
{
percentiles[i].flag = 0;
double x_max = -DBL_MAX;
struct histogram *hist;
- const double bins = 11;
+ int bins;
struct hsh_iterator hi;
struct hsh_table *fh = ft->data;
if ( frq->value.f > x_max ) x_max = frq->value.f ;
}
+ /* Sturges' formula. */
+ bins = ceil (log (ft->valid_cases) / log (2) + 1);
+ if (bins < 5)
+ bins = 5;
+
hist = histogram_create (bins, x_min, x_max);
for( i = 0 ; i < ft->n_valid ; ++i )