Skip to content

Commit

Permalink
Fix formatting of some larger file sizes on 32bit x86
Browse files Browse the repository at this point in the history
With the x87 FPU available, GCC uses long double precision for some variables.
Due to the function call passing a double, some comparisons break down.
That resulted in "1.00 YB" being printed as "1000.00 ZB" instead.

Fixes steveire#85
  • Loading branch information
Vogtinator committed Nov 13, 2022
1 parent 20d415b commit 7e34ffa
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions templates/lib/util.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
#include "metaenumvariable_p.h"
#include "metatype.h"

#include <cfloat>
#include <QtCore/QStringList>

QString Grantlee::unescapeStringLiteral(const QString &input)
Expand Down Expand Up @@ -212,7 +213,13 @@ std::pair<qreal, QString> Grantlee::calcFileSize(qreal size, int unitSystem,
bool found = false;
int count = 0;
const qreal baseVal = (_unitSystem == 10) ? 1000.0F : 1024.0F;
#if FLT_EVAL_METHOD == 2
// Avoid that this is treated as long double, as the increased
// precision breaks the comparison below.
volatile qreal current = 1.0F;
#else
qreal current = 1.0F;
#endif
int units = decimalUnits.size();
while (!found && (count < units)) {
current *= baseVal;
Expand Down

0 comments on commit 7e34ffa

Please sign in to comment.