QTest::toString: remove massageExponent()
We don't need it after tst_selftests got code to normalize floating point string representations. Change-Id: Id9cd1293ade99e77b900fffd0bd292418a6ea475 Reviewed-by: Edward Welbourne <edward.welbourne@qt.io>
This commit is contained in:
parent
395d23fbb3
commit
297df8317c
@ -3072,32 +3072,6 @@ TO_STRING_IMPL(bool, %d)
|
|||||||
TO_STRING_IMPL(signed char, %hhd)
|
TO_STRING_IMPL(signed char, %hhd)
|
||||||
TO_STRING_IMPL(unsigned char, %hhu)
|
TO_STRING_IMPL(unsigned char, %hhu)
|
||||||
|
|
||||||
/*!
|
|
||||||
\internal
|
|
||||||
|
|
||||||
Be consistent about leading 0 in exponent.
|
|
||||||
|
|
||||||
POSIX specifies that %e (hence %g when using it) uses at least two digits in
|
|
||||||
the exponent, requiring a leading 0 on single-digit exponents; (at least)
|
|
||||||
MinGW includes a leading zero also on an already-two-digit exponent,
|
|
||||||
e.g. 9e-040, which differs from more usual platforms. So massage that away.
|
|
||||||
*/
|
|
||||||
static void massageExponent(char *text)
|
|
||||||
{
|
|
||||||
char *p = strchr(text, 'e');
|
|
||||||
if (!p)
|
|
||||||
return;
|
|
||||||
const char *const end = p + strlen(p); // *end is '\0'
|
|
||||||
p += (p[1] == '-' || p[1] == '+') ? 2 : 1;
|
|
||||||
if (p[0] != '0' || end - 2 <= p)
|
|
||||||
return;
|
|
||||||
// We have a leading 0 on an exponent of at least two more digits
|
|
||||||
const char *n = p + 1;
|
|
||||||
while (end - 2 > n && n[0] == '0')
|
|
||||||
++n;
|
|
||||||
memmove(p, n, end + 1 - n);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Be consistent about display of infinities and NaNs (snprintf()'s varies,
|
// Be consistent about display of infinities and NaNs (snprintf()'s varies,
|
||||||
// notably on MinGW, despite POSIX documenting "[-]inf" or "[-]infinity" for %f,
|
// notably on MinGW, despite POSIX documenting "[-]inf" or "[-]infinity" for %f,
|
||||||
// %e and %g, uppercasing for their capital versions; similar for "nan"):
|
// %e and %g, uppercasing for their capital versions; similar for "nan"):
|
||||||
@ -3112,9 +3086,7 @@ static char *toStringFp(double t, int digits10)
|
|||||||
qstrncpy(msg, "nan", 128);
|
qstrncpy(msg, "nan", 128);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
std::snprintf(msg, 128, "%.*g", digits10, t);
|
std::snprintf(msg, 128, "%.*g (%a)", digits10, t, t);
|
||||||
massageExponent(msg);
|
|
||||||
std::snprintf(msg + strlen(msg), 128 - strlen(msg), " (%a)", t);
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
return msg;
|
return msg;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user