From 5274748a73ed98c2fe03665aab9649c10e25d60f Mon Sep 17 00:00:00 2001 From: Buschmann Date: Sat, 10 Dec 2022 06:51:22 +0100 Subject: [PATCH 1/2] 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. Fix taken from https://github.com/steveire/grantlee/pull/86 --- templates/lib/util.cpp | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/templates/lib/util.cpp b/templates/lib/util.cpp index 2e9cb95..b644f4d 100644 --- a/templates/lib/util.cpp +++ b/templates/lib/util.cpp @@ -26,6 +26,8 @@ #include #include +#include + QString Cutelee::unescapeStringLiteral(const QString &input) { return input.mid(1, input.size() - 2) @@ -266,7 +268,13 @@ std::pair 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; From 42be3620a868900d5aebdc13be39b90b7e863a43 Mon Sep 17 00:00:00 2001 From: Buschmann Date: Sat, 10 Dec 2022 06:53:48 +0100 Subject: [PATCH 2/2] Remove unneeded variable --- templates/lib/util.cpp | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/templates/lib/util.cpp b/templates/lib/util.cpp index b644f4d..b3fbd0e 100644 --- a/templates/lib/util.cpp +++ b/templates/lib/util.cpp @@ -265,7 +265,6 @@ std::pair Cutelee::calcFileSize(qreal size, int unitSystem, qreal QStringLiteral("YB") }); - bool found = false; int count = 0; const qreal baseVal = (_unitSystem == 10) ? 1000.0f : 1024.0f; #if FLT_EVAL_METHOD == 2 @@ -276,10 +275,9 @@ std::pair Cutelee::calcFileSize(qreal size, int unitSystem, qreal qreal current = 1.0f; #endif int units = decimalUnits.size(); - while (!found && (count < units)) { + while (count < units) { current *= baseVal; if (_size < current) { - found = true; break; } count++;