From 295b1b78d888b528f7a5a23411b1a82d4b39eed1 Mon Sep 17 00:00:00 2001 From: "Robert C. Helling" Date: Fri, 10 Mar 2017 07:22:31 +0100 Subject: Make depth conversion work for negative depths This is needed in the altitude pressure conversion as there negative altitudes are possible (for diving in the netherlands or the Dead Sea). Signed-off-by: Robert C. Helling --- core/dive.c | 12 ++++++++---- core/dive.h | 2 +- 2 files changed, 9 insertions(+), 5 deletions(-) (limited to 'core') diff --git a/core/dive.c b/core/dive.c index 48dd929f4..b091e2bc7 100644 --- a/core/dive.c +++ b/core/dive.c @@ -248,11 +248,15 @@ int units_to_sac(double volume) return rint(volume * 1000); } -unsigned int units_to_depth(double depth) +depth_t units_to_depth(double depth) { - if (get_units()->length == METERS) - return rint(depth * 1000); - return feet_to_mm(depth); + depth_t internaldepth; + if (get_units()->length == METERS) { + internaldepth.mm = rint(depth * 1000); + } else { + internaldepth.mm = feet_to_mm(depth); + } + return internaldepth; } double get_depth_units(int mm, int *frac, const char **units) diff --git a/core/dive.h b/core/dive.h index ba92e1083..194cb978c 100644 --- a/core/dive.h +++ b/core/dive.h @@ -131,7 +131,7 @@ extern double get_temp_units(unsigned int mk, const char **units); extern double get_weight_units(unsigned int grams, int *frac, const char **units); extern double get_vertical_speed_units(unsigned int mms, int *frac, const char **units); -extern unsigned int units_to_depth(double depth); +extern depth_t units_to_depth(double depth); extern int units_to_sac(double volume); /* Volume in mliter of a cylinder at pressure 'p' */ -- cgit v1.2.3-70-g09d2