|
Packit |
6c4009 |
/* Test fesetenv (FE_DFL_ENV) and fesetenv (FE_NOMASK_ENV) clear
|
|
Packit |
6c4009 |
exceptions (bug 19181).
|
|
Packit |
6c4009 |
Copyright (C) 2015-2018 Free Software Foundation, Inc.
|
|
Packit |
6c4009 |
This file is part of the GNU C Library.
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
The GNU C Library is free software; you can redistribute it and/or
|
|
Packit |
6c4009 |
modify it under the terms of the GNU Lesser General Public
|
|
Packit |
6c4009 |
License as published by the Free Software Foundation; either
|
|
Packit |
6c4009 |
version 2.1 of the License, or (at your option) any later version.
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
The GNU C Library is distributed in the hope that it will be useful,
|
|
Packit |
6c4009 |
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
Packit |
6c4009 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
Packit |
6c4009 |
Lesser General Public License for more details.
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
You should have received a copy of the GNU Lesser General Public
|
|
Packit |
6c4009 |
License along with the GNU C Library; if not, see
|
|
Packit |
6c4009 |
<http://www.gnu.org/licenses/>. */
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
#include <fenv.h>
|
|
Packit |
6c4009 |
#include <float.h>
|
|
Packit |
6c4009 |
#include <stdio.h>
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
volatile float fa = 1.0f, fb = 0.0f, fc = FLT_MAX, fr;
|
|
Packit |
6c4009 |
volatile long double lda = 1.0L, ldb = 0.0L, ldc = LDBL_MAX, ldr;
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
static void
|
|
Packit |
6c4009 |
raise_exceptions (void)
|
|
Packit |
6c4009 |
{
|
|
Packit |
6c4009 |
/* Raise exceptions both with feraiseexcept and arithmetic to allow
|
|
Packit |
6c4009 |
for case of multiple floating-point units with separate
|
|
Packit |
6c4009 |
exceptions state. */
|
|
Packit |
6c4009 |
feraiseexcept (FE_ALL_EXCEPT);
|
|
Packit |
6c4009 |
fr = fb / fb;
|
|
Packit |
6c4009 |
fr = fa / fb;
|
|
Packit |
6c4009 |
fr = fc * fc;
|
|
Packit |
6c4009 |
fr = fa / fc / fc;
|
|
Packit |
6c4009 |
ldr = ldb / ldb;
|
|
Packit |
6c4009 |
ldr = lda / ldb;
|
|
Packit |
6c4009 |
ldr = ldc * ldc;
|
|
Packit |
6c4009 |
ldr = lda / ldc / ldc;
|
|
Packit |
6c4009 |
}
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
static __attribute__ ((noinline)) int
|
|
Packit |
6c4009 |
run_tests (void)
|
|
Packit |
6c4009 |
{
|
|
Packit |
6c4009 |
int result = 0;
|
|
Packit |
6c4009 |
raise_exceptions ();
|
|
Packit |
6c4009 |
if (fesetenv (FE_DFL_ENV) == 0)
|
|
Packit |
6c4009 |
{
|
|
Packit |
6c4009 |
puts ("PASS: fesetenv (FE_DFL_ENV)");
|
|
Packit |
6c4009 |
if (fetestexcept (FE_ALL_EXCEPT) == 0)
|
|
Packit |
6c4009 |
puts ("PASS: fesetenv (FE_DFL_ENV) clearing exceptions");
|
|
Packit |
6c4009 |
else
|
|
Packit |
6c4009 |
{
|
|
Packit |
6c4009 |
puts ("FAIL: fesetenv (FE_DFL_ENV) clearing exceptions");
|
|
Packit |
6c4009 |
result = 1;
|
|
Packit |
6c4009 |
}
|
|
Packit |
6c4009 |
}
|
|
Packit |
6c4009 |
else
|
|
Packit |
6c4009 |
{
|
|
Packit |
6c4009 |
puts ("FAIL: fesetenv (FE_DFL_ENV)");
|
|
Packit |
6c4009 |
result = 1;
|
|
Packit |
6c4009 |
}
|
|
Packit |
6c4009 |
#ifdef FE_NOMASK_ENV
|
|
Packit |
6c4009 |
raise_exceptions ();
|
|
Packit |
6c4009 |
if (fesetenv (FE_NOMASK_ENV) == 0)
|
|
Packit |
6c4009 |
{
|
|
Packit |
6c4009 |
if (fetestexcept (FE_ALL_EXCEPT) == 0)
|
|
Packit |
6c4009 |
puts ("PASS: fesetenv (FE_NOMASK_ENV) clearing exceptions");
|
|
Packit |
6c4009 |
else
|
|
Packit |
6c4009 |
{
|
|
Packit |
6c4009 |
puts ("FAIL: fesetenv (FE_NOMASK_ENV) clearing exceptions");
|
|
Packit |
6c4009 |
result = 1;
|
|
Packit |
6c4009 |
}
|
|
Packit |
6c4009 |
}
|
|
Packit |
6c4009 |
else
|
|
Packit |
6c4009 |
puts ("fesetenv (FE_NOMASK_ENV) failed, cannot test");
|
|
Packit |
6c4009 |
#endif
|
|
Packit |
6c4009 |
return result;
|
|
Packit |
6c4009 |
}
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
static int
|
|
Packit |
6c4009 |
do_test (void)
|
|
Packit |
6c4009 |
{
|
|
Packit |
6c4009 |
CHECK_CAN_TEST;
|
|
Packit |
6c4009 |
return run_tests ();
|
|
Packit |
6c4009 |
}
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
#define TEST_FUNCTION do_test ()
|
|
Packit |
6c4009 |
#include "../test-skeleton.c"
|