forked from personal/squiggle.c
tweak: add decimal points tweak to original histogram function
This commit is contained in:
parent
c676a22ba8
commit
d78a5cd182
|
@ -276,18 +276,13 @@ void array_print_histogram(double* xs, int n_samples, int n_bins) {
|
||||||
double bin_start = min_value + i * bin_width;
|
double bin_start = min_value + i * bin_width;
|
||||||
double bin_end = bin_start + bin_width;
|
double bin_end = bin_start + bin_width;
|
||||||
|
|
||||||
if(bin_width < 0.01){
|
int decimalPlaces = 1;
|
||||||
printf(" [%4.4f, %4.4f", bin_start, bin_end);
|
if((0 < bin_width) && (bin_width < 1)){
|
||||||
} else if(bin_width < 0.1){
|
int magnitude = (int) floor(log10(bin_width));
|
||||||
printf(" [%4.3f, %4.3f", bin_start, bin_end);
|
decimalPlaces = -magnitude;
|
||||||
} else if(bin_width < 1){
|
decimalPlaces = decimalPlaces > 10 ? 10 : decimalPlaces;
|
||||||
printf(" [%4.2f, %4.2f", bin_start, bin_end);
|
|
||||||
} else if(bin_width < 10){
|
|
||||||
printf(" [%4.1f, %4.1f", bin_start, bin_end);
|
|
||||||
} else {
|
|
||||||
printf(" [%4.0f, %4.0f", bin_start, bin_end);
|
|
||||||
}
|
}
|
||||||
|
printf(" [%*.*f, %*.*f", 4+decimalPlaces, decimalPlaces, bin_start, 4+decimalPlaces, decimalPlaces, bin_end);
|
||||||
char interval_delimiter = ')';
|
char interval_delimiter = ')';
|
||||||
if(i == (n_bins-1)){
|
if(i == (n_bins-1)){
|
||||||
interval_delimiter = ']'; // last bucket is inclusive
|
interval_delimiter = ']'; // last bucket is inclusive
|
||||||
|
|
Loading…
Reference in New Issue
Block a user