summaryrefslogtreecommitdiffstats
path: root/core/cochran.c
diff options
context:
space:
mode:
authorGravatar Dirk Hohndel <dirk@hohndel.org>2019-03-17 11:35:09 -0700
committerGravatar Dirk Hohndel <dirk@hohndel.org>2019-03-17 15:11:31 -0700
commit47f92b92acc9eb4875590cf197d60e053cd36781 (patch)
tree1e22c884bacfaa8f933fd5b47daf1fdc0b6dc9b3 /core/cochran.c
parent412c242c10bba270314fe0bee9a14a0547f97014 (diff)
downloadsubsurface-47f92b92acc9eb4875590cf197d60e053cd36781.tar.gz
Core: cast to the correct type
While in the specific calculations here there isn't really a risk that float might overflow, it seems odd to cast to float in order to assign to double. This caused an Alert via LGTM.com Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Diffstat (limited to 'core/cochran.c')
-rw-r--r--core/cochran.c18
1 files changed, 9 insertions, 9 deletions
diff --git a/core/cochran.c b/core/cochran.c
index a3e4c9a13..d89617431 100644
--- a/core/cochran.c
+++ b/core/cochran.c
@@ -450,23 +450,23 @@ static void cochran_parse_samples(struct dive *dive, const unsigned char *log,
// Get starting depth and temp (tank PSI???)
switch (config.type) {
case TYPE_GEMINI:
- depth = (float) (log[CMD_START_DEPTH]
+ depth = (double) (log[CMD_START_DEPTH]
+ log[CMD_START_DEPTH + 1] * 256) / 4;
temp = log[CMD_START_TEMP];
psi = log[CMD_START_PSI] + log[CMD_START_PSI + 1] * 256;
- sgc_rate = (float)(log[CMD_START_SGC]
+ sgc_rate = (double)(log[CMD_START_SGC]
+ log[CMD_START_SGC + 1] * 256) / 2;
profile_period = log[CMD_PROFILE_PERIOD];
break;
case TYPE_COMMANDER:
- depth = (float) (log[CMD_START_DEPTH]
+ depth = (double) (log[CMD_START_DEPTH]
+ log[CMD_START_DEPTH + 1] * 256) / 4;
temp = log[CMD_START_TEMP];
profile_period = log[CMD_PROFILE_PERIOD];
break;
case TYPE_EMC:
- depth = (float) log [EMC_START_DEPTH] / 256
+ depth = (double) log [EMC_START_DEPTH] / 256
+ log[EMC_START_DEPTH + 1];
temp = log[EMC_START_TEMP];
profile_period = log[EMC_PROFILE_PERIOD];
@@ -503,7 +503,7 @@ static void cochran_parse_samples(struct dive *dive, const unsigned char *log,
}
// Depth is in every sample
- depth_sample = (float)(s[0] & 0x3F) / 4 * (s[0] & 0x40 ? -1 : 1);
+ depth_sample = (double)(s[0] & 0x3F) / 4 * (s[0] & 0x40 ? -1 : 1);
depth += depth_sample;
#ifdef COCHRAN_DEBUG
@@ -528,13 +528,13 @@ static void cochran_parse_samples(struct dive *dive, const unsigned char *log,
ascent_rate = (s[1] & 0x7f) * (s[1] & 0x80 ? 1 : -1);
break;
case 2: // PSI change
- psi -= (float)(s[1] & 0x7f) * (s[1] & 0x80 ? 1 : -1) / 4;
+ psi -= (double)(s[1] & 0x7f) * (s[1] & 0x80 ? 1 : -1) / 4;
break;
case 1: // SGC rate
- sgc_rate -= (float)(s[1] & 0x7f) * (s[1] & 0x80 ? 1 : -1) / 2;
+ sgc_rate -= (double)(s[1] & 0x7f) * (s[1] & 0x80 ? 1 : -1) / 2;
break;
case 3: // Temperature
- temp = (float)s[1] / 2 + 20;
+ temp = (double)s[1] / 2 + 20;
break;
}
break;
@@ -544,7 +544,7 @@ static void cochran_parse_samples(struct dive *dive, const unsigned char *log,
ascent_rate = (s[1] & 0x7f) * (s[1] & 0x80 ? 1: -1);
break;
case 1: // Temperature
- temp = (float)s[1] / 2 + 20;
+ temp = (double)s[1] / 2 + 20;
break;
}
// Get NDL and deco information