summaryrefslogtreecommitdiffstats
path: root/core
diff options
context:
space:
mode:
Diffstat (limited to 'core')
-rw-r--r--core/cochran.c34
-rw-r--r--core/datatrak.c4
-rw-r--r--core/deco.c4
-rw-r--r--core/device.c24
-rw-r--r--core/dive.h2
-rw-r--r--core/divelist.c8
-rw-r--r--core/divesite.c2
-rw-r--r--core/file.c16
-rw-r--r--core/gaspressures.c2
-rw-r--r--core/libdivecomputer.c15
-rw-r--r--core/liquivision.c4
-rw-r--r--core/parse-xml.c32
-rw-r--r--core/planner.c12
-rw-r--r--core/profile.c18
-rw-r--r--core/save-html.c2
-rw-r--r--core/statistics.c10
-rw-r--r--core/uemis-downloader.c4
-rw-r--r--core/uemis.c6
18 files changed, 100 insertions, 99 deletions
diff --git a/core/cochran.c b/core/cochran.c
index b42ed8233..c31e78f79 100644
--- a/core/cochran.c
+++ b/core/cochran.c
@@ -578,14 +578,14 @@ static void cochran_parse_samples(struct dive *dive, const unsigned char *log,
if (temp < *min_temp) *min_temp = temp;
*avg_depth = (*avg_depth * seconds + depth) / (seconds + 1);
- sample->depth.mm = depth * FEET * 1000;
+ sample->depth.mm = lrint(depth * FEET * 1000);
sample->ndl.seconds = ndl;
sample->in_deco = in_deco;
sample->stoptime.seconds = deco_time;
- sample->stopdepth.mm = deco_ceiling * FEET * 1000;
+ sample->stopdepth.mm = lrint(deco_ceiling * FEET * 1000);
sample->temperature.mkelvin = C_to_mkelvin((temp - 32) / 1.8);
sample->sensor = 0;
- sample->cylinderpressure.mbar = psi * PSI / 100;
+ sample->cylinderpressure.mbar = lrint(psi * PSI / 100);
finish_sample(dc);
@@ -693,13 +693,13 @@ static void cochran_parse_dive(const unsigned char *decode, unsigned mod,
dive->number = log[CMD_NUMBER] + log[CMD_NUMBER + 1] * 256 + 1;
dc->duration.seconds = (log[CMD_BT] + log[CMD_BT + 1] * 256) * 60;
dc->surfacetime.seconds = (log[CMD_SIT] + log[CMD_SIT + 1] * 256) * 60;
- dc->maxdepth.mm = (log[CMD_MAX_DEPTH] +
- log[CMD_MAX_DEPTH + 1] * 256) / 4 * FEET * 1000;
- dc->meandepth.mm = (log[CMD_AVG_DEPTH] +
- log[CMD_AVG_DEPTH + 1] * 256) / 4 * FEET * 1000;
+ dc->maxdepth.mm = lrint((log[CMD_MAX_DEPTH] +
+ log[CMD_MAX_DEPTH + 1] * 256) / 4 * FEET * 1000);
+ dc->meandepth.mm = lrint((log[CMD_AVG_DEPTH] +
+ log[CMD_AVG_DEPTH + 1] * 256) / 4 * FEET * 1000);
dc->watertemp.mkelvin = C_to_mkelvin((log[CMD_MIN_TEMP] / 32) - 1.8);
- dc->surface_pressure.mbar = ATM / BAR * pow(1 - 0.0000225577
- * (double) log[CMD_ALTITUDE] * 250 * FEET, 5.25588) * 1000;
+ dc->surface_pressure.mbar = lrint(ATM / BAR * pow(1 - 0.0000225577
+ * (double) log[CMD_ALTITUDE] * 250 * FEET, 5.25588) * 1000);
dc->salinity = 10000 + 150 * log[CMD_WATER_CONDUCTIVITY];
SHA1(log + CMD_NUMBER, 2, (unsigned char *)csum);
@@ -734,13 +734,13 @@ static void cochran_parse_dive(const unsigned char *decode, unsigned mod,
dive->number = log[EMC_NUMBER] + log[EMC_NUMBER + 1] * 256 + 1;
dc->duration.seconds = (log[EMC_BT] + log[EMC_BT + 1] * 256) * 60;
dc->surfacetime.seconds = (log[EMC_SIT] + log[EMC_SIT + 1] * 256) * 60;
- dc->maxdepth.mm = (log[EMC_MAX_DEPTH] +
- log[EMC_MAX_DEPTH + 1] * 256) / 4 * FEET * 1000;
- dc->meandepth.mm = (log[EMC_AVG_DEPTH] +
- log[EMC_AVG_DEPTH + 1] * 256) / 4 * FEET * 1000;
+ dc->maxdepth.mm = lrint((log[EMC_MAX_DEPTH] +
+ log[EMC_MAX_DEPTH + 1] * 256) / 4 * FEET * 1000);
+ dc->meandepth.mm = lrint((log[EMC_AVG_DEPTH] +
+ log[EMC_AVG_DEPTH + 1] * 256) / 4 * FEET * 1000);
dc->watertemp.mkelvin = C_to_mkelvin((log[EMC_MIN_TEMP] - 32) / 1.8);
- dc->surface_pressure.mbar = ATM / BAR * pow(1 - 0.0000225577
- * (double) log[EMC_ALTITUDE] * 250 * FEET, 5.25588) * 1000;
+ dc->surface_pressure.mbar = lrint(ATM / BAR * pow(1 - 0.0000225577
+ * (double) log[EMC_ALTITUDE] * 250 * FEET, 5.25588) * 1000);
dc->salinity = 10000 + 150 * (log[EMC_WATER_CONDUCTIVITY] & 0x3);
SHA1(log + EMC_NUMBER, 2, (unsigned char *)csum);
@@ -758,8 +758,8 @@ static void cochran_parse_dive(const unsigned char *decode, unsigned mod,
// Check for corrupt dive
if (corrupt_dive) {
- dc->maxdepth.mm = max_depth * FEET * 1000;
- dc->meandepth.mm = avg_depth * FEET * 1000;
+ dc->maxdepth.mm = lrint(max_depth * FEET * 1000);
+ dc->meandepth.mm = lrint(avg_depth * FEET * 1000);
dc->watertemp.mkelvin = C_to_mkelvin((min_temp - 32) / 1.8);
dc->duration.seconds = duration;
}
diff --git a/core/datatrak.c b/core/datatrak.c
index ab888977c..d46167cc8 100644
--- a/core/datatrak.c
+++ b/core/datatrak.c
@@ -384,7 +384,7 @@ bool dt_dive_parser(FILE *archivo, struct dive *dt_dive)
*/
read_bytes(2);
if (tmp_2bytes != 0x7FFF && dt_dive->cylinder[0].type.size.mliter)
- dt_dive->cylinder[0].gas_used.mliter = dt_dive->cylinder[0].type.size.mliter * (tmp_2bytes / 100.0);
+ dt_dive->cylinder[0].gas_used.mliter = lrint(dt_dive->cylinder[0].type.size.mliter * (tmp_2bytes / 100.0));
/*
* Dive Type 1 - Bit table. Subsurface don't have this record, but
@@ -625,7 +625,7 @@ bool dt_dive_parser(FILE *archivo, struct dive *dt_dive)
read_bytes(1);
if (is_nitrox) {
dt_dive->cylinder[0].gasmix.o2.permille =
- (tmp_1byte & 0x0F ? 20.0 + 2 * (tmp_1byte & 0x0F) : 21.0) * 10;
+ lrint((tmp_1byte & 0x0F ? 20.0 + 2 * (tmp_1byte & 0x0F) : 21.0) * 10);
} else {
dt_dive->cylinder[0].gasmix.o2.permille = tmp_1byte * 10;
read_bytes(1) // Jump over one byte, unknown use
diff --git a/core/deco.c b/core/deco.c
index 8247800da..66ed219ee 100644
--- a/core/deco.c
+++ b/core/deco.c
@@ -622,10 +622,10 @@ int deco_allowed_depth(double tissues_tolerance, double surface_pressure, struct
/* Avoid negative depths */
pressure_delta = tissues_tolerance > surface_pressure ? tissues_tolerance - surface_pressure : 0.0;
- depth = rel_mbar_to_depth(pressure_delta * 1000, dive);
+ depth = rel_mbar_to_depth(lrint(pressure_delta * 1000), dive);
if (!smooth)
- depth = ceil(depth / DECO_STOPS_MULTIPLIER_MM) * DECO_STOPS_MULTIPLIER_MM;
+ depth = lrint(ceil(depth / DECO_STOPS_MULTIPLIER_MM) * DECO_STOPS_MULTIPLIER_MM);
if (depth > 0 && depth < buehlmann_config.last_deco_stop_in_mtr * 1000)
depth = buehlmann_config.last_deco_stop_in_mtr * 1000;
diff --git a/core/device.c b/core/device.c
index 86c30dbd9..e20aecb5a 100644
--- a/core/device.c
+++ b/core/device.c
@@ -64,10 +64,10 @@
static int fill_samples(struct sample *s, int max_d, int avg_d, int max_t, double slope, double d_frac)
{
double t_frac = max_t * (1 - avg_d / (double)max_d);
- int t1 = max_d / slope;
- int t4 = max_t - t1 * d_frac;
- int t3 = t4 - (t_frac - t1) / (1 - d_frac);
- int t2 = t3 - t1 * (1 - d_frac);
+ int t1 = lrint(max_d / slope);
+ int t4 = lrint(max_t - t1 * d_frac);
+ int t3 = lrint(t4 - (t_frac - t1) / (1 - d_frac));
+ int t2 = lrint(t3 - t1 * (1 - d_frac));
if (t1 < 0 || t1 > t2 || t2 > t3 || t3 > t4 || t4 > max_t)
return 0;
@@ -77,9 +77,9 @@ static int fill_samples(struct sample *s, int max_d, int avg_d, int max_t, doubl
s[2].time.seconds = t2;
s[2].depth.mm = max_d;
s[3].time.seconds = t3;
- s[3].depth.mm = max_d * d_frac;
+ s[3].depth.mm = lrint(max_d * d_frac);
s[4].time.seconds = t4;
- s[4].depth.mm = max_d * d_frac;
+ s[4].depth.mm = lrint(max_d * d_frac);
return 1;
}
@@ -92,18 +92,18 @@ static void fill_samples_no_avg(struct sample *s, int max_d, int max_t, double s
{
// shallow or short dives are just trapecoids based on the given slope
if (max_d < 10000 || max_t < 600) {
- s[1].time.seconds = max_d / slope;
+ s[1].time.seconds = lrint(max_d / slope);
s[1].depth.mm = max_d;
- s[2].time.seconds = max_t - max_d / slope;
+ s[2].time.seconds = max_t - lrint(max_d / slope);
s[2].depth.mm = max_d;
} else {
- s[1].time.seconds = max_d / slope;
+ s[1].time.seconds = lrint(max_d / slope);
s[1].depth.mm = max_d;
- s[2].time.seconds = max_t - max_d / slope - 180;
+ s[2].time.seconds = max_t - lrint(max_d / slope) - 180;
s[2].depth.mm = max_d;
- s[3].time.seconds = max_t - 5000 / slope - 180;
+ s[3].time.seconds = max_t - lrint(5000 / slope) - 180;
s[3].depth.mm = 5000;
- s[4].time.seconds = max_t - 5000 / slope;
+ s[4].time.seconds = max_t - lrint(5000 / slope);
s[4].depth.mm = 5000;
}
}
diff --git a/core/dive.h b/core/dive.h
index 164886df6..981cdc0b9 100644
--- a/core/dive.h
+++ b/core/dive.h
@@ -499,7 +499,7 @@ static inline depth_t gas_mnd(struct gasmix *mix, depth_t end, struct dive *dive
pressure_t ppo2n2;
ppo2n2.mbar = depth_to_mbar(end.mm, dive);
- double maxambient = ppo2n2.mbar / (1 - get_he(mix) / 1000.0);
+ int maxambient = lrint(ppo2n2.mbar / (1 - get_he(mix) / 1000.0));
rounded_depth.mm = lrint(((double)mbar_to_depth(maxambient, dive)) / roundto) * roundto;
return rounded_depth;
}
diff --git a/core/divelist.c b/core/divelist.c
index d47b034bd..f3465830e 100644
--- a/core/divelist.c
+++ b/core/divelist.c
@@ -178,7 +178,7 @@ static int calculate_otu(struct dive *dive)
po2 = sample->setpoint.mbar;
} else {
int o2 = active_o2(dive, dc, sample->time);
- po2 = o2 * depth_to_atm(sample->depth.mm, dive);
+ po2 = lrint(o2 * depth_to_atm(sample->depth.mm, dive));
}
if (po2 >= 500)
otu += pow((po2 - 500) / 1000.0, 0.83) * t / 30.0;
@@ -243,7 +243,7 @@ static int calculate_cns(struct dive *dive)
po2 = sample->setpoint.mbar;
} else {
int o2 = active_o2(dive, dc, sample->time);
- po2 = o2 * depth_to_atm(sample->depth.mm, dive);
+ po2 = lrint(o2 * depth_to_atm(sample->depth.mm, dive));
}
/* CNS don't increse when below 500 matm */
if (po2 < 500)
@@ -256,7 +256,7 @@ static int calculate_cns(struct dive *dive)
cns += ((double)t) / ((double)cns_table[j][1]) * 100;
}
/* save calculated cns in dive struct */
- dive->cns = cns;
+ dive->cns = lrint(cns);
return dive->cns;
}
/*
@@ -305,7 +305,7 @@ static int calculate_sac(struct dive *dive)
sac = airuse / pressure * 60 / duration;
/* milliliters per minute.. */
- return sac * 1000;
+ return lrint(sac * 1000);
}
/* for now we do this based on the first divecomputer */
diff --git a/core/divesite.c b/core/divesite.c
index 73c198e99..cbcc89d91 100644
--- a/core/divesite.c
+++ b/core/divesite.c
@@ -65,7 +65,7 @@ unsigned int get_distance(degrees_t lat1, degrees_t lon1, degrees_t lat2, degree
double c = 2 * atan2(sqrt(a), sqrt(1.0 - a));
// Earth radious in metres
- return 6371000 * c;
+ return lrint(6371000 * c);
}
/* find the closest one, no more than distance meters away - if more than one at same distance, pick the first */
diff --git a/core/file.c b/core/file.c
index 5b910e72b..889a9102b 100644
--- a/core/file.c
+++ b/core/file.c
@@ -293,31 +293,31 @@ static void add_sample_data(struct sample *sample, enum csv_format type, double
sample->cylinderpressure.mbar = psi_to_mbar(val * 4);
break;
case POSEIDON_DEPTH:
- sample->depth.mm = val * 0.5 *1000;
+ sample->depth.mm = lrint(val * 0.5 * 1000);
break;
case POSEIDON_TEMP:
sample->temperature.mkelvin = C_to_mkelvin(val * 0.2);
break;
case POSEIDON_SETPOINT:
- sample->setpoint.mbar = val * 10;
+ sample->setpoint.mbar = lrint(val * 10);
break;
case POSEIDON_SENSOR1:
- sample->o2sensor[0].mbar = val * 10;
+ sample->o2sensor[0].mbar = lrint(val * 10);
break;
case POSEIDON_SENSOR2:
- sample->o2sensor[1].mbar = val * 10;
+ sample->o2sensor[1].mbar = lrint(val * 10);
break;
case POSEIDON_PRESSURE:
- sample->cylinderpressure.mbar = val * 1000;
+ sample->cylinderpressure.mbar = lrint(val * 1000);
break;
case POSEIDON_O2CYLINDER:
- sample->o2cylinderpressure.mbar = val * 1000;
+ sample->o2cylinderpressure.mbar = lrint(val * 1000);
break;
case POSEIDON_NDL:
- sample->ndl.seconds = val * 60;
+ sample->ndl.seconds = lrint(val * 60);
break;
case POSEIDON_CEILING:
- sample->stopdepth.mm = val * 1000;
+ sample->stopdepth.mm = lrint(val * 1000);
break;
}
}
diff --git a/core/gaspressures.c b/core/gaspressures.c
index e74f26d3b..146086483 100644
--- a/core/gaspressures.c
+++ b/core/gaspressures.c
@@ -137,7 +137,7 @@ static void fill_missing_segment_pressures(pr_track_t *list, enum interpolation_
pt += list->pressure_time;
pressure = start;
if (pt_sum)
- pressure -= (start - end) * (double)pt / pt_sum;
+ pressure -= lrint((start - end) * (double)pt / pt_sum);
list->end = pressure;
if (list == tmp)
break;
diff --git a/core/libdivecomputer.c b/core/libdivecomputer.c
index 2d8c79b4c..799846fc2 100644
--- a/core/libdivecomputer.c
+++ b/core/libdivecomputer.c
@@ -166,10 +166,11 @@ static int parse_gasmixes(device_data_t *devdata, struct dive *dive, dc_parser_t
* First, the pressures are off by a constant factor. WTF?
* Then we can round the wet sizes so we get to multiples of 10
* for cuft sizes (as that's all that you can enter) */
- dive->cylinder[i].type.workingpressure.mbar *= 206.843 / 206.7;
+ dive->cylinder[i].type.workingpressure.mbar = lrint(
+ dive->cylinder[i].type.workingpressure.mbar * 206.843 / 206.7 );
char name_buffer[9];
- int rounded_size = ml_to_cuft(gas_volume(&dive->cylinder[i],
- dive->cylinder[i].type.workingpressure));
+ int rounded_size = lrint(ml_to_cuft(gas_volume(&dive->cylinder[i],
+ dive->cylinder[i].type.workingpressure)));
rounded_size = (int)((rounded_size + 5) / 10) * 10;
switch (dive->cylinder[i].type.workingpressure.mbar) {
case 206843:
@@ -189,8 +190,8 @@ static int parse_gasmixes(device_data_t *devdata, struct dive *dive, dc_parser_t
break;
}
dive->cylinder[i].type.description = copy_string(name_buffer);
- dive->cylinder[i].type.size.mliter = cuft_to_l(rounded_size) * 1000 /
- mbar_to_atm(dive->cylinder[i].type.workingpressure.mbar);
+ dive->cylinder[i].type.size.mliter = lrint(cuft_to_l(rounded_size) * 1000 /
+ mbar_to_atm(dive->cylinder[i].type.workingpressure.mbar));
}
}
if (tank.gasmix != i) { // we don't handle this, yet
@@ -203,8 +204,8 @@ static int parse_gasmixes(device_data_t *devdata, struct dive *dive, dc_parser_t
// this new API also gives us the beginning and end pressure for the tank
if (!IS_FP_SAME(tank.beginpressure, 0.0) && !IS_FP_SAME(tank.endpressure, 0.0)) {
- dive->cylinder[i].start.mbar = tank.beginpressure * 1000;
- dive->cylinder[i].end.mbar = tank.endpressure * 1000;
+ dive->cylinder[i].start.mbar = lrint(tank.beginpressure * 1000);
+ dive->cylinder[i].end.mbar = lrint(tank.endpressure * 1000);
}
}
#endif
diff --git a/core/liquivision.c b/core/liquivision.c
index 9347a724a..e2e9ff75e 100644
--- a/core/liquivision.c
+++ b/core/liquivision.c
@@ -234,9 +234,9 @@ static void parse_dives (int log_version, const unsigned char *buf, unsigned int
// Xeo, with CNS and OTU
start_cns = *(float *) (buf + ptr);
ptr += 4;
- dive->cns = *(float *) (buf + ptr); // end cns
+ dive->cns = lrintf(*(float *) (buf + ptr)); // end cns
ptr += 4;
- dive->otu = *(float *) (buf + ptr);
+ dive->otu = lrintf(*(float *) (buf + ptr));
ptr += 4;
dive_mode = *(buf + ptr++); // 0=Deco, 1=Gauge, 2=None
algorithm = *(buf + ptr++); // 0=ZH-L16C+GF
diff --git a/core/parse-xml.c b/core/parse-xml.c
index 23dc76715..2bd00bafa 100644
--- a/core/parse-xml.c
+++ b/core/parse-xml.c
@@ -425,7 +425,7 @@ static void temperature(char *buffer, temperature_t *temperature)
case FLOAT:
switch (xml_parsing_units.temperature) {
case KELVIN:
- temperature->mkelvin = val.fp * 1000;
+ temperature->mkelvin = lrint(val.fp * 1000);
break;
case CELSIUS:
temperature->mkelvin = C_to_mkelvin(val.fp);
@@ -2219,7 +2219,7 @@ extern int dm5_cylinders(void *handle, int columns, char **data, char **column)
if (atof(data[6]) == 0.0 && cur_dive->cylinder[cur_cylinder_index].start.mbar)
cur_dive->cylinder[cur_cylinder_index].type.size.mliter = 12000;
else
- cur_dive->cylinder[cur_cylinder_index].type.size.mliter = (atof(data[6])) * 1000;
+ cur_dive->cylinder[cur_cylinder_index].type.size.mliter = lrint((atof(data[6])) * 1000);
}
if (data[2])
cur_dive->cylinder[cur_cylinder_index].gasmix.o2.permille = atoi(data[2]) * 10;
@@ -2240,7 +2240,7 @@ extern int dm5_gaschange(void *handle, int columns, char **data, char **column)
cur_event.time.seconds = atoi(data[0]);
if (data[1]) {
strcpy(cur_event.name, "gaschange");
- cur_event.value = atof(data[1]);
+ cur_event.value = lrint(atof(data[1]));
}
event_end();
@@ -2308,7 +2308,7 @@ extern int dm4_dive(void *param, int columns, char **data, char **column)
settings_end();
if (data[6])
- cur_dive->dc.maxdepth.mm = atof(data[6]) * 1000;
+ cur_dive->dc.maxdepth.mm = lrint(atof(data[6]) * 1000);
if (data[8])
cur_dive->dc.airtemp.mkelvin = C_to_mkelvin(atoi(data[8]));
if (data[9])
@@ -2327,7 +2327,7 @@ extern int dm4_dive(void *param, int columns, char **data, char **column)
if (data[11] && atoi(data[11]) > 0)
cur_dive->cylinder[cur_cylinder_index].end.mbar = (atoi(data[11]));
if (data[12])
- cur_dive->cylinder[cur_cylinder_index].type.size.mliter = (atof(data[12])) * 1000;
+ cur_dive->cylinder[cur_cylinder_index].type.size.mliter = lrint((atof(data[12])) * 1000);
if (data[13])
cur_dive->cylinder[cur_cylinder_index].type.workingpressure.mbar = (atoi(data[13]));
if (data[20])
@@ -2347,7 +2347,7 @@ extern int dm4_dive(void *param, int columns, char **data, char **column)
sample_start();
cur_sample->time.seconds = i * interval;
if (profileBlob)
- cur_sample->depth.mm = profileBlob[i] * 1000;
+ cur_sample->depth.mm = lrintf(profileBlob[i] * 1000.0f);
else
cur_sample->depth.mm = cur_dive->dc.maxdepth.mm;
@@ -2431,7 +2431,7 @@ extern int dm5_dive(void *param, int columns, char **data, char **column)
settings_end();
if (data[6])
- cur_dive->dc.maxdepth.mm = atof(data[6]) * 1000;
+ cur_dive->dc.maxdepth.mm = lrint(atof(data[6]) * 1000);
if (data[8])
cur_dive->dc.airtemp.mkelvin = C_to_mkelvin(atoi(data[8]));
if (data[9])
@@ -2477,7 +2477,7 @@ extern int dm5_dive(void *param, int columns, char **data, char **column)
sample_start();
cur_sample->time.seconds = i * interval;
- cur_sample->depth.mm = depth[0] * 1000;
+ cur_sample->depth.mm = lrintf(depth[0] * 1000.0f);
/*
* Limit temperatures and cylinder pressures to somewhat
* sensible values
@@ -2506,7 +2506,7 @@ extern int dm5_dive(void *param, int columns, char **data, char **column)
sample_start();
cur_sample->time.seconds = i * interval;
if (profileBlob)
- cur_sample->depth.mm = profileBlob[i] * 1000;
+ cur_sample->depth.mm = lrintf(profileBlob[i] * 1000.0f);
else
cur_sample->depth.mm = cur_dive->dc.maxdepth.mm;
@@ -2601,9 +2601,9 @@ extern int shearwater_cylinders(void *handle, int columns, char **data, char **c
cylinder_start();
if (data[0])
- cur_dive->cylinder[cur_cylinder_index].gasmix.o2.permille = atof(data[0]) * 1000;
+ cur_dive->cylinder[cur_cylinder_index].gasmix.o2.permille = lrint(atof(data[0]) * 1000);
if (data[1])
- cur_dive->cylinder[cur_cylinder_index].gasmix.he.permille = atof(data[1]) * 1000;
+ cur_dive->cylinder[cur_cylinder_index].gasmix.he.permille = lrint(atof(data[1]) * 1000);
cylinder_end();
return 0;
@@ -2620,7 +2620,7 @@ extern int shearwater_changes(void *handle, int columns, char **data, char **col
cur_event.time.seconds = atoi(data[0]);
if (data[1]) {
strcpy(cur_event.name, "gaschange");
- cur_event.value = atof(data[1]) * 100;
+ cur_event.value = lrint(atof(data[1]) * 100);
}
event_end();
@@ -2657,11 +2657,11 @@ extern int shearwater_profile_sample(void *handle, int columns, char **data, cha
if (data[0])
cur_sample->time.seconds = atoi(data[0]);
if (data[1])
- cur_sample->depth.mm = metric ? atof(data[1]) * 1000 : feet_to_mm(atof(data[1]));
+ cur_sample->depth.mm = metric ? lrint(atof(data[1]) * 1000) : feet_to_mm(atof(data[1]));
if (data[2])
cur_sample->temperature.mkelvin = metric ? C_to_mkelvin(atof(data[2])) : F_to_mkelvin(atof(data[2]));
if (data[3]) {
- cur_sample->setpoint.mbar = atof(data[3]) * 1000;
+ cur_sample->setpoint.mbar = lrint(atof(data[3]) * 1000);
cur_dive->dc.divemode = CCR;
}
if (data[4])
@@ -2710,7 +2710,7 @@ extern int shearwater_dive(void *param, int columns, char **data, char **column)
/* TODO: verify that metric calculation is correct */
if (data[6])
- cur_dive->dc.maxdepth.mm = metric ? atof(data[6]) * 1000 : feet_to_mm(atof(data[6]));
+ cur_dive->dc.maxdepth.mm = metric ? lrint(atof(data[6]) * 1000) : feet_to_mm(atof(data[6]));
if (data[7])
cur_dive->dc.duration.seconds = atoi(data[7]) * 60;
@@ -3294,7 +3294,7 @@ extern int divinglog_dive(void *param, int columns, char **data, char **column)
utf8_string(data[4], &cur_dive->notes);
if (data[5])
- cur_dive->dc.maxdepth.mm = atof(data[5]) * 1000;
+ cur_dive->dc.maxdepth.mm = lrint(atof(data[5]) * 1000);
if (data[6])
cur_dive->dc.duration.seconds = atoi(data[6]) * 60;
diff --git a/core/planner.c b/core/planner.c
index cc099b01f..771ea6acc 100644
--- a/core/planner.c
+++ b/core/planner.c
@@ -220,7 +220,7 @@ void fill_default_cylinder(cylinder_t *cyl)
} else {
cyl->type.workingpressure.mbar = psi_to_mbar(ti->psi);
if (ti->psi)
- cyl->type.size.mliter = cuft_to_l(ti->cuft) * 1000 / bar_to_atm(psi_to_bar(ti->psi));
+ cyl->type.size.mliter = lrint(cuft_to_l(ti->cuft) * 1000 / bar_to_atm(psi_to_bar(ti->psi)));
}
// MOD of air
cyl->depth = gas_mod(&cyl->gasmix, pO2, &displayed_dive, 1);
@@ -241,12 +241,12 @@ static void update_cylinder_pressure(struct dive *d, int old_depth, int new_dept
if (!cyl)
return;
mean_depth.mm = (old_depth + new_depth) / 2;
- gas_used.mliter = depth_to_atm(mean_depth.mm, d) * sac / 60 * duration * factor / 1000;
+ gas_used.mliter = lrint(depth_to_atm(mean_depth.mm, d) * sac / 60 * duration * factor / 1000);
cyl->gas_used.mliter += gas_used.mliter;
if (in_deco)
cyl->deco_gas_used.mliter += gas_used.mliter;
if (cyl->type.size.mliter) {
- delta_p.mbar = gas_used.mliter * 1000.0 / cyl->type.size.mliter * gas_compressibility_factor(&cyl->gasmix, cyl->end.mbar / 1000.0);
+ delta_p.mbar = lrint(gas_used.mliter * 1000.0 / cyl->type.size.mliter * gas_compressibility_factor(&cyl->gasmix, cyl->end.mbar / 1000.0));
cyl->end.mbar -= delta_p.mbar;
}
}
@@ -830,7 +830,7 @@ static void add_plan_to_notes(struct diveplan *diveplan, struct dive *dive, bool
depth_unit);
/* Get SAC values and units for printing it in gas consumption */
- float bottomsacvalue, decosacvalue;
+ double bottomsacvalue, decosacvalue;
int sacdecimals;
const char* sacunit;
@@ -858,10 +858,10 @@ static void add_plan_to_notes(struct diveplan *diveplan, struct dive *dive, bool
volume = get_volume_units(cyl->gas_used.mliter, NULL, &unit);
deco_volume = get_volume_units(cyl->deco_gas_used.mliter, NULL, &unit);
if (cyl->type.size.mliter) {
- int remaining_gas = (double)cyl->end.mbar * cyl->type.size.mliter / 1000.0 / gas_compressibility_factor(&cyl->gasmix, cyl->end.mbar / 1000.0);
+ int remaining_gas = lrint((double)cyl->end.mbar * cyl->type.size.mliter / 1000.0 / gas_compressibility_factor(&cyl->gasmix, cyl->end.mbar / 1000.0));
double deco_pressure_bar = isothermal_pressure(&cyl->gasmix, 1.0, remaining_gas + cyl->deco_gas_used.mliter, cyl->type.size.mliter)
- cyl->end.mbar / 1000.0;
- deco_pressure = get_pressure_units(1000.0 * deco_pressure_bar, &pressure_unit);
+ deco_pressure = get_pressure_units(lrint(1000.0 * deco_pressure_bar), &pressure_unit);
pressure = get_pressure_units(cyl->start.mbar - cyl->end.mbar, &pressure_unit);
/* Warn if the plan uses more gas than is available in a cylinder
* This only works if we have working pressure for the cylinder
diff --git a/core/profile.c b/core/profile.c
index 484d9b15a..1a50c7efd 100644
--- a/core/profile.c
+++ b/core/profile.c
@@ -112,7 +112,7 @@ int get_maxdepth(struct plot_info *pi)
/* Minimum 30m, rounded up to 10m, with at least 3m to spare */
md = MAX((unsigned)30000, ROUND_UP(mm + 3000, 10000));
}
- md += pi->maxpp * 9000;
+ md += lrint(pi->maxpp * 9000);
return md;
}
@@ -194,7 +194,7 @@ static int get_local_sac(struct plot_data *entry1, struct plot_data *entry2, str
airuse = gas_volume(cyl, a) - gas_volume(cyl, b);
/* milliliters per minute */
- return airuse / atm * 60 / duration;
+ return lrint(airuse / atm * 60 / duration);
}
#define HALF_INTERVAL 9 * 30
@@ -1020,8 +1020,8 @@ void calculate_deco_information(struct dive *dive, struct divecomputer *dc, stru
double m_value = buehlmann_inertgas_a[j] + entry->ambpressure / buehlmann_inertgas_b[j];
entry->ceilings[j] = deco_allowed_depth(tolerated_by_tissue[j], surface_pressure, dive, 1);
entry->percentages[j] = tissue_inertgas_saturation[j] < entry->ambpressure ?
- tissue_inertgas_saturation[j] / entry->ambpressure * AMB_PERCENTAGE :
- AMB_PERCENTAGE + (tissue_inertgas_saturation[j] - entry->ambpressure) / (m_value - entry->ambpressure) * (100.0 - AMB_PERCENTAGE);
+ lrint(tissue_inertgas_saturation[j] / entry->ambpressure * AMB_PERCENTAGE) :
+ lrint(AMB_PERCENTAGE + (tissue_inertgas_saturation[j] - entry->ambpressure) / (m_value - entry->ambpressure) * (100.0 - AMB_PERCENTAGE));
}
/* should we do more calculations?
@@ -1322,18 +1322,18 @@ static void plot_string(struct plot_info *pi, struct plot_data *entry, struct me
if (prefs.pp_graphs.phe)
put_format(b, translate("gettextFromC", "pHe: %.2fbar\n"), entry->pressures.he);
if (prefs.mod) {
- mod = (int)get_depth_units(entry->mod, NULL, &depth_unit);
+ mod = lrint(get_depth_units(lrint(entry->mod), NULL, &depth_unit));
put_format(b, translate("gettextFromC", "MOD: %d%s\n"), mod, depth_unit);
}
- eadd = (int)get_depth_units(entry->eadd, NULL, &depth_unit);
+ eadd = lrint(get_depth_units(lrint(entry->eadd), NULL, &depth_unit));
if (prefs.ead) {
switch (pi->dive_type) {
case NITROX:
- ead = (int)get_depth_units(entry->ead, NULL, &depth_unit);
+ ead = lrint(get_depth_units(lrint(entry->ead), NULL, &depth_unit));
put_format(b, translate("gettextFromC", "EAD: %d%s\nEADD: %d%s\n"), ead, depth_unit, eadd, depth_unit);
break;
case TRIMIX:
- end = (int)get_depth_units(entry->end, NULL, &depth_unit);
+ end = lrint(get_depth_units(lrint(entry->end), NULL, &depth_unit));
put_format(b, translate("gettextFromC", "END: %d%s\nEADD: %d%s\n"), end, depth_unit, eadd, depth_unit);
break;
case AIR:
@@ -1570,7 +1570,7 @@ void compare_samples(struct plot_data *e1, struct plot_data *e2, char *buf, int
double atm = depth_to_atm(avg_depth, &displayed_dive);
/* milliliters per minute */
- int sac = volume_used / atm * 60 / delta_time;
+ int sac = lrint(volume_used / atm * 60 / delta_time);
memcpy(buf2, buf, bufsize);
volume_value = get_volume_units(sac, &volume_precision, &volume_unit);
snprintf(buf, bufsize, translate("gettextFromC", "%s SAC:%.*f %s"), buf2, volume_precision, volume_value, volume_unit);
diff --git a/core/save-html.c b/core/save-html.c
index 4f811558a..66472fdfc 100644
--- a/core/save-html.c
+++ b/core/save-html.c
@@ -127,7 +127,7 @@ static void put_cylinder_HTML(struct membuffer *b, struct dive *dive)
if (cylinder->type.size.mliter) {
int volume = cylinder->type.size.mliter;
if (prefs.units.volume == CUFT && cylinder->type.workingpressure.mbar)
- volume *= bar_to_atm(cylinder->type.workingpressure.mbar / 1000.0);
+ volume = lrint(volume * bar_to_atm(cylinder->type.workingpressure.mbar / 1000.0));
put_HTML_volume_units(b, volume, "\"Size\":\"", " \", ");
} else {
write_attribute(b, "Size", "--", ", ");
diff --git a/core/statistics.c b/core/statistics.c
index b615cdef1..5f0d977e7 100644
--- a/core/statistics.c
+++ b/core/statistics.c
@@ -68,15 +68,15 @@ static void process_dive(struct dive *dp, stats_t *stats)
return;
if (dp->meandepth.mm) {
stats->total_average_depth_time.seconds += duration;
- stats->avg_depth.mm = (1.0 * old_tadt * stats->avg_depth.mm +
- duration * dp->meandepth.mm) /
- stats->total_average_depth_time.seconds;
+ stats->avg_depth.mm = lrint((1.0 * old_tadt * stats->avg_depth.mm +
+ duration * dp->meandepth.mm) /
+ stats->total_average_depth_time.seconds);
}
if (dp->sac > 100) { /* less than .1 l/min is bogus, even with a pSCR */
sac_time = stats->total_sac_time + duration;
- stats->avg_sac.mliter = (1.0 * stats->total_sac_time * stats->avg_sac.mliter +
+ stats->avg_sac.mliter = lrint((1.0 * stats->total_sac_time * stats->avg_sac.mliter +
duration * dp->sac) /
- sac_time;
+ sac_time);
if (dp->sac > stats->max_sac.mliter)
stats->max_sac.mliter = dp->sac;
if (stats->min_sac.mliter == 0 || dp->sac < stats->min_sac.mliter)
diff --git a/core/uemis-downloader.c b/core/uemis-downloader.c
index 4a03c065e..237a6863f 100644
--- a/core/uemis-downloader.c
+++ b/core/uemis-downloader.c
@@ -129,8 +129,8 @@ static void uemis_add_string(const char *buffer, char **text, const char *delimi
static void uemis_get_weight(char *buffer, weightsystem_t *weight, int diveid)
{
weight->weight.grams = uemis_get_weight_unit(diveid) ?
- lbs_to_grams(ascii_strtod(buffer, NULL)) :
- ascii_strtod(buffer, NULL) * 1000;
+ lbs_to_grams(ascii_strtod(buffer, NULL)) :
+ lrint(ascii_strtod(buffer, NULL) * 1000);
weight->description = strdup(translate("gettextFromC", "unknown"));
}
diff --git a/core/uemis.c b/core/uemis.c
index 564e7dfbb..199b69fa1 100644
--- a/core/uemis.c
+++ b/core/uemis.c
@@ -173,8 +173,8 @@ void uemis_set_divelocation(int divespot, char *text, double longitude, double l
struct dive_site *ds = get_dive_site_by_uuid(hp->dive_site_uuid);
if (ds) {
ds->name = strdup(text);
- ds->longitude.udeg = round(longitude * 1000000);
- ds->latitude.udeg = round(latitude * 1000000);
+ ds->longitude.udeg = lrint(longitude * 1000000);
+ ds->latitude.udeg = lrint(latitude * 1000000);
}
}
hp = hp->next;
@@ -329,7 +329,7 @@ void uemis_parse_divelog_binary(char *base64, void *datap)
if (template == 0)
template = 1;
for (i = 0; i < template; i++) {
- float volume = *(float *)(data + 116 + 25 * (gasoffset + i)) * 1000.0;
+ float volume = *(float *)(data + 116 + 25 * (gasoffset + i)) * 1000.0f;
/* uemis always assumes a working pressure of 202.6bar (!?!?) - I first thought
* it was 3000psi, but testing against all my dives gets me that strange number.
* Still, that's of course completely bogus and shows they don't get how