From fbbdb834f9f3900d56347dc250f5995f173129b0 Mon Sep 17 00:00:00 2001 From: Linus Torvalds Date: Sun, 11 Nov 2012 18:32:31 +0100 Subject: Fix average temperature statistics We generate the average temperature statistics by adding up the (converted to user unites - not in millikelvin) temperatures and then dividing by the number of dives we've added up over. HOWEVER. We did that summing of the temperatures into an integer variable, even though the converted temperatures are floating point. So things got rounded down to integers and the average temperature was just bogus (although reasonably close). We could do the summing of the temperatures in millikelvin and only doing the conversion to the user at the very end. But the smaller patch is to just change the accumulator to a double value. Signed-off-by: Linus Torvalds Signed-off-by: Dirk Hohndel --- statistics.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/statistics.c b/statistics.c index 08fb73814..a946d500b 100644 --- a/statistics.c +++ b/statistics.c @@ -71,7 +71,7 @@ typedef struct { volume_t avg_sac; int max_temp; int min_temp; - unsigned int combined_temp; + double combined_temp; unsigned int combined_count; unsigned int selection_size; unsigned int total_sac_time; @@ -286,7 +286,7 @@ static void process_interval_stats(stats_t stats_interval, GtkTreeIter *parent, /* Average water temperature */ value = get_temp_units(stats_interval.min_temp, &unit); if (stats_interval.combined_temp && stats_interval.combined_count) { - snprintf(value_str, sizeof(value_str), "%.1f %s", stats_interval.combined_temp / (stats_interval.combined_count * 1.0), unit); + snprintf(value_str, sizeof(value_str), "%.1f %s", stats_interval.combined_temp / stats_interval.combined_count, unit); add_cell_to_tree(store, value_str, 12, row); } else { add_cell_to_tree(store, "", 12, row); @@ -611,7 +611,7 @@ static void show_total_dive_stats(struct dive *dive) set_label(stats_w.min_temp, "%.1f %s", value, unit); } if (stats_ptr->combined_temp && stats_ptr->combined_count) - set_label(stats_w.avg_temp, "%.1f %s", stats_ptr->combined_temp / (stats_ptr->combined_count * 1.0), unit); + set_label(stats_w.avg_temp, "%.1f %s", stats_ptr->combined_temp / stats_ptr->combined_count, unit); if (stats_ptr->max_temp) { value = get_temp_units(stats_ptr->max_temp, &unit); set_label(stats_w.max_temp, "%.1f %s", value, unit); -- cgit v1.2.3-70-g09d2