Change calls to rint into lrint avoiding conversion warnings

Using gcc option "-Wfloat-conversion" is useful to catch
potential conversion errors (where lrint should be used).
rint returns double and still raises the same warning,
this is why this change updates all rint calls to lrint.
In few places, where input type is a float, corresponding
lrinf is used.

Signed-off-by: Jeremie Guichard <djebrest@gmail.com>
This commit is contained in:
Jeremie Guichard 2017-03-08 13:41:41 +07:00
parent 9c2619ea3b
commit 406e4287eb
21 changed files with 101 additions and 101 deletions

View file

@ -243,15 +243,15 @@ double get_volume_units(unsigned int ml, int *frac, const char **units)
int units_to_sac(double volume) int units_to_sac(double volume)
{ {
if (get_units()->volume == CUFT) if (get_units()->volume == CUFT)
return rint(cuft_to_l(volume) * 1000.0); return lrint(cuft_to_l(volume) * 1000.0);
else else
return rint(volume * 1000); return lrint(volume * 1000);
} }
unsigned int units_to_depth(double depth) unsigned int units_to_depth(double depth)
{ {
if (get_units()->length == METERS) if (get_units()->length == METERS)
return rint(depth * 1000); return lrint(depth * 1000);
return feet_to_mm(depth); return feet_to_mm(depth);
} }
@ -872,7 +872,7 @@ int gas_volume(cylinder_t *cyl, pressure_t p)
{ {
double bar = p.mbar / 1000.0; double bar = p.mbar / 1000.0;
double z_factor = gas_compressibility_factor(&cyl->gasmix, bar); double z_factor = gas_compressibility_factor(&cyl->gasmix, bar);
return rint(cyl->type.size.mliter * bar_to_atm(bar) / z_factor); return lrint(cyl->type.size.mliter * bar_to_atm(bar) / z_factor);
} }
/* /*
@ -1019,7 +1019,7 @@ static void match_standard_cylinder(cylinder_type_t *type)
default: default:
return; return;
} }
len = snprintf(buffer, sizeof(buffer), fmt, (int)rint(cuft)); len = snprintf(buffer, sizeof(buffer), fmt, (int)lrint(cuft));
p = malloc(len + 1); p = malloc(len + 1);
if (!p) if (!p)
return; return;
@ -1056,7 +1056,7 @@ static void sanitize_cylinder_type(cylinder_type_t *type)
volume_of_air = cuft_to_l(type->size.mliter); volume_of_air = cuft_to_l(type->size.mliter);
/* milliliters at 1 atm: not corrected for compressibility! */ /* milliliters at 1 atm: not corrected for compressibility! */
volume = volume_of_air / bar_to_atm(bar); volume = volume_of_air / bar_to_atm(bar);
type->size.mliter = rint(volume); type->size.mliter = lrint(volume);
} }
/* Ok, we have both size and pressure: try to match a description */ /* Ok, we have both size and pressure: try to match a description */

View file

@ -173,7 +173,7 @@ static inline int interpolate(int a, int b, int part, int whole)
/* It is doubtful that we actually need floating point for this, but whatever */ /* It is doubtful that we actually need floating point for this, but whatever */
if (whole) { if (whole) {
double x = (double)a * (whole - part) + (double)b * part; double x = (double)a * (whole - part) + (double)b * part;
return rint(x / whole); return lrint(x / whole);
} }
return (a+b)/2; return (a+b)/2;
} }
@ -440,7 +440,7 @@ static inline int calculate_depth_to_mbar(int depth, pressure_t surface_pressure
if (salinity < 500) if (salinity < 500)
salinity += FRESHWATER_SALINITY; salinity += FRESHWATER_SALINITY;
specific_weight = salinity / 10000.0 * 0.981; specific_weight = salinity / 10000.0 * 0.981;
mbar += rint(depth / 10.0 * specific_weight); mbar += lrint(depth / 10.0 * specific_weight);
return mbar; return mbar;
} }
@ -470,7 +470,7 @@ static inline int rel_mbar_to_depth(int mbar, struct dive *dive)
if (dive->dc.salinity) if (dive->dc.salinity)
specific_weight = dive->dc.salinity / 10000.0 * 0.981; specific_weight = dive->dc.salinity / 10000.0 * 0.981;
/* whole mbar gives us cm precision */ /* whole mbar gives us cm precision */
cm = rint(mbar / specific_weight); cm = lrint(mbar / specific_weight);
return cm * 10; return cm * 10;
} }
@ -489,7 +489,7 @@ static inline depth_t gas_mod(struct gasmix *mix, pressure_t po2_limit, struct d
depth_t rounded_depth; depth_t rounded_depth;
double depth = (double) mbar_to_depth(po2_limit.mbar * 1000 / get_o2(mix), dive); double depth = (double) mbar_to_depth(po2_limit.mbar * 1000 / get_o2(mix), dive);
rounded_depth.mm = rint(depth / roundto) * roundto; rounded_depth.mm = lrint(depth / roundto) * roundto;
return rounded_depth; return rounded_depth;
} }
@ -500,7 +500,7 @@ static inline depth_t gas_mnd(struct gasmix *mix, depth_t end, struct dive *dive
ppo2n2.mbar = depth_to_mbar(end.mm, dive); ppo2n2.mbar = depth_to_mbar(end.mm, dive);
double maxambient = ppo2n2.mbar / (1 - get_he(mix) / 1000.0); double maxambient = ppo2n2.mbar / (1 - get_he(mix) / 1000.0);
rounded_depth.mm = rint(mbar_to_depth(maxambient, dive) / roundto) * roundto; rounded_depth.mm = lrint(((double)mbar_to_depth(maxambient, dive)) / roundto) * roundto;
return rounded_depth; return rounded_depth;
} }

View file

@ -183,7 +183,7 @@ static int calculate_otu(struct dive *dive)
if (po2 >= 500) if (po2 >= 500)
otu += pow((po2 - 500) / 1000.0, 0.83) * t / 30.0; otu += pow((po2 - 500) / 1000.0, 0.83) * t / 30.0;
} }
return rint(otu); return lrint(otu);
} }
/* calculate CNS for a dive - this only takes the first divecomputer into account */ /* calculate CNS for a dive - this only takes the first divecomputer into account */
int const cns_table[][3] = { int const cns_table[][3] = {

View file

@ -148,7 +148,7 @@ static void fill_missing_segment_pressures(pr_track_t *list, enum interpolation_
case TIME: case TIME:
if (list->t_end && (tmp->t_start - tmp->t_end)) { if (list->t_end && (tmp->t_start - tmp->t_end)) {
magic = (list->t_start - tmp->t_end) / (tmp->t_start - tmp->t_end); magic = (list->t_start - tmp->t_end) / (tmp->t_start - tmp->t_end);
list->end = rint(start - (start - end) * magic); list->end = lrint(start - (start - end) * magic);
} else { } else {
list->end = start; list->end = start;
} }
@ -290,11 +290,11 @@ static void fill_missing_tank_pressures(struct dive *dive, struct plot_info *pi,
magic = (interpolate.end - interpolate.start) / (double)interpolate.pressure_time; magic = (interpolate.end - interpolate.start) / (double)interpolate.pressure_time;
/* Use that overall pressure change to update the current pressure */ /* Use that overall pressure change to update the current pressure */
cur_pr[cyl] = rint(interpolate.start + magic * interpolate.acc_pressure_time); cur_pr[cyl] = lrint(interpolate.start + magic * interpolate.acc_pressure_time);
} }
} else { } else {
magic = (interpolate.end - interpolate.start) / (segment->t_end - segment->t_start); magic = (interpolate.end - interpolate.start) / (segment->t_end - segment->t_start);
cur_pr[cyl] = rint(segment->start + magic * (entry->sec - segment->t_start)); cur_pr[cyl] = lrint(segment->start + magic * (entry->sec - segment->t_start));
} }
*save_interpolated = cur_pr[cyl]; // and store the interpolated data in plot_info *save_interpolated = cur_pr[cyl]; // and store the interpolated data in plot_info
} }

View file

@ -157,8 +157,8 @@ void GpsLocation::newPosition(QGeoPositionInfo pos)
gpsTracker gt; gpsTracker gt;
gt.when = pos.timestamp().toTime_t(); gt.when = pos.timestamp().toTime_t();
gt.when += gettimezoneoffset(gt.when); gt.when += gettimezoneoffset(gt.when);
gt.latitude.udeg = rint(pos.coordinate().latitude() * 1000000); gt.latitude.udeg = lrint(pos.coordinate().latitude() * 1000000);
gt.longitude.udeg = rint(pos.coordinate().longitude() * 1000000); gt.longitude.udeg = lrint(pos.coordinate().longitude() * 1000000);
addFixToStorage(gt); addFixToStorage(gt);
} }
} }

View file

@ -117,8 +117,8 @@ static int parse_gasmixes(device_data_t *devdata, struct dive *dive, dc_parser_t
if (i >= MAX_CYLINDERS) if (i >= MAX_CYLINDERS)
continue; continue;
o2 = rint(gasmix.oxygen * 1000); o2 = lrint(gasmix.oxygen * 1000);
he = rint(gasmix.helium * 1000); he = lrint(gasmix.helium * 1000);
/* Ignore bogus data - libdivecomputer does some crazy stuff */ /* Ignore bogus data - libdivecomputer does some crazy stuff */
if (o2 + he <= O2_IN_AIR || o2 > 1000) { if (o2 + he <= O2_IN_AIR || o2 > 1000) {
@ -149,8 +149,8 @@ static int parse_gasmixes(device_data_t *devdata, struct dive *dive, dc_parser_t
if (rc == DC_STATUS_SUCCESS) { if (rc == DC_STATUS_SUCCESS) {
cylinder_t *cyl = dive->cylinder + i; cylinder_t *cyl = dive->cylinder + i;
cyl->type.size.mliter = rint(tank.volume * 1000); cyl->type.size.mliter = lrint(tank.volume * 1000);
cyl->type.workingpressure.mbar = rint(tank.workpressure * 1000); cyl->type.workingpressure.mbar = lrint(tank.workpressure * 1000);
cyl->cylinder_use = OC_GAS; cyl->cylinder_use = OC_GAS;
if (tank.type & DC_TANKINFO_CC_O2) if (tank.type & DC_TANKINFO_CC_O2)
@ -330,7 +330,7 @@ sample_cb(dc_sample_type_t type, dc_sample_value_t value, void *userdata)
finish_sample(dc); finish_sample(dc);
break; break;
case DC_SAMPLE_DEPTH: case DC_SAMPLE_DEPTH:
sample->depth.mm = rint(value.depth * 1000); sample->depth.mm = lrint(value.depth * 1000);
break; break;
case DC_SAMPLE_PRESSURE: case DC_SAMPLE_PRESSURE:
/* Do we already have a pressure reading? */ /* Do we already have a pressure reading? */
@ -341,7 +341,7 @@ sample_cb(dc_sample_type_t type, dc_sample_value_t value, void *userdata)
break; break;
} }
sample->sensor = value.pressure.tank; sample->sensor = value.pressure.tank;
sample->cylinderpressure.mbar = rint(value.pressure.value * 1000); sample->cylinderpressure.mbar = lrint(value.pressure.value * 1000);
break; break;
case DC_SAMPLE_GASMIX: case DC_SAMPLE_GASMIX:
handle_gasmix(dc, sample, value.gasmix); handle_gasmix(dc, sample, value.gasmix);
@ -373,11 +373,11 @@ sample_cb(dc_sample_type_t type, dc_sample_value_t value, void *userdata)
#if DC_VERSION_CHECK(0, 3, 0) #if DC_VERSION_CHECK(0, 3, 0)
case DC_SAMPLE_SETPOINT: case DC_SAMPLE_SETPOINT:
/* for us a setpoint means constant pO2 from here */ /* for us a setpoint means constant pO2 from here */
sample->setpoint.mbar = po2 = rint(value.setpoint * 1000); sample->setpoint.mbar = po2 = lrint(value.setpoint * 1000);
break; break;
case DC_SAMPLE_PPO2: case DC_SAMPLE_PPO2:
if (nsensor < 3) if (nsensor < 3)
sample->o2sensor[nsensor].mbar = rint(value.ppo2 * 1000); sample->o2sensor[nsensor].mbar = lrint(value.ppo2 * 1000);
else else
report_error("%d is more o2 sensors than we can handle", nsensor); report_error("%d is more o2 sensors than we can handle", nsensor);
nsensor++; nsensor++;
@ -386,22 +386,22 @@ sample_cb(dc_sample_type_t type, dc_sample_value_t value, void *userdata)
dc->no_o2sensors = nsensor; dc->no_o2sensors = nsensor;
break; break;
case DC_SAMPLE_CNS: case DC_SAMPLE_CNS:
sample->cns = cns = rint(value.cns * 100); sample->cns = cns = lrint(value.cns * 100);
break; break;
case DC_SAMPLE_DECO: case DC_SAMPLE_DECO:
if (value.deco.type == DC_DECO_NDL) { if (value.deco.type == DC_DECO_NDL) {
sample->ndl.seconds = ndl = value.deco.time; sample->ndl.seconds = ndl = value.deco.time;
sample->stopdepth.mm = stopdepth = rint(value.deco.depth * 1000.0); sample->stopdepth.mm = stopdepth = lrint(value.deco.depth * 1000.0);
sample->in_deco = in_deco = false; sample->in_deco = in_deco = false;
} else if (value.deco.type == DC_DECO_DECOSTOP || } else if (value.deco.type == DC_DECO_DECOSTOP ||
value.deco.type == DC_DECO_DEEPSTOP) { value.deco.type == DC_DECO_DEEPSTOP) {
sample->in_deco = in_deco = true; sample->in_deco = in_deco = true;
sample->stopdepth.mm = stopdepth = rint(value.deco.depth * 1000.0); sample->stopdepth.mm = stopdepth = lrint(value.deco.depth * 1000.0);
sample->stoptime.seconds = stoptime = value.deco.time; sample->stoptime.seconds = stoptime = value.deco.time;
ndl = 0; ndl = 0;
} else if (value.deco.type == DC_DECO_SAFETYSTOP) { } else if (value.deco.type == DC_DECO_SAFETYSTOP) {
sample->in_deco = in_deco = false; sample->in_deco = in_deco = false;
sample->stopdepth.mm = stopdepth = rint(value.deco.depth * 1000.0); sample->stopdepth.mm = stopdepth = lrint(value.deco.depth * 1000.0);
sample->stoptime.seconds = stoptime = value.deco.time; sample->stoptime.seconds = stoptime = value.deco.time;
} }
#endif #endif
@ -627,7 +627,7 @@ static dc_status_t libdc_header_parser(dc_parser_t *parser, struct device_data_t
return rc; return rc;
} }
if (rc == DC_STATUS_SUCCESS) if (rc == DC_STATUS_SUCCESS)
dive->dc.maxdepth.mm = rint(maxdepth * 1000); dive->dc.maxdepth.mm = lrint(maxdepth * 1000);
#if DC_VERSION_CHECK(0, 5, 0) && defined(DC_GASMIX_UNKNOWN) #if DC_VERSION_CHECK(0, 5, 0) && defined(DC_GASMIX_UNKNOWN)
// if this is defined then we have a fairly late version of libdivecomputer // if this is defined then we have a fairly late version of libdivecomputer
@ -678,7 +678,7 @@ static dc_status_t libdc_header_parser(dc_parser_t *parser, struct device_data_t
return rc; return rc;
} }
if (rc == DC_STATUS_SUCCESS) if (rc == DC_STATUS_SUCCESS)
dive->dc.salinity = rint(salinity.density * 10.0); dive->dc.salinity = lrint(salinity.density * 10.0);
double surface_pressure = 0; double surface_pressure = 0;
rc = dc_parser_get_field(parser, DC_FIELD_ATMOSPHERIC, 0, &surface_pressure); rc = dc_parser_get_field(parser, DC_FIELD_ATMOSPHERIC, 0, &surface_pressure);
@ -687,7 +687,7 @@ static dc_status_t libdc_header_parser(dc_parser_t *parser, struct device_data_t
return rc; return rc;
} }
if (rc == DC_STATUS_SUCCESS) if (rc == DC_STATUS_SUCCESS)
dive->dc.surface_pressure.mbar = rint(surface_pressure * 1000.0); dive->dc.surface_pressure.mbar = lrint(surface_pressure * 1000.0);
#endif #endif
#ifdef DC_FIELD_STRING #ifdef DC_FIELD_STRING

View file

@ -81,40 +81,40 @@ static temperature_t get_temperature(const char *line)
static depth_t get_depth(const char *line) static depth_t get_depth(const char *line)
{ {
depth_t d; depth_t d;
d.mm = rint(1000*ascii_strtod(line, NULL)); d.mm = lrint(1000*ascii_strtod(line, NULL));
return d; return d;
} }
static volume_t get_volume(const char *line) static volume_t get_volume(const char *line)
{ {
volume_t v; volume_t v;
v.mliter = rint(1000*ascii_strtod(line, NULL)); v.mliter = lrint(1000*ascii_strtod(line, NULL));
return v; return v;
} }
static weight_t get_weight(const char *line) static weight_t get_weight(const char *line)
{ {
weight_t w; weight_t w;
w.grams = rint(1000*ascii_strtod(line, NULL)); w.grams = lrint(1000*ascii_strtod(line, NULL));
return w; return w;
} }
static pressure_t get_pressure(const char *line) static pressure_t get_pressure(const char *line)
{ {
pressure_t p; pressure_t p;
p.mbar = rint(1000*ascii_strtod(line, NULL)); p.mbar = lrint(1000*ascii_strtod(line, NULL));
return p; return p;
} }
static int get_salinity(const char *line) static int get_salinity(const char *line)
{ {
return rint(10*ascii_strtod(line, NULL)); return lrint(10*ascii_strtod(line, NULL));
} }
static fraction_t get_fraction(const char *line) static fraction_t get_fraction(const char *line)
{ {
fraction_t f; fraction_t f;
f.permille = rint(10*ascii_strtod(line, NULL)); f.permille = lrint(10*ascii_strtod(line, NULL));
return f; return f;
} }
@ -568,10 +568,10 @@ static char *parse_sample_unit(struct sample *sample, double val, char *unit)
/* The units are "°C", "m" or "bar", so let's just look at the first character */ /* The units are "°C", "m" or "bar", so let's just look at the first character */
switch (*unit) { switch (*unit) {
case 'm': case 'm':
sample->depth.mm = rint(1000*val); sample->depth.mm = lrint(1000*val);
break; break;
case 'b': case 'b':
sample->cylinderpressure.mbar = rint(1000*val); sample->cylinderpressure.mbar = lrint(1000*val);
break; break;
default: default:
sample->temperature.mkelvin = C_to_mkelvin(val); sample->temperature.mkelvin = C_to_mkelvin(val);

View file

@ -286,7 +286,7 @@ static enum number_type parse_float(const char *buffer, double *res, const char
if (errno || *endp == buffer) if (errno || *endp == buffer)
return NEITHER; return NEITHER;
if (**endp == ',') { if (**endp == ',') {
if (IS_FP_SAME(val, rint(val))) { if (IS_FP_SAME(val, lrint(val))) {
/* we really want to send an error if this is a Subsurface native file /* we really want to send an error if this is a Subsurface native file
* as this is likely indication of a bug - but right now we don't have * as this is likely indication of a bug - but right now we don't have
* that information available */ * that information available */
@ -338,7 +338,7 @@ static void pressure(char *buffer, pressure_t *pressure)
break; break;
} }
if (fabs(mbar) > 5 && fabs(mbar) < 5000000) { if (fabs(mbar) > 5 && fabs(mbar) < 5000000) {
pressure->mbar = rint(mbar); pressure->mbar = lrint(mbar);
break; break;
} }
/* fallthrough */ /* fallthrough */
@ -358,7 +358,7 @@ static void salinity(char *buffer, int *salinity)
union int_or_float val; union int_or_float val;
switch (integer_or_float(buffer, &val)) { switch (integer_or_float(buffer, &val)) {
case FLOAT: case FLOAT:
*salinity = rint(val.fp * 10.0); *salinity = lrint(val.fp * 10.0);
break; break;
default: default:
printf("Strange salinity reading %s\n", buffer); printf("Strange salinity reading %s\n", buffer);
@ -373,7 +373,7 @@ static void depth(char *buffer, depth_t *depth)
case FLOAT: case FLOAT:
switch (xml_parsing_units.length) { switch (xml_parsing_units.length) {
case METERS: case METERS:
depth->mm = rint(val.fp * 1000); depth->mm = lrint(val.fp * 1000);
break; break;
case FEET: case FEET:
depth->mm = feet_to_mm(val.fp); depth->mm = feet_to_mm(val.fp);
@ -405,7 +405,7 @@ static void weight(char *buffer, weight_t *weight)
case FLOAT: case FLOAT:
switch (xml_parsing_units.weight) { switch (xml_parsing_units.weight) {
case KG: case KG:
weight->grams = rint(val.fp * 1000); weight->grams = lrint(val.fp * 1000);
break; break;
case LBS: case LBS:
weight->grams = lbs_to_grams(val.fp); weight->grams = lbs_to_grams(val.fp);
@ -510,7 +510,7 @@ static void percent(char *buffer, fraction_t *fraction)
/* Then turn percent into our integer permille format */ /* Then turn percent into our integer permille format */
if (val >= 0 && val <= 100.0) { if (val >= 0 && val <= 100.0) {
fraction->permille = rint(val * 10); fraction->permille = lrint(val * 10);
break; break;
} }
default: default:
@ -541,7 +541,7 @@ static void cylindersize(char *buffer, volume_t *volume)
switch (integer_or_float(buffer, &val)) { switch (integer_or_float(buffer, &val)) {
case FLOAT: case FLOAT:
volume->mliter = rint(val.fp * 1000); volume->mliter = lrint(val.fp * 1000);
break; break;
default: default:
@ -614,7 +614,7 @@ static void get_rating(char *buffer, int *i)
static void double_to_o2pressure(char *buffer, o2pressure_t *i) static void double_to_o2pressure(char *buffer, o2pressure_t *i)
{ {
i->mbar = rint(ascii_strtod(buffer, NULL) * 1000.0); i->mbar = lrint(ascii_strtod(buffer, NULL) * 1000.0);
} }
static void hex_value(char *buffer, uint32_t *i) static void hex_value(char *buffer, uint32_t *i)
@ -697,7 +697,7 @@ static void psi_or_bar(char *buffer, pressure_t *pressure)
if (val.fp > 400) if (val.fp > 400)
pressure->mbar = psi_to_mbar(val.fp); pressure->mbar = psi_to_mbar(val.fp);
else else
pressure->mbar = rint(val.fp * 1000); pressure->mbar = lrint(val.fp * 1000);
break; break;
default: default:
fprintf(stderr, "Crazy Diving Log PSI reading %s\n", buffer); fprintf(stderr, "Crazy Diving Log PSI reading %s\n", buffer);
@ -3182,7 +3182,7 @@ extern int divinglog_profile(void *handle, int columns, char **data, char **colu
if (atoi(ppo2_3) > 0) if (atoi(ppo2_3) > 0)
cur_sample->o2sensor[2].mbar = atoi(ppo2_3) * 100; cur_sample->o2sensor[2].mbar = atoi(ppo2_3) * 100;
if (atoi(cns) > 0) if (atoi(cns) > 0)
cur_sample->cns = rint(atoi(cns) / 10); cur_sample->cns = lrintf(atoi(cns) / 10.0f);
if (atoi(setpoint) > 0) if (atoi(setpoint) > 0)
cur_sample->setpoint.mbar = atoi(setpoint) * 100; cur_sample->setpoint.mbar = atoi(setpoint) * 100;

View file

@ -1406,8 +1406,8 @@ bool plan(struct diveplan *diveplan, char **cached_datap, bool is_planner, bool
plan_add_segment(diveplan, clock - previous_point_time, 0, current_cylinder, po2, false); plan_add_segment(diveplan, clock - previous_point_time, 0, current_cylinder, po2, false);
if (decoMode() == VPMB) { if (decoMode() == VPMB) {
diveplan->eff_gfhigh = rint(100.0 * regressionb()); diveplan->eff_gfhigh = lrint(100.0 * regressionb());
diveplan->eff_gflow = rint(100.0 * (regressiona() * first_stop_depth + regressionb())); diveplan->eff_gflow = lrint(100.0 * (regressiona() * first_stop_depth + regressionb()));
} }
create_dive_from_plan(diveplan, is_planner); create_dive_from_plan(diveplan, is_planner);

View file

@ -760,7 +760,7 @@ static int sac_between(struct dive *dive, struct plot_data *first, struct plot_d
pressuretime /= 60; pressuretime /= 60;
/* SAC = mliter per minute */ /* SAC = mliter per minute */
return rint(airuse / pressuretime); return lrint(airuse / pressuretime);
} }
/* /*

View file

@ -51,9 +51,9 @@ QString weight_string(int weight_in_grams)
} else { } else {
double lbs = grams_to_lbs(weight_in_grams); double lbs = grams_to_lbs(weight_in_grams);
if (lbs >= 40.0) if (lbs >= 40.0)
lbs = rint(lbs + 0.5); lbs = lrint(lbs + 0.5);
else else
lbs = rint(lbs + 0.05); lbs = lrint(lbs + 0.05);
str = QString("%1").arg(lbs, 0, 'f', lbs >= 40.0 ? 0 : 1); str = QString("%1").arg(lbs, 0, 'f', lbs >= 40.0 ? 0 : 1);
} }
return (str); return (str);
@ -264,8 +264,8 @@ bool gpsHasChanged(struct dive *dive, struct dive *master, const QString &gps_te
if (!(*parsed = parseGpsText(gps_text, &latitude, &longitude))) if (!(*parsed = parseGpsText(gps_text, &latitude, &longitude)))
return false; return false;
latudeg = rint(1000000 * latitude); latudeg = lrint(1000000 * latitude);
longudeg = rint(1000000 * longitude); longudeg = lrint(1000000 * longitude);
/* if dive gps didn't change, nothing changed */ /* if dive gps didn't change, nothing changed */
if (dive->latitude.udeg == latudeg && dive->longitude.udeg == longudeg) if (dive->latitude.udeg == latudeg && dive->longitude.udeg == longudeg)
@ -843,13 +843,13 @@ int parseWeightToGrams(const QString &text)
return 0; return 0;
double number = numOnly.toDouble(); double number = numOnly.toDouble();
if (text.contains(QObject::tr("kg"), Qt::CaseInsensitive)) { if (text.contains(QObject::tr("kg"), Qt::CaseInsensitive)) {
grams = rint(number * 1000); grams = lrint(number * 1000);
} else if (text.contains(QObject::tr("lbs"), Qt::CaseInsensitive)) { } else if (text.contains(QObject::tr("lbs"), Qt::CaseInsensitive)) {
grams = lbs_to_grams(number); grams = lbs_to_grams(number);
} else { } else {
switch (prefs.units.weight) { switch (prefs.units.weight) {
case units::KG: case units::KG:
grams = rint(number * 1000); grams = lrint(number * 1000);
break; break;
case units::LBS: case units::LBS:
grams = lbs_to_grams(number); grams = lbs_to_grams(number);
@ -870,13 +870,13 @@ int parsePressureToMbar(const QString &text)
return 0; return 0;
double number = numOnly.toDouble(); double number = numOnly.toDouble();
if (text.contains(QObject::tr("bar"), Qt::CaseInsensitive)) { if (text.contains(QObject::tr("bar"), Qt::CaseInsensitive)) {
mbar = rint(number * 1000); mbar = lrint(number * 1000);
} else if (text.contains(QObject::tr("psi"), Qt::CaseInsensitive)) { } else if (text.contains(QObject::tr("psi"), Qt::CaseInsensitive)) {
mbar = psi_to_mbar(number); mbar = psi_to_mbar(number);
} else { } else {
switch (prefs.units.pressure) { switch (prefs.units.pressure) {
case units::BAR: case units::BAR:
mbar = rint(number * 1000); mbar = lrint(number * 1000);
break; break;
case units::PSI: case units::PSI:
mbar = psi_to_mbar(number); mbar = psi_to_mbar(number);
@ -1242,8 +1242,8 @@ extern "C" void picture_load_exif_data(struct picture *p)
goto picture_load_exit; goto picture_load_exit;
if (exif.parseFrom((const unsigned char *)mem.buffer, (unsigned)mem.size) != PARSE_EXIF_SUCCESS) if (exif.parseFrom((const unsigned char *)mem.buffer, (unsigned)mem.size) != PARSE_EXIF_SUCCESS)
goto picture_load_exit; goto picture_load_exit;
p->longitude.udeg= lrint(1000000.0 * exif.GeoLocation.Longitude); p->longitude.udeg= llrint(1000000.0 * exif.GeoLocation.Longitude);
p->latitude.udeg = lrint(1000000.0 * exif.GeoLocation.Latitude); p->latitude.udeg = llrint(1000000.0 * exif.GeoLocation.Latitude);
picture_load_exit: picture_load_exit:
free(mem.buffer); free(mem.buffer);
@ -1280,7 +1280,7 @@ weight_t string_to_weight(const char *str)
if (prefs.units.weight == prefs.units.LBS) if (prefs.units.weight == prefs.units.LBS)
goto lbs; goto lbs;
kg: kg:
weight.grams = rint(value * 1000); weight.grams = lrint(value * 1000);
return weight; return weight;
lbs: lbs:
weight.grams = lbs_to_grams(value); weight.grams = lbs_to_grams(value);
@ -1305,7 +1305,7 @@ depth_t string_to_depth(const char *str)
if (prefs.units.length == prefs.units.FEET) if (prefs.units.length == prefs.units.FEET)
goto ft; goto ft;
m: m:
depth.mm = rint(value * 1000); depth.mm = lrint(value * 1000);
return depth; return depth;
ft: ft:
depth.mm = feet_to_mm(value); depth.mm = feet_to_mm(value);
@ -1328,7 +1328,7 @@ pressure_t string_to_pressure(const char *str)
if (prefs.units.pressure == prefs.units.PSI) if (prefs.units.pressure == prefs.units.PSI)
goto psi; goto psi;
bar: bar:
pressure.mbar = rint(value * 1000); pressure.mbar = lrint(value * 1000);
return pressure; return pressure;
psi: psi:
pressure.mbar = psi_to_mbar(value); pressure.mbar = psi_to_mbar(value);
@ -1362,7 +1362,7 @@ cuft:
value /= bar_to_atm(workp.mbar / 1000.0); value /= bar_to_atm(workp.mbar / 1000.0);
value = cuft_to_l(value); value = cuft_to_l(value);
l: l:
volume.mliter = rint(value * 1000); volume.mliter = lrint(value * 1000);
return volume; return volume;
} }
@ -1372,7 +1372,7 @@ fraction_t string_to_fraction(const char *str)
double value = strtod_flags(str, &end, 0); double value = strtod_flags(str, &end, 0);
fraction_t fraction; fraction_t fraction;
fraction.permille = rint(value * 10); fraction.permille = lrint(value * 10);
/* /*
* Don't permit values less than zero or greater than 100% * Don't permit values less than zero or greater than 100%
*/ */

View file

@ -396,8 +396,8 @@ static void get_gas_parts(struct gasmix mix, volume_t vol, int o2_in_topup, volu
return; return;
} }
air.mliter = rint(((double)vol.mliter * (1000 - get_he(&mix) - get_o2(&mix))) / (1000 - o2_in_topup)); air.mliter = lrint(((double)vol.mliter * (1000 - get_he(&mix) - get_o2(&mix))) / (1000 - o2_in_topup));
he->mliter = rint(((double)vol.mliter * get_he(&mix)) / 1000.0); he->mliter = lrint(((double)vol.mliter * get_he(&mix)) / 1000.0);
o2->mliter += vol.mliter - he->mliter - air.mliter; o2->mliter += vol.mliter - he->mliter - air.mliter;
} }

View file

@ -92,7 +92,7 @@ static void uemis_ts(char *buffer, void *_when)
/* float minutes */ /* float minutes */
static void uemis_duration(char *buffer, duration_t *duration) static void uemis_duration(char *buffer, duration_t *duration)
{ {
duration->seconds = rint(ascii_strtod(buffer, NULL) * 60); duration->seconds = lrint(ascii_strtod(buffer, NULL) * 60);
} }
/* int cm */ /* int cm */

View file

@ -337,7 +337,7 @@ void uemis_parse_divelog_binary(char *base64, void *datap)
* we store the incorrect working pressure to get the SAC calculations "close" * we store the incorrect working pressure to get the SAC calculations "close"
* but the user will have to correct this manually * but the user will have to correct this manually
*/ */
dive->cylinder[i].type.size.mliter = rint(volume); dive->cylinder[i].type.size.mliter = lrintf(volume);
dive->cylinder[i].type.workingpressure.mbar = 202600; dive->cylinder[i].type.workingpressure.mbar = 202600;
dive->cylinder[i].gasmix.o2.permille = *(uint8_t *)(data + 120 + 25 * (gasoffset + i)) * 10; dive->cylinder[i].gasmix.o2.permille = *(uint8_t *)(data + 120 + 25 * (gasoffset + i)) * 10;
dive->cylinder[i].gasmix.he.permille = 0; dive->cylinder[i].gasmix.he.permille = 0;

View file

@ -134,7 +134,7 @@ static inline double grams_to_lbs(int grams)
static inline int lbs_to_grams(double lbs) static inline int lbs_to_grams(double lbs)
{ {
return rint(lbs * 453.6); return lrint(lbs * 453.6);
} }
static inline double ml_to_cuft(int ml) static inline double ml_to_cuft(int ml)
@ -159,12 +159,12 @@ static inline double m_to_mile(int m)
static inline unsigned long feet_to_mm(double feet) static inline unsigned long feet_to_mm(double feet)
{ {
return rint(feet * 304.8); return lrint(feet * 304.8);
} }
static inline int to_feet(depth_t depth) static inline int to_feet(depth_t depth)
{ {
return rint(mm_to_feet(depth.mm)); return lrint(mm_to_feet(depth.mm));
} }
static inline double mkelvin_to_C(int mkelvin) static inline double mkelvin_to_C(int mkelvin)
@ -179,12 +179,12 @@ static inline double mkelvin_to_F(int mkelvin)
static inline unsigned long F_to_mkelvin(double f) static inline unsigned long F_to_mkelvin(double f)
{ {
return rint((f - 32) * 1000 / 1.8 + ZERO_C_IN_MKELVIN); return lrint((f - 32) * 1000 / 1.8 + ZERO_C_IN_MKELVIN);
} }
static inline unsigned long C_to_mkelvin(double c) static inline unsigned long C_to_mkelvin(double c)
{ {
return rint(c * 1000 + ZERO_C_IN_MKELVIN); return lrint(c * 1000 + ZERO_C_IN_MKELVIN);
} }
static inline double psi_to_bar(double psi) static inline double psi_to_bar(double psi)
@ -194,12 +194,12 @@ static inline double psi_to_bar(double psi)
static inline long psi_to_mbar(double psi) static inline long psi_to_mbar(double psi)
{ {
return rint(psi_to_bar(psi) * 1000); return lrint(psi_to_bar(psi) * 1000);
} }
static inline int to_PSI(pressure_t pressure) static inline int to_PSI(pressure_t pressure)
{ {
return rint(pressure.mbar * 0.0145037738); return lrint(pressure.mbar * 0.0145037738);
} }
static inline double bar_to_atm(double bar) static inline double bar_to_atm(double bar)

View file

@ -379,12 +379,12 @@ PlannerSettingsWidget::PlannerSettingsWidget(QWidget *parent, Qt::WindowFlags f)
void PlannerSettingsWidget::updateUnitsUI() void PlannerSettingsWidget::updateUnitsUI()
{ {
ui.ascRate75->setValue(rint(prefs.ascrate75 / UNIT_FACTOR)); ui.ascRate75->setValue(lrint(prefs.ascrate75 / UNIT_FACTOR));
ui.ascRate50->setValue(rint(prefs.ascrate50 / UNIT_FACTOR)); ui.ascRate50->setValue(lrint(prefs.ascrate50 / UNIT_FACTOR));
ui.ascRateStops->setValue(rint(prefs.ascratestops / UNIT_FACTOR)); ui.ascRateStops->setValue(lrint(prefs.ascratestops / UNIT_FACTOR));
ui.ascRateLast6m->setValue(rint(prefs.ascratelast6m / UNIT_FACTOR)); ui.ascRateLast6m->setValue(lrint(prefs.ascratelast6m / UNIT_FACTOR));
ui.descRate->setValue(rint(prefs.descrate / UNIT_FACTOR)); ui.descRate->setValue(lrint(prefs.descrate / UNIT_FACTOR));
ui.bestmixEND->setValue(rint(get_depth_units(prefs.bestmixend.mm, NULL, NULL))); ui.bestmixEND->setValue(lrint(get_depth_units(prefs.bestmixend.mm, NULL, NULL)));
} }
PlannerSettingsWidget::~PlannerSettingsWidget() PlannerSettingsWidget::~PlannerSettingsWidget()

View file

@ -140,8 +140,8 @@ void GlobeGPS::mouseClicked(qreal lon, qreal lat, GeoDataCoordinates::Unit unit)
return; return;
GeoDataCoordinates here(lon, lat, unit); GeoDataCoordinates here(lon, lat, unit);
long lon_udeg = rint(1000000 * here.longitude(GeoDataCoordinates::Degree)); long lon_udeg = lrint(1000000 * here.longitude(GeoDataCoordinates::Degree));
long lat_udeg = rint(1000000 * here.latitude(GeoDataCoordinates::Degree)); long lat_udeg = lrint(1000000 * here.latitude(GeoDataCoordinates::Degree));
// distance() is in km above the map. // distance() is in km above the map.
// We're going to use that to decide how // We're going to use that to decide how
@ -155,7 +155,7 @@ void GlobeGPS::mouseClicked(qreal lon, qreal lat, GeoDataCoordinates::Unit unit)
// Trigonometry is hard, but sin x == x // Trigonometry is hard, but sin x == x
// for small x, so let's just do this as // for small x, so let's just do this as
// a linear thing. // a linear thing.
long resolve = rint(distance() * 1000); long resolve = lrint(distance() * 1000);
int idx; int idx;
struct dive *dive; struct dive *dive;
@ -347,8 +347,8 @@ void GlobeGPS::changeDiveGeoPosition(qreal lon, qreal lat, GeoDataCoordinates::U
centerOn(lon, lat, true); centerOn(lon, lat, true);
// change the location of the displayed_dive and put the UI in edit mode // change the location of the displayed_dive and put the UI in edit mode
displayed_dive_site.latitude.udeg = lrint(lat * 1000000.0); displayed_dive_site.latitude.udeg = llrint(lat * 1000000.0);
displayed_dive_site.longitude.udeg = lrint(lon * 1000000.0); displayed_dive_site.longitude.udeg = llrint(lon * 1000000.0);
emit coordinatesChanged(); emit coordinatesChanged();
repopulateLabels(); repopulateLabels();
} }

View file

@ -41,7 +41,7 @@ void PreferencesGraph::refreshSettings()
ui->show_ccr_sensors->setChecked(prefs.show_ccr_sensors); ui->show_ccr_sensors->setChecked(prefs.show_ccr_sensors);
ui->defaultSetpoint->setValue((double)prefs.defaultsetpoint / 1000.0); ui->defaultSetpoint->setValue((double)prefs.defaultsetpoint / 1000.0);
ui->psro2rate->setValue(prefs.o2consumption / 1000.0); ui->psro2rate->setValue(prefs.o2consumption / 1000.0);
ui->pscrfactor->setValue(rint(1000.0 / prefs.pscr_ratio)); ui->pscrfactor->setValue(lrint(1000.0 / prefs.pscr_ratio));
ui->display_unused_tanks->setChecked(prefs.display_unused_tanks); ui->display_unused_tanks->setChecked(prefs.display_unused_tanks);
ui->show_average_depth->setChecked(prefs.show_average_depth); ui->show_average_depth->setChecked(prefs.show_average_depth);
@ -50,9 +50,9 @@ void PreferencesGraph::refreshSettings()
void PreferencesGraph::syncSettings() void PreferencesGraph::syncSettings()
{ {
auto general = SettingsObjectWrapper::instance()->general_settings; auto general = SettingsObjectWrapper::instance()->general_settings;
general->setDefaultSetPoint(rint(ui->defaultSetpoint->value() * 1000.0)); general->setDefaultSetPoint(lrint(ui->defaultSetpoint->value() * 1000.0));
general->setO2Consumption(rint(ui->psro2rate->value() *1000.0)); general->setO2Consumption(lrint(ui->psro2rate->value() *1000.0));
general->setPscrRatio(rint(1000.0 / ui->pscrfactor->value())); general->setPscrRatio(lrint(1000.0 / ui->pscrfactor->value()));
auto pp_gas = SettingsObjectWrapper::instance()->pp_gas; auto pp_gas = SettingsObjectWrapper::instance()->pp_gas;
pp_gas->setPheThreshold(ui->pheThreshold->value()); pp_gas->setPheThreshold(ui->pheThreshold->value());

View file

@ -37,7 +37,7 @@ void QMLProfile::paint(QPainter *painter)
qreal sy = painterRect.height() / sceneSize / dprComp; qreal sy = painterRect.height() / sceneSize / dprComp;
// next figure out the weird magic by which we need to shift the painter so the profile is shown // next figure out the weird magic by which we need to shift the painter so the profile is shown
int dpr = rint(devicePixelRatio()); int dpr = lrint(devicePixelRatio());
qreal magicShiftFactor = (dpr == 2 ? 0.25 : (dpr == 3 ? 0.33 : 0.0)); qreal magicShiftFactor = (dpr == 2 ? 0.25 : (dpr == 3 ? 0.33 : 0.0));
// now set up the transformations scale the profile and // now set up the transformations scale the profile and

View file

@ -949,8 +949,8 @@ void ProfileWidget2::mouseDoubleClickEvent(QMouseEvent *event)
if (isPointOutOfBoundaries(mappedPos)) if (isPointOutOfBoundaries(mappedPos))
return; return;
int minutes = rint(timeAxis->valueAt(mappedPos) / 60); int minutes = lrint(timeAxis->valueAt(mappedPos) / 60);
int milimeters = rint(profileYAxis->valueAt(mappedPos) / M_OR_FT(1, 1)) * M_OR_FT(1, 1); int milimeters = lrint(profileYAxis->valueAt(mappedPos) / M_OR_FT(1, 1)) * M_OR_FT(1, 1);
plannerModel->addStop(milimeters, minutes * 60, -1, 0, true); plannerModel->addStop(milimeters, minutes * 60, -1, 0, true);
} }
} }
@ -1789,13 +1789,13 @@ void ProfileWidget2::recreatePlannedDive()
if (index < plannerModel->size() - 1) if (index < plannerModel->size() - 1)
maxtime = plannerModel->at(index + 1).time; maxtime = plannerModel->at(index + 1).time;
int minutes = rint(timeAxis->valueAt(activeHandler->pos()) / 60); int minutes = lrint(timeAxis->valueAt(activeHandler->pos()) / 60);
if (minutes * 60 <= mintime || minutes * 60 >= maxtime) if (minutes * 60 <= mintime || minutes * 60 >= maxtime)
return; return;
divedatapoint data = plannerModel->at(index); divedatapoint data = plannerModel->at(index);
data.depth = rint(profileYAxis->valueAt(activeHandler->pos()) / M_OR_FT(1, 1)) * M_OR_FT(1, 1); data.depth = lrint(profileYAxis->valueAt(activeHandler->pos()) / M_OR_FT(1, 1)) * M_OR_FT(1, 1);
data.time = rint(timeAxis->valueAt(activeHandler->pos())); data.time = lrint(timeAxis->valueAt(activeHandler->pos()));
plannerModel->editStop(index, data); plannerModel->editStop(index, data);
} }

View file

@ -241,7 +241,7 @@ QVariant DivePlannerPointsModel::data(const QModelIndex &index, int role) const
case CCSETPOINT: case CCSETPOINT:
return (double)p.setpoint / 1000; return (double)p.setpoint / 1000;
case DEPTH: case DEPTH:
return (int) rint(get_depth_units(p.depth, NULL, NULL)); return (int) lrint(get_depth_units(p.depth, NULL, NULL));
case RUNTIME: case RUNTIME:
return p.time / 60; return p.time / 60;
case DURATION: case DURATION: