mirror of
https://github.com/subsurface/subsurface.git
synced 2024-11-28 05:00:20 +00:00
Fix potential double/float to int rounding errors
Not using lrint(f) when converting double/float to int creates rounding errors. This error was detected by TestParse::testParseDM4 failure on Windows. It was creating rounding inconsistencies on Linux too, see change in TestDiveDM4.xml. Enable -Wfloat-conversion for gcc version greater than 4.9.0 Signed-off-by: Jeremie Guichard <djebrest@gmail.com>
This commit is contained in:
parent
406e4287eb
commit
2b06a0b223
20 changed files with 109 additions and 100 deletions
|
@ -86,6 +86,14 @@ elseif ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "AppleClang")
|
|||
elseif ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU")
|
||||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=gnu99")
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
|
||||
|
||||
# Warn about possible float conversion errors
|
||||
# Use NOT VERSION_LESS since VERSION_GREATER_EQUAL is not available
|
||||
# in currently used cmake version.
|
||||
if (NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS "4.9.0")
|
||||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wfloat-conversion")
|
||||
endif()
|
||||
|
||||
elseif ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Intel")
|
||||
# using Intel C++
|
||||
elseif ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC")
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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 */
|
||||
|
|
|
@ -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 */
|
||||
|
|
16
core/file.c
16
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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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", "--", ", ");
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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"));
|
||||
}
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -141,7 +141,7 @@
|
|||
<sample time='42:00 min' depth='16.07 m' pressure='91.15 bar' />
|
||||
<sample time='42:20 min' depth='15.95 m' pressure='90.42 bar' />
|
||||
<sample time='42:40 min' depth='16.24 m' pressure='89.9 bar' />
|
||||
<sample time='43:00 min' depth='16.379 m' pressure='88.92 bar' />
|
||||
<sample time='43:00 min' depth='16.38 m' pressure='88.92 bar' />
|
||||
<sample time='43:20 min' depth='16.67 m' pressure='88.2 bar' />
|
||||
<sample time='43:40 min' depth='16.61 m' pressure='87.41 bar' />
|
||||
<sample time='44:00 min' depth='17.17 m' pressure='86.42 bar' />
|
||||
|
|
Loading…
Reference in a new issue