|
| 1 | +From 13094b78a790786030a468453c2b3ead4c7fd9cf Mon Sep 17 00:00:00 2001 |
| 2 | +From: Fabian Vogt < [email protected]> |
| 3 | +Date: Sun, 13 Nov 2022 14:01:21 +0100 |
| 4 | +Subject: [PATCH] Fix formatting of some larger file sizes on 32bit x86 |
| 5 | + |
| 6 | +With the x87 FPU available, GCC uses long double precision for some variables. |
| 7 | +Due to the function call passing a double, some comparisons break down. |
| 8 | +That resulted in "1.00 YB" being printed as "1000.00 ZB" instead. |
| 9 | + |
| 10 | +Fixes #85 |
| 11 | +--- |
| 12 | + templates/lib/util.cpp | 7 +++++++ |
| 13 | + 1 file changed, 7 insertions(+) |
| 14 | + |
| 15 | +diff --git a/templates/lib/util.cpp b/templates/lib/util.cpp |
| 16 | +index 504674a7..a0381c59 100644 |
| 17 | +--- a/templates/lib/util.cpp |
| 18 | ++++ b/templates/lib/util.cpp |
| 19 | +@@ -23,6 +23,7 @@ |
| 20 | + #include "metaenumvariable_p.h" |
| 21 | + #include "metatype.h" |
| 22 | + |
| 23 | ++#include <cfloat> |
| 24 | + #include <QtCore/QStringList> |
| 25 | + |
| 26 | + QString Grantlee::unescapeStringLiteral(const QString &input) |
| 27 | +@@ -212,7 +213,13 @@ std::pair<qreal, QString> Grantlee::calcFileSize(qreal size, int unitSystem, |
| 28 | + bool found = false; |
| 29 | + int count = 0; |
| 30 | + const qreal baseVal = (_unitSystem == 10) ? 1000.0F : 1024.0F; |
| 31 | ++#if FLT_EVAL_METHOD == 2 |
| 32 | ++ // Avoid that this is treated as long double, as the increased |
| 33 | ++ // precision breaks the comparison below. |
| 34 | ++ volatile qreal current = 1.0F; |
| 35 | ++#else |
| 36 | + qreal current = 1.0F; |
| 37 | ++#endif |
| 38 | + int units = decimalUnits.size(); |
| 39 | + while (!found && (count < units)) { |
| 40 | + current *= baseVal; |
0 commit comments