mirror of
https://github.com/subsurface/subsurface.git
synced 2024-11-28 05:00:20 +00:00
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.
This commit is contained in:
parent
b1d94b2470
commit
a748e7f239
6 changed files with 13 additions and 13 deletions
|
@ -610,7 +610,7 @@ bool enough_gas(int current_cylinder)
|
||||||
if (!cyl->start.mbar)
|
if (!cyl->start.mbar)
|
||||||
return true;
|
return true;
|
||||||
if (cyl->type.size.mliter)
|
if (cyl->type.size.mliter)
|
||||||
return (float)(cyl->end.mbar - prefs.reserve_gas) * cyl->type.size.mliter / 1000.0 > (float) cyl->deco_gas_used.mliter;
|
return (cyl->end.mbar - prefs.reserve_gas) / 1000.0 * cyl->type.size.mliter > cyl->deco_gas_used.mliter;
|
||||||
else
|
else
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
|
@ -401,8 +401,8 @@ void add_plan_to_notes(struct diveplan *diveplan, struct dive *dive, bool show_d
|
||||||
translate("gettextFromC", "Warning:"),
|
translate("gettextFromC", "Warning:"),
|
||||||
translate("gettextFromC", "this is more gas than available in the specified cylinder!"));
|
translate("gettextFromC", "this is more gas than available in the specified cylinder!"));
|
||||||
else
|
else
|
||||||
if ((float) cyl->end.mbar * cyl->type.size.mliter / 1000.0 / gas_compressibility_factor(&cyl->gasmix, cyl->end.mbar / 1000.0)
|
if (cyl->end.mbar / 1000.0 * cyl->type.size.mliter / gas_compressibility_factor(&cyl->gasmix, cyl->end.mbar / 1000.0)
|
||||||
< (float) cyl->deco_gas_used.mliter)
|
< cyl->deco_gas_used.mliter)
|
||||||
snprintf(warning, sizeof(warning), "<br> — <span style='color: red;'>%s </span> %s",
|
snprintf(warning, sizeof(warning), "<br> — <span style='color: red;'>%s </span> %s",
|
||||||
translate("gettextFromC", "Warning:"),
|
translate("gettextFromC", "Warning:"),
|
||||||
translate("gettextFromC", "not enough reserve for gas sharing on ascent!"));
|
translate("gettextFromC", "not enough reserve for gas sharing on ascent!"));
|
||||||
|
|
|
@ -310,7 +310,7 @@ void DiveLogExportDialog::export_TeX(const char *filename, const bool selected_o
|
||||||
int i;
|
int i;
|
||||||
int qty_cyl;
|
int qty_cyl;
|
||||||
int qty_weight;
|
int qty_weight;
|
||||||
float total_weight;
|
double total_weight;
|
||||||
|
|
||||||
if (need_pagebreak)
|
if (need_pagebreak)
|
||||||
put_format(&buf, "\\vfill\\eject\n");
|
put_format(&buf, "\\vfill\\eject\n");
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
// SPDX-License-Identifier: GPL-2.0
|
// SPDX-License-Identifier: GPL-2.0
|
||||||
#include "abstractpreferenceswidget.h"
|
#include "abstractpreferenceswidget.h"
|
||||||
|
|
||||||
AbstractPreferencesWidget::AbstractPreferencesWidget(const QString& name, const QIcon& icon, float positionHeight)
|
AbstractPreferencesWidget::AbstractPreferencesWidget(const QString& name, const QIcon& icon, double positionHeight)
|
||||||
: QWidget(), _icon(icon), _name(name), _positionHeight(positionHeight)
|
: QWidget(), _icon(icon), _name(name), _positionHeight(positionHeight)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
@ -16,7 +16,7 @@ QString AbstractPreferencesWidget::name() const
|
||||||
return _name;
|
return _name;
|
||||||
}
|
}
|
||||||
|
|
||||||
float AbstractPreferencesWidget::positionHeight() const
|
double AbstractPreferencesWidget::positionHeight() const
|
||||||
{
|
{
|
||||||
return _positionHeight;
|
return _positionHeight;
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,10 +8,10 @@
|
||||||
class AbstractPreferencesWidget : public QWidget {
|
class AbstractPreferencesWidget : public QWidget {
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
AbstractPreferencesWidget(const QString& name, const QIcon& icon, float positionHeight);
|
AbstractPreferencesWidget(const QString& name, const QIcon& icon, double positionHeight);
|
||||||
QIcon icon() const;
|
QIcon icon() const;
|
||||||
QString name() const;
|
QString name() const;
|
||||||
float positionHeight() const;
|
double positionHeight() const;
|
||||||
|
|
||||||
/* gets the values from the preferences and should set the correct values in
|
/* gets the values from the preferences and should set the correct values in
|
||||||
* the interface */
|
* the interface */
|
||||||
|
@ -26,6 +26,6 @@ signals:
|
||||||
private:
|
private:
|
||||||
QIcon _icon;
|
QIcon _icon;
|
||||||
QString _name;
|
QString _name;
|
||||||
float _positionHeight;
|
double _positionHeight;
|
||||||
};
|
};
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -152,7 +152,6 @@ void validateGL()
|
||||||
QOffscreenSurface surface;
|
QOffscreenSurface surface;
|
||||||
QOpenGLFunctions *func;
|
QOpenGLFunctions *func;
|
||||||
const char *verChar;
|
const char *verChar;
|
||||||
float verFloat;
|
|
||||||
|
|
||||||
surface.setFormat(ctx.format());
|
surface.setFormat(ctx.format());
|
||||||
surface.create();
|
surface.create();
|
||||||
|
@ -182,9 +181,10 @@ void validateGL()
|
||||||
"before running Subsurface!\n").toUtf8().data();
|
"before running Subsurface!\n").toUtf8().data();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (sscanf(verChar, "%f", &verFloat) == 1) {
|
int min, maj;
|
||||||
verMajor = (GLint)verFloat;
|
if (sscanf(verChar, "%d.%d", &maj, &min) == 2) {
|
||||||
verMinor = (GLint)roundf((verFloat - verMajor) * 10.f);
|
verMajor = (GLint)maj;
|
||||||
|
verMinor = (GLint)min;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// attempt to detect version using the newer API
|
// attempt to detect version using the newer API
|
||||||
|
|
Loading…
Reference in a new issue