Skip to content

Commit 7e34ffa

Browse files
committed
Fix formatting of some larger file sizes on 32bit x86
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
1 parent 20d415b commit 7e34ffa

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

Diff for: templates/lib/util.cpp

+7
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
#include "metaenumvariable_p.h"
2424
#include "metatype.h"
2525

26+
#include <cfloat>
2627
#include <QtCore/QStringList>
2728

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

0 commit comments

Comments
 (0)