Changeset a748e7f in subsurface


Ignore:
Timestamp:
Dec 17, 2017, 9:02:44 AM (5 weeks ago)
Author:
Dirk Hohndel <dirk@…>
Branches:
master
Children:
b59778a
Parents:
b1d94b2
git-author:
Berthold Stoeger <bstoeger@…> (11/20/17 12:39:50)
git-committer:
Dirk Hohndel <dirk@…> (12/17/17 09:02:44)
Message:

Unify float calulations: use double

Internal floating point (FP) calculations should be performed using double
unless there is a very good reason. This avoids headaches with conversions.
Indeed, the vast majority of FP calculations were already done using double.
This patch adapts most remaining calculations. Not converted where things
that were based on binary representations and variables which weren't used
anyway.

An analysis of all instances follows:

core/plannernotes.c, l.404:

This was a comparison between two floats. On the left side, first an integer
was cast to float then multiplied with and integer and divided by a constant
double. The right hand side was an integer cast to a float. Simply divide by
1000.0 first to convert to double and continue with calculations. On the right
hand side, remove the cast, because the integer will be implicitely cast to
double for comparison. This conversion actually emits less instructions,
because no conversion to double and back is performed.

core/planner.c, l.613:

Same analysis as previous case.

subsurface-desktop-main.cpp, l.155:

A local variable representing the version OpenGL version. Turn this into
integer logic. Not only does this avoid dreaded FP rounding issues, it also
works correctly for minor version > 10 (not that such a thing is to be
expected anytime soon).

abstractpreferenceswidget.[h/cpp]:

A widget where the position is described as a float. Turn into double.

desktop-widgets/divelogexportdialog.cpp, l.313:

total_weight is described as float. Use double arithmetics instead. This
instance fixes a truncation warning emitted by gcc.

Files:
6 edited

Legend:

Unmodified
Added
Removed
  • core/planner.c

    ra9703628 ra748e7f  
    611611                return true;
    612612        if (cyl->type.size.mliter)
    613                 return (float)(cyl->end.mbar - prefs.reserve_gas) * cyl->type.size.mliter / 1000.0 > (float) cyl->deco_gas_used.mliter;
     613                return (cyl->end.mbar - prefs.reserve_gas) / 1000.0 * cyl->type.size.mliter > cyl->deco_gas_used.mliter;
    614614        else
    615615                return true;
  • core/plannernotes.c

    rd8350ef2 ra748e7f  
    402402                                        translate("gettextFromC", "this is more gas than available in the specified cylinder!"));
    403403                        else
    404                                 if ((float) cyl->end.mbar * cyl->type.size.mliter / 1000.0 / gas_compressibility_factor(&cyl->gasmix, cyl->end.mbar / 1000.0)
    405                                     < (float) cyl->deco_gas_used.mliter)
     404                                if (cyl->end.mbar / 1000.0 * cyl->type.size.mliter / gas_compressibility_factor(&cyl->gasmix, cyl->end.mbar / 1000.0)
     405                                    < cyl->deco_gas_used.mliter)
    406406                                        snprintf(warning, sizeof(warning), "<br>&nbsp;&mdash; <span style='color: red;'>%s </span> %s",
    407407                                                translate("gettextFromC", "Warning:"),
  • desktop-widgets/divelogexportdialog.cpp

    r256ae87 ra748e7f  
    311311                int qty_cyl;
    312312                int qty_weight;
    313                 float total_weight;
     313                double total_weight;
    314314
    315315                if (need_pagebreak)
  • desktop-widgets/preferences/abstractpreferenceswidget.cpp

    r9021a44 ra748e7f  
    22#include "abstractpreferenceswidget.h"
    33
    4 AbstractPreferencesWidget::AbstractPreferencesWidget(const QString& name, const QIcon& icon, float positionHeight)
     4AbstractPreferencesWidget::AbstractPreferencesWidget(const QString& name, const QIcon& icon, double positionHeight)
    55: QWidget(), _icon(icon), _name(name), _positionHeight(positionHeight)
    66{
     
    1717}
    1818
    19 float AbstractPreferencesWidget::positionHeight() const
     19double AbstractPreferencesWidget::positionHeight() const
    2020{
    2121        return _positionHeight;
  • desktop-widgets/preferences/abstractpreferenceswidget.h

    r9021a44 ra748e7f  
    99        Q_OBJECT
    1010public:
    11         AbstractPreferencesWidget(const QString& name, const QIcon& icon, float positionHeight);
     11        AbstractPreferencesWidget(const QString& name, const QIcon& icon, double positionHeight);
    1212        QIcon icon() const;
    1313        QString name() const;
    14         float positionHeight() const;
     14        double positionHeight() const;
    1515
    1616        /* gets the values from the preferences and should set the correct values in
     
    2727        QIcon _icon;
    2828        QString _name;
    29         float _positionHeight;
     29        double _positionHeight;
    3030};
    3131#endif
  • subsurface-desktop-main.cpp

    ra8fbceac ra748e7f  
    153153        QOpenGLFunctions *func;
    154154        const char *verChar;
    155         float verFloat;
    156155
    157156        surface.setFormat(ctx.format());
     
    183182                         return;
    184183                }
    185                 if (sscanf(verChar, "%f", &verFloat) == 1) {
    186                         verMajor = (GLint)verFloat;
    187                         verMinor = (GLint)roundf((verFloat - verMajor) * 10.f);
     184                int min, maj;
     185                if (sscanf(verChar, "%d.%d", &maj, &min) == 2) {
     186                        verMajor = (GLint)maj;
     187                        verMinor = (GLint)min;
    188188                }
    189189        }
Note: See TracChangeset for help on using the changeset viewer.