summaryrefslogtreecommitdiffstats
path: root/statistics.c
diff options
context:
space:
mode:
authorGravatar Linus Torvalds <torvalds@linux-foundation.org>2012-11-11 18:32:31 +0100
committerGravatar Dirk Hohndel <dirk@hohndel.org>2012-11-11 18:49:29 +0100
commitfbbdb834f9f3900d56347dc250f5995f173129b0 (patch)
treef418dac06d4cc584a61f8b605b72f2a86f230695 /statistics.c
parentec042222f0827c7394458a4a0aa4dcbce0c390fb (diff)
downloadsubsurface-fbbdb834f9f3900d56347dc250f5995f173129b0.tar.gz
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 <torvalds@linux-foundation.org> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Diffstat (limited to 'statistics.c')
-rw-r--r--statistics.c6
1 files 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);