Changeset 597539c in subsurface


Ignore:
Timestamp:
Mar 24, 2017, 9:39:25 AM (4 weeks ago)
Author:
Dirk Hohndel <dirk@…>
Branches:
master
Children:
3413fcd1
Parents:
d83449f
git-author:
Jeremie Guichard <djebrest@…> (03/22/17 18:13:49)
git-committer:
Dirk Hohndel <dirk@…> (03/24/17 09:39:25)
Message:

Fix double to int truncation in C++ code

Wfloat-conversion enabled for C++ part of the code
Fix warnings raised by the flag using lrint

Original issue reported on the mailing list:
The ascent/descent rates are sometimes not what is expected.
E.g. setting the ascent rate to 10m/min results in an actual
ascent rate of 9m/min.
This is due to truncating the ascent rate preference,
then effectively rounding up the time to reach each stop to 2s intervals.
The result being that setting the ascent rate to 10m/min
results in 20s to ascend 3m (9m/min), when it should be exactly 18s.

Reported-by: John Smith <noseygit@…>
Reported-by: Rick Walsh <rickmwalsh@…>
Signed-off-by: Jeremie Guichard <djebrest@…>

Files:
25 edited

Legend:

Unmodified
Added
Removed
  • CMakeLists.txt

    r2b06a0b2 r597539c  
    9393        if (NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS "4.9.0")
    9494                set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wfloat-conversion")
     95                set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wfloat-conversion")
    9596        endif()
    9697
  • core/configuredivecomputerthreads.cpp

    r95d5771 r597539c  
    15671567        switch (event) {
    15681568        case DC_EVENT_PROGRESS:
    1569                 dt->progressCB(100.0 * (double)progress->current / (double)progress->maximum);
     1569                dt->progressCB(lrint(100.0 * (double)progress->current / (double)progress->maximum));
    15701570                break;
    15711571        default:
  • core/gpslocation.cpp

    r406e428 r597539c  
    158158                gt.when = pos.timestamp().toTime_t();
    159159                gt.when += gettimezoneoffset(gt.when);
    160                 gt.latitude.udeg = lrint(pos.coordinate().latitude() * 1000000);
    161                 gt.longitude.udeg = lrint(pos.coordinate().longitude() * 1000000);
     160                gt.latitude.udeg = (int)(pos.coordinate().latitude() * 1000000);
     161                gt.longitude.udeg = (int)(pos.coordinate().longitude() * 1000000);
    162162                addFixToStorage(gt);
    163163        }
     
    613613                                struct gpsTracker gt;
    614614                                gt.when = timestamp.toMSecsSinceEpoch() / 1000;
    615                                 gt.latitude.udeg = latitude.toDouble() * 1000000;
    616                                 gt.longitude.udeg = longitude.toDouble() * 1000000;
     615                                gt.latitude.udeg = (int)(latitude.toDouble() * 1000000);
     616                                gt.longitude.udeg = (int)(longitude.toDouble() * 1000000);
    617617                                gt.name = name;
    618618                                // add this GPS fix to the QMap and the settings (remove existing fix at the same timestamp first)
  • core/qthelper.cpp

    r406e428 r597539c  
    776776                minutes = numOnly;
    777777        }
    778         secs = hours.toDouble() * 3600 + minutes.toDouble() * 60 + seconds.toDouble();
     778        secs = lrint(hours.toDouble() * 3600 + minutes.toDouble() * 60 + seconds.toDouble());
    779779        return secs;
    780780}
     
    789789        double number = numOnly.toDouble();
    790790        if (text.contains(QObject::tr("m"), Qt::CaseInsensitive)) {
    791                 mm = number * 1000;
     791                mm = lrint(number * 1000);
    792792        } else if (text.contains(QObject::tr("ft"), Qt::CaseInsensitive)) {
    793793                mm = feet_to_mm(number);
     
    798798                        break;
    799799                case units::METERS:
    800                         mm = number * 1000;
     800                        mm = lrint(number * 1000);
    801801                        break;
    802802                default:
  • desktop-widgets/configuredivecomputerdialog.cpp

    r95d5771 r597539c  
    495495        deviceDetails->graphicalSpeedIndicator = ui.graphicalSpeedIndicator->isChecked();
    496496        deviceDetails->alwaysShowppO2 = ui.alwaysShowppO2->isChecked();
    497         deviceDetails->tempSensorOffset = ui.tempSensorOffsetDoubleSpinBox->value() * 10;
     497        deviceDetails->tempSensorOffset = lrint(ui.tempSensorOffsetDoubleSpinBox->value() * 10);
    498498        deviceDetails->safetyStopLength = ui.safetyStopLengthSpinBox->value();
    499         deviceDetails->safetyStopStartDepth = ui.safetyStopStartDepthDoubleSpinBox->value() * 10;
    500         deviceDetails->safetyStopEndDepth = ui.safetyStopEndDepthDoubleSpinBox->value() * 10;
    501         deviceDetails->safetyStopResetDepth = ui.safetyStopResetDepthDoubleSpinBox->value() * 10;
     499        deviceDetails->safetyStopStartDepth = lrint(ui.safetyStopStartDepthDoubleSpinBox->value() * 10);
     500        deviceDetails->safetyStopEndDepth = lrint(ui.safetyStopEndDepthDoubleSpinBox->value() * 10);
     501        deviceDetails->safetyStopResetDepth = lrint(ui.safetyStopResetDepthDoubleSpinBox->value() * 10);
    502502
    503503        //set gas values
     
    613613        deviceDetails->lastDeco = ui.lastDecoSpinBox_3->value();
    614614        deviceDetails->samplingRate = ui.samplingRateSpinBox_3->value();
    615         deviceDetails->salinity = ui.salinityDoubleSpinBox_3->value() * 100;
     615        deviceDetails->salinity = lrint(ui.salinityDoubleSpinBox_3->value() * 100);
    616616        deviceDetails->dateFormat = ui.dateFormatComboBox_3->currentIndex();
    617617        deviceDetails->syncTime = ui.dateTimeSyncCheckBox_3->isChecked();
     
    630630        deviceDetails->graphicalSpeedIndicator = ui.graphicalSpeedIndicator_3->isChecked();
    631631        deviceDetails->safetyStopLength = ui.safetyStopLengthSpinBox_3->value();
    632         deviceDetails->safetyStopStartDepth = ui.safetyStopStartDepthDoubleSpinBox_3->value() * 10;
    633         deviceDetails->safetyStopEndDepth = ui.safetyStopEndDepthDoubleSpinBox_3->value() * 10;
    634         deviceDetails->safetyStopResetDepth = ui.safetyStopResetDepthDoubleSpinBox_3->value() * 10;
     632        deviceDetails->safetyStopStartDepth = lrint(ui.safetyStopStartDepthDoubleSpinBox_3->value() * 10);
     633        deviceDetails->safetyStopEndDepth = lrint(ui.safetyStopEndDepthDoubleSpinBox_3->value() * 10);
     634        deviceDetails->safetyStopResetDepth = lrint(ui.safetyStopResetDepthDoubleSpinBox_3->value() * 10);
    635635
    636636        //set gas values
  • desktop-widgets/diveplanner.cpp

    r0828427 r597539c  
    229229{
    230230        /* Salinity is expressed in weight in grams per 10l */
    231         plannerModel->setSalinity(10000 * salinity);
     231        plannerModel->setSalinity(lrint(10000 * salinity));
    232232}
    233233
     
    479479void PlannerSettingsWidget::setAscRate75(int rate)
    480480{
    481         SettingsObjectWrapper::instance()->planner_settings->setAscrate75(rate * UNIT_FACTOR);
     481        SettingsObjectWrapper::instance()->planner_settings->setAscrate75(lrint(rate * UNIT_FACTOR));
    482482}
    483483
    484484void PlannerSettingsWidget::setAscRate50(int rate)
    485485{
    486         SettingsObjectWrapper::instance()->planner_settings->setAscrate50(rate * UNIT_FACTOR);
     486        SettingsObjectWrapper::instance()->planner_settings->setAscrate50(lrint(rate * UNIT_FACTOR));
    487487}
    488488
    489489void PlannerSettingsWidget::setAscRateStops(int rate)
    490490{
    491         SettingsObjectWrapper::instance()->planner_settings->setAscratestops(rate * UNIT_FACTOR);
     491        SettingsObjectWrapper::instance()->planner_settings->setAscratestops(lrint(rate * UNIT_FACTOR));
    492492}
    493493
    494494void PlannerSettingsWidget::setAscRateLast6m(int rate)
    495495{
    496         SettingsObjectWrapper::instance()->planner_settings->setAscratelast6m(rate * UNIT_FACTOR);
     496        SettingsObjectWrapper::instance()->planner_settings->setAscratelast6m(lrint(rate * UNIT_FACTOR));
    497497}
    498498
    499499void PlannerSettingsWidget::setDescRate(int rate)
    500500{
    501         SettingsObjectWrapper::instance()->planner_settings->setDescrate(rate * UNIT_FACTOR);
     501        SettingsObjectWrapper::instance()->planner_settings->setDescrate(lrint(rate * UNIT_FACTOR));
    502502}
    503503
  • desktop-widgets/downloadfromdivecomputer.cpp

    r59d18a0 r597539c  
    127127                ui.progressBar->setFormat("%p%");
    128128        }
    129         ui.progressBar->setValue(progress_bar_fraction * 100);
     129        ui.progressBar->setValue(lrint(progress_bar_fraction * 100));
    130130}
    131131
  • desktop-widgets/globe.cpp

    r406e428 r597539c  
    268268        // the current zoom level
    269269        if (currentZoomLevel == -1) {
    270                 currentZoomLevel = zoomFromDistance(3.0);
     270                currentZoomLevel = lrint(zoomFromDistance(3.0));
    271271                centerOn(longitude, latitude);
    272272                fixZoom(true);
  • desktop-widgets/groupedlineedit.cpp

    re49d621 r597539c  
    140140        QSize rs(
    141141                40,
    142                 document()->findBlock(0).layout()->lineAt(0).height() +
     142                lrint(document()->findBlock(0).layout()->lineAt(0).height() +
    143143                        document()->documentMargin() * 2 +
    144                         frameWidth() * 2);
     144                        frameWidth() * 2));
    145145        return rs;
    146146}
  • desktop-widgets/kmessagewidget.cpp

    re49d621 r597539c  
    178178void KMessageWidgetPrivate::slotTimeLineChanged(qreal value)
    179179{
    180     q->setFixedHeight(qMin(value * 2, qreal(1.0)) * content->height());
    181     q->update();
     180        q->setFixedHeight(lrint(qMin(value * 2, qreal(1.0)) * content->height()));
     181        q->update();
    182182}
    183183
  • desktop-widgets/locationinformation.cpp

    r7be962b r597539c  
    157157                double lat, lon;
    158158                parseGpsText(ui.diveSiteCoordinates->text(), &lat, &lon);
    159                 currentDs->latitude.udeg = lat * 1000000.0;
    160                 currentDs->longitude.udeg = lon * 1000000.0;
     159                currentDs->latitude.udeg = (int)(lat * 1000000.0);
     160                currentDs->longitude.udeg = (int)(lon * 1000000.0);
    161161        }
    162162        if (dive_site_is_empty(currentDs)) {
     
    233233                double latitude, longitude;
    234234                if (parseGpsText(text, &latitude, &longitude)) {
    235                         displayed_dive_site.latitude.udeg = latitude * 1000000;
    236                         displayed_dive_site.longitude.udeg = longitude * 1000000;
     235                        displayed_dive_site.latitude.udeg = (int)(latitude * 1000000);
     236                        displayed_dive_site.longitude.udeg = (int)(longitude * 1000000);
    237237                        markChangedWidget(ui.diveSiteCoordinates);
    238238                        emit coordinatesChanged();
  • desktop-widgets/maintab.cpp

    rf7cbe24 r597539c  
    630630                        volumes.append(get_volume_string(gases[i], true));
    631631                        if (duration[i]) {
    632                                 sac.mliter = gases[i].mliter / (depth_to_atm(mean[i], &displayed_dive) * duration[i] / 60);
     632                                sac.mliter = lrint(gases[i].mliter / (depth_to_atm(mean[i], &displayed_dive) * duration[i] / 60));
    633633                                SACs.append(get_volume_string(sac, true).append(tr("/min")));
    634634                        }
  • desktop-widgets/mainwindow.cpp

    rd36f056 r597539c  
    10421042        view->setModel(m);
    10431043        l->addWidget(view);
    1044         d.resize(width() * .8, height() / 2);
    1045         d.move(width() * .1, height() / 4);
     1044        d.resize(lrint(width() * .8), height() / 2);
     1045        d.move(lrint(width() * .1), height() / 4);
    10461046        QShortcut *close = new QShortcut(QKeySequence(Qt::CTRL + Qt::Key_W), &d);
    10471047        connect(close, SIGNAL(activated()), &d, SLOT(close()));
     
    11061106        const int appW = qApp->desktop()->size().width();
    11071107        if (mainSizes.empty()) {
    1108                 mainSizes.append(appH * 0.7);
    1109                 mainSizes.append(appH * 0.3);
     1108                mainSizes.append(lrint(appH * 0.7));
     1109                mainSizes.append(lrint(appH * 0.3));
    11101110        }
    11111111        static QList<int> infoProfileSizes;
    11121112        if (infoProfileSizes.empty()) {
    1113                 infoProfileSizes.append(appW * 0.3);
    1114                 infoProfileSizes.append(appW * 0.7);
     1113                infoProfileSizes.append(lrint(appW * 0.3));
     1114                infoProfileSizes.append(lrint(appW * 0.7));
    11151115        }
    11161116
    11171117        static QList<int> listGlobeSizes;
    11181118        if (listGlobeSizes.empty()) {
    1119                 listGlobeSizes.append(appW * 0.7);
    1120                 listGlobeSizes.append(appW * 0.3);
     1119                listGlobeSizes.append(lrint(appW * 0.7));
     1120                listGlobeSizes.append(lrint(appW * 0.3));
    11211121        }
    11221122
  • desktop-widgets/modeldelegates.cpp

    rb1ed04a r597539c  
    527527                painter->setPen(QPen(opt.palette.highlight().color().darker()));
    528528                painter->setBrush(opt.palette.highlight());
    529                 const qreal pad = 1.0;
    530                 const qreal pad2 = pad * 2.0;
    531                 const qreal rounding = 5.0;
     529                const int pad = 1;
     530                const int pad2 = pad * 2;
     531                const int rounding = 5;
    532532                painter->drawRoundedRect(option.rect.x() + pad,
    533                         option.rect.y() + pad,
    534                         option.rect.width() - pad2,
    535                         option.rect.height() - pad2,
    536                         rounding, rounding);
     533                                        option.rect.y() + pad,
     534                                        option.rect.width() - pad2,
     535                                        option.rect.height() - pad2,
     536                                        rounding, rounding);
    537537        }
    538538        painter->setPen(textPen);
    539539        painter->setFont(fontBigger);
    540         const qreal textPad = 5.0;
     540        const int textPad = 5;
    541541        painter->drawText(option.rect.x() + textPad, option.rect.y() + fmBigger.boundingRect("YH").height(), diveSiteName);
    542542        double pointSize = fontSmaller.pointSizeF();
  • desktop-widgets/printer.cpp

    re8c9186 r597539c  
    105105
    106106                        // rendering progress is 4/5 of total work
    107                         emit(progessUpdated((end * 80.0 / fullPageResolution) + done));
     107                        emit(progessUpdated(lrint((end * 80.0 / fullPageResolution) + done)));
    108108
    109109                        // add new pages only in print mode, while previewing we don't add new pages
     
    184184
    185185                // rendering progress is 4/5 of total work
    186                 emit(progessUpdated((i * 80.0 / Pages) + done));
     186                emit(progessUpdated(lrint((i * 80.0 / Pages) + done)));
    187187                if (i < Pages - 1 && printMode == Printer::PRINT)
    188188                        static_cast<QPrinter*>(paintDevice)->newPage();
  • desktop-widgets/templateedit.cpp

    re8c9186 r597539c  
    1818        // restore the settings and init the UI
    1919        ui->fontSelection->setCurrentIndex(templateOptions->font_index);
    20         ui->fontsize->setValue(templateOptions->font_size);
     20        ui->fontsize->setValue(lrint(templateOptions->font_size));
    2121        ui->colorpalette->setCurrentIndex(templateOptions->color_palette_index);
    2222        ui->linespacing->setValue(templateOptions->line_spacing);
  • desktop-widgets/templatelayout.cpp

    rad2ac58 r597539c  
    106106                diveList.append(QVariant::fromValue(d));
    107107                progress++;
    108                 emit progressUpdated(progress * 100.0 / totalWork);
     108                emit progressUpdated(lrint(progress * 100.0 / totalWork));
    109109        }
    110110        Grantlee::Context c;
  • profile-widget/divecartesianaxis.cpp

    r7be962b r597539c  
    370370        if (value == 0)
    371371                return QString();
    372         return get_depth_string(value, false, false);
     372        return get_depth_string(lrint(value), false, false);
    373373}
    374374
     
    410410QString TimeAxis::textForValue(double value)
    411411{
    412         int nr = value / 60;
     412        int nr = lrint(value) / 60;
    413413        if (maximum() < 600)
    414414                return QString("%1:%2").arg(nr).arg((int)value % 60, 2, 10, QChar('0'));
  • profile-widget/diveprofileitem.cpp

    rb14301a r597539c  
    668668        int decimals;
    669669        const char *unitText;
    670         double d = get_depth_units(lastRunningSum, &decimals, &unitText);
     670        double d = get_depth_units(lrint(lastRunningSum), &decimals, &unitText);
    671671        DiveTextItem *text = new DiveTextItem(this);
    672672        text->setAlignment(Qt::AlignRight | Qt::AlignTop);
  • profile-widget/divetextitem.cpp

    r176b927 r597539c  
    8989                // set in pixels - so the scale factor may not make a difference if it's too close to 1
    9090                size *= scale * printScale;
    91                 fnt.setPixelSize(size);
     91                fnt.setPixelSize(lrint(size));
    9292        } else {
    9393                size = fnt.pointSizeF();
  • profile-widget/divetooltipitem.cpp

    rbb4bf63 r597539c  
    109109        // clip the height
    110110        if (entryToolTip.first) {
    111                 const int minH = entryToolTip.first->y() + entryToolTip.first->pixmap().height() + sp2;
     111                const int minH = lrint(entryToolTip.first->y() + entryToolTip.first->pixmap().height() + sp2);
    112112                if (height < minH)
    113113                        height = minH;
     
    246246        refreshTime.start();
    247247
    248         int time = timeAxis->valueAt(pos);
     248        int time = lrint(timeAxis->valueAt(pos));
    249249        if (time == lastTime)
    250250                return;
     
    270270                painter.setPen(QColor(0, 0, 0, 255));
    271271                if (decoMode() == BUEHLMANN)
    272                         painter.drawLine(0, 60 - entry->gfline / 2, 16, 60 - entry->gfline / 2);
    273                 painter.drawLine(0, 60 - AMB_PERCENTAGE * (entry->pressures.n2 + entry->pressures.he) / entry->ambpressure / 2,
    274                                 16, 60 - AMB_PERCENTAGE * (entry->pressures.n2 + entry->pressures.he) / entry->ambpressure /2);
     272                        painter.drawLine(0, lrint(60 - entry->gfline / 2), 16, lrint(60 - entry->gfline / 2));
     273                painter.drawLine(0, lrint(60 - AMB_PERCENTAGE * (entry->pressures.n2 + entry->pressures.he) / entry->ambpressure / 2),
     274                                16, lrint(60 - AMB_PERCENTAGE * (entry->pressures.n2 + entry->pressures.he) / entry->ambpressure /2));
    275275                painter.setPen(QColor(0, 0, 0, 127));
    276276                for (int i=0; i<16; i++) {
  • profile-widget/profilewidget2.cpp

    r0828427 r597539c  
    976976        const qreal yRat = (qreal)pos.y() / viewport()->height();
    977977        const qreal xRat = (qreal)pos.x() / viewport()->width();
    978         vs->setValue(yRat * vs->maximum());
    979         hs->setValue(xRat * hs->maximum());
     978        vs->setValue(lrint(yRat * vs->maximum()));
     979        hs->setValue(lrint(xRat * hs->maximum()));
    980980}
    981981
     
    13131313{
    13141314        // find the time stamp corresponding to the mouse position
    1315         int seconds = timeAxis->valueAt(pos);
     1315        int seconds = lrint(timeAxis->valueAt(pos));
    13161316        struct plot_data *entry = NULL;
    13171317
     
    15411541        QAction *action = qobject_cast<QAction *>(sender());
    15421542        QPointF scenePos = mapToScene(mapFromGlobal(action->data().toPoint()));
    1543         add_event(current_dc, timeAxis->valueAt(scenePos), SAMPLE_EVENT_BOOKMARK, 0, 0, "bookmark");
     1543        add_event(current_dc, lrint(timeAxis->valueAt(scenePos)), SAMPLE_EVENT_BOOKMARK, 0, 0, "bookmark");
    15441544        invalidate_dive_cache(current_dive);
    15451545        mark_divelist_changed(true);
     
    15511551        QAction *action = qobject_cast<QAction *>(sender());
    15521552        QPointF scenePos = mapToScene(mapFromGlobal(action->data().toPoint()));
    1553         SetpointDialog::instance()->setpointData(current_dc, timeAxis->valueAt(scenePos));
     1553        SetpointDialog::instance()->setpointData(current_dc, lrint(timeAxis->valueAt(scenePos)));
    15541554        SetpointDialog::instance()->show();
    15551555}
     
    17841784        DivePlannerPointsModel *plannerModel = DivePlannerPointsModel::instance();
    17851785        int index = fixHandlerIndex(activeHandler);
    1786         int mintime = 0, maxtime = (timeAxis->maximum() + 10) * 60;
     1786        int mintime = 0, maxtime = lrint((timeAxis->maximum() + 10) * 60);
    17871787        if (index > 0)
    17881788                mintime = plannerModel->at(index - 1).time;
     
    19931993                FOR_EACH_PICTURE(current_dive) {
    19941994                        if (QString(picture->filename) == filename) {
    1995                                 picture->offset.seconds = timeAxis->valueAt(mappedPos);
     1995                                picture->offset.seconds = lrint(timeAxis->valueAt(mappedPos));
    19961996                                mark_divelist_changed(true);
    19971997                                break;
  • profile-widget/ruleritem.cpp

    r7be962b r597539c  
    128128        // clamp so that the text doesn't go out of the screen to the right
    129129        if (diff > view->width()) {
    130                 begin.setX(begin.x() - (diff - view->width()));
     130                begin.setX(lrint(begin.x() - (diff - view->width())));
    131131                tgtX = mapFromScene(view->mapToScene(begin)).x();
    132132        }
  • qt-models/tankinfomodel.cpp

    r7be962b r597539c  
    6363
    6464                if (info->cuft && info->psi)
    65                         ml = cuft_to_l(info->cuft) * 1000 / bar_to_atm(bar);
     65                        ml = lrint(cuft_to_l(info->cuft) * 1000 / bar_to_atm(bar));
    6666
    6767                switch (index.column()) {
  • tests/testplan.cpp

    r6f21d27 r597539c  
    333333                int permilDifferenceAllowed = 1 * 10;
    334334                int absoluteDifferenceAllowedSeconds = 60;
    335                 int totalDifferenceAllowed = 0.001 * permilDifferenceAllowed * benchmarkRunTimeSeconds + absoluteDifferenceAllowedSeconds;
     335                int totalDifferenceAllowed = lrint(0.001 * permilDifferenceAllowed * benchmarkRunTimeSeconds + absoluteDifferenceAllowedSeconds);
    336336                int totalDifference = abs(actualRunTimeSeconds - benchmarkRunTimeSeconds);
    337337
Note: See TracChangeset for help on using the changeset viewer.