Clean up and modernise tst_QLocale::fpExceptions()

Use the modern "portable" _clearfp() and _controlfp(), that work
regardless of the hardware MS is running on, rather than the
x86-specific _clear87() and _control87(); and move some defines into
the #if-ery context in which they're used, rather than defining them
regardless of whether they're used.

Change-Id: I13abf2c85525b1182b99bc2c366aadd6b5fc656f
Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
bb10
Edward Welbourne 2022-03-30 15:37:09 +02:00
parent 50a5ef9945
commit 67a563e5c5
1 changed files with 14 additions and 15 deletions

View File

@ -1,6 +1,6 @@
/****************************************************************************
**
** Copyright (C) 2021 The Qt Company Ltd.
** Copyright (C) 2022 The Qt Company Ltd.
** Contact: https://www.qt.io/licensing/
**
** This file is part of the test suite of the Qt Toolkit.
@ -1434,19 +1434,18 @@ void tst_QLocale::testInfAndNan()
void tst_QLocale::fpExceptions()
{
#ifndef _MCW_EM
#define _MCW_EM 0x0008001F
#endif
#ifndef _EM_INEXACT
#define _EM_INEXACT 0x00000001
#endif
// check that double-to-string conversion doesn't throw floating point exceptions when they are
// enabled
// Check that double-to-string conversion doesn't throw floating point
// exceptions when they are enabled.
#ifdef Q_OS_WIN
_clear87();
unsigned int oldbits = _control87(0, 0);
_control87( 0 | _EM_INEXACT, _MCW_EM );
# ifndef _MCW_EM
# define _MCW_EM 0x0008001F
# endif
# ifndef _EM_INEXACT
# define _EM_INEXACT 0x00000001
# endif
_clearfp();
unsigned int oldbits = _controlfp(0, 0);
_controlfp( 0 | _EM_INEXACT, _MCW_EM );
#endif
#ifdef QT_USE_FENV
@ -1463,8 +1462,8 @@ void tst_QLocale::fpExceptions()
QVERIFY(true);
#ifdef Q_OS_WIN
_clear87();
_control87(oldbits, 0xFFFFF);
_clearfp();
_controlfp(oldbits, 0xFFFFF);
#endif
#ifdef QT_USE_FENV