Move some purely floating-point testing from tst_QLocale to tst_QNumeric
The testing of infinity and NaN somewhat duplicated existing tests in tst_QNumeric and, in any case, belongs there. Change-Id: I6b5d1ff9767daf8e4bbe0025d3efab3d74ed35de Reviewed-by: Miikka Heikkinen <miikka.heikkinen@qt.io> Reviewed-by: Sona Kurazyan <sona.kurazyan@qt.io>
This commit is contained in:
parent
3a2e3625d1
commit
2e044791b8
@ -179,6 +179,15 @@ void tst_QNumeric::fuzzyIsNull()
|
||||
QCOMPARE(::qFuzzyIsNull(-value), isNull);
|
||||
}
|
||||
|
||||
static void clearFpExceptions()
|
||||
{
|
||||
// Call after any functions that exercise floating-point exceptions, such as
|
||||
// sqrt(-1) or log(0).
|
||||
#ifdef Q_OS_WIN
|
||||
_clearfp();
|
||||
#endif
|
||||
}
|
||||
|
||||
#if defined __FAST_MATH__ && (__GNUC__ * 100 + __GNUC_MINOR__ >= 404)
|
||||
// turn -ffast-math off
|
||||
# pragma GCC optimize "no-fast-math"
|
||||
@ -187,6 +196,7 @@ void tst_QNumeric::fuzzyIsNull()
|
||||
template<typename F>
|
||||
void tst_QNumeric::checkNaN(F nan)
|
||||
{
|
||||
const auto cleanup = qScopeGuard([]() { clearFpExceptions(); });
|
||||
#define CHECKNAN(value) \
|
||||
do { \
|
||||
const F v = (value); \
|
||||
@ -211,6 +221,7 @@ void tst_QNumeric::checkNaN(F nan)
|
||||
CHECKNAN(one / nan);
|
||||
CHECKNAN(zero / nan);
|
||||
CHECKNAN(zero * nan);
|
||||
CHECKNAN(sqrt(-one));
|
||||
|
||||
// When any NaN is expected, any NaN will do:
|
||||
QCOMPARE(nan, nan);
|
||||
@ -298,6 +309,7 @@ void tst_QNumeric::generalNaN()
|
||||
template<typename F>
|
||||
void tst_QNumeric::infinity()
|
||||
{
|
||||
const auto cleanup = qScopeGuard([]() { clearFpExceptions(); });
|
||||
const F inf = qInf();
|
||||
const F zero(0), one(1), two(2);
|
||||
QVERIFY(inf > zero);
|
||||
@ -320,6 +332,7 @@ void tst_QNumeric::infinity()
|
||||
QCOMPARE(one / -inf, zero);
|
||||
QVERIFY(qIsNaN(zero * inf));
|
||||
QVERIFY(qIsNaN(zero * -inf));
|
||||
QCOMPARE(log(zero), -inf);
|
||||
}
|
||||
|
||||
template<typename F>
|
||||
|
@ -90,7 +90,6 @@ private slots:
|
||||
void long_long_conversion_data();
|
||||
void long_long_conversion();
|
||||
void long_long_conversion_extra();
|
||||
void testInfAndNan();
|
||||
void fpExceptions();
|
||||
void negativeZero_data();
|
||||
void negativeZero();
|
||||
@ -1409,29 +1408,6 @@ void tst_QLocale::long_long_conversion_extra()
|
||||
QCOMPARE(l.toString((qulonglong)12345), QString("12,345"));
|
||||
}
|
||||
|
||||
void tst_QLocale::testInfAndNan()
|
||||
{
|
||||
double neginf = log(0.0);
|
||||
double nan = sqrt(-1.0);
|
||||
|
||||
#ifdef Q_OS_WIN
|
||||
// these cause INVALID floating point exception so we want to clear the status.
|
||||
_clear87();
|
||||
#endif
|
||||
|
||||
QVERIFY(qIsInf(-neginf));
|
||||
QVERIFY(!qIsNaN(-neginf));
|
||||
QVERIFY(!qIsFinite(-neginf));
|
||||
|
||||
QVERIFY(!qIsInf(nan));
|
||||
QVERIFY(qIsNaN(nan));
|
||||
QVERIFY(!qIsFinite(nan));
|
||||
|
||||
QVERIFY(!qIsInf(1.234));
|
||||
QVERIFY(!qIsNaN(1.234));
|
||||
QVERIFY(qIsFinite(1.234));
|
||||
}
|
||||
|
||||
void tst_QLocale::fpExceptions()
|
||||
{
|
||||
// Check that double-to-string conversion doesn't throw floating point
|
||||
|
Loading…
Reference in New Issue
Block a user