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.

Fix taken from steveire/grantlee#86
  • Loading branch information
buschmann23 committed Dec 10, 2022
1 parent f425132 commit 712e6ac
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions templates/lib/util.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@
#include <QtCore/QStringList>
#include <QDebug>

#include <cfloat>

QString Cutelee::unescapeStringLiteral(const QString &input)
{
return input.mid(1, input.size() - 2)
Expand Down Expand Up @@ -266,7 +268,13 @@ std::pair<qreal,QString> Cutelee::calcFileSize(qreal size, int unitSystem, qreal
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 712e6ac

Please sign in to comment.