powerpc: Update AT_HWCAP2 bits
[glibc.git] / math / test-fetestexceptflag.c
bloba81b503c5141b7a9e942bd8251cc009fabb816fe
1 /* Test fetestexceptflag.
2 Copyright (C) 2016-2017 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
5 The GNU C Library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
10 The GNU C Library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
15 You should have received a copy of the GNU Lesser General Public
16 License along with the GNU C Library; if not, see
17 <http://www.gnu.org/licenses/>. */
19 #include <fenv.h>
20 #include <stdio.h>
21 #include <math-tests.h>
23 static int
24 test_one (int exc_test, int exc_set, int exc_save)
26 int result = 0;
28 printf ("Individual test: %x %x %x\n", (unsigned int) exc_test,
29 (unsigned int) exc_set, (unsigned int) exc_save);
31 feclearexcept (FE_ALL_EXCEPT);
32 int ret = fesetexcept (exc_set);
33 if (ret != 0)
35 puts ("fesetexcept failed");
36 if (exc_set == 0 || EXCEPTION_TESTS (float))
38 puts ("failure of fesetexcept was unexpected");
39 result = 1;
41 else
42 puts ("failure of fesetexcept OK, skipping further tests");
43 return result;
45 fexcept_t saved;
46 ret = fegetexceptflag (&saved, exc_save);
47 if (ret == 0)
48 puts ("fegetexceptflag succeeded");
49 else
51 puts ("fegetexceptflag failed");
52 result = 1;
53 return result;
55 ret = fetestexceptflag (&saved, exc_test);
56 if (ret == (exc_set & exc_test))
57 puts ("fetestexceptflag result correct");
58 else
60 printf ("fetestexceptflag returned %x, expected %x\n", ret,
61 exc_set & exc_test);
62 result = 1;
64 if (exc_save == FE_ALL_EXCEPT)
66 /* Also test fetestexceptflag testing all exceptions but
67 possibly with only some set. */
68 ret = fetestexceptflag (&saved, FE_ALL_EXCEPT);
69 if (ret == exc_set)
70 puts ("fetestexceptflag (FE_ALL_EXCEPT) result correct");
71 else
73 printf ("fetestexceptflag (FE_ALL_EXCEPT) returned %x, expected %x\n",
74 ret, exc_set);
75 result = 1;
78 return result;
81 static int
82 test_fetestexceptflag (int exc, const char *exc_name)
84 int result = 0;
86 printf ("Testing %s\n", exc_name);
88 /* Test each case of: whether this exception is set or clear;
89 whether other exceptions are set or clear; whether the whole
90 state is saved or just the state for this exception. */
91 result |= test_one (exc, 0, exc);
92 result |= test_one (exc, 0, FE_ALL_EXCEPT);
93 result |= test_one (exc, exc, exc);
94 result |= test_one (exc, exc, FE_ALL_EXCEPT);
95 result |= test_one (exc, FE_ALL_EXCEPT & ~exc, exc);
96 result |= test_one (exc, FE_ALL_EXCEPT & ~exc, FE_ALL_EXCEPT);
97 result |= test_one (exc, FE_ALL_EXCEPT, exc);
98 result |= test_one (exc, FE_ALL_EXCEPT, FE_ALL_EXCEPT);
100 return result;
103 static int
104 do_test (void)
106 int result = 0;
108 result |= test_fetestexceptflag (0, "0");
109 result |= test_fetestexceptflag (FE_ALL_EXCEPT, "FE_ALL_EXCEPT");
110 #ifdef FE_DIVBYZERO
111 result |= test_fetestexceptflag (FE_DIVBYZERO, "FE_DIVBYZERO");
112 #endif
113 #ifdef FE_INEXACT
114 result |= test_fetestexceptflag (FE_INEXACT, "FE_INEXACT");
115 #endif
116 #ifdef FE_INVALID
117 result |= test_fetestexceptflag (FE_INVALID, "FE_INVALID");
118 #endif
119 #ifdef FE_OVERFLOW
120 result |= test_fetestexceptflag (FE_OVERFLOW, "FE_OVERFLOW");
121 #endif
122 #ifdef FE_UNDERFLOW
123 result |= test_fetestexceptflag (FE_UNDERFLOW, "FE_UNDERFLOW");
124 #endif
126 return result;
129 #define TEST_FUNCTION do_test ()
130 #include "../test-skeleton.c"