1 /* Test that setjmp/longjmp do not save and restore floating-point
2 exceptions and rounding modes.
3 Copyright (C) 2013-2014 Free Software Foundation, Inc.
4 This file is part of the GNU C Library.
6 The GNU C Library is free software; you can redistribute it and/or
7 modify it under the terms of the GNU Lesser General Public
8 License as published by the Free Software Foundation; either
9 version 2.1 of the License, or (at your option) any later version.
11 The GNU C Library is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 Lesser General Public License for more details.
16 You should have received a copy of the GNU Lesser General Public
17 License along with the GNU C Library; if not, see
18 <http://www.gnu.org/licenses/>. */
26 static int result
= 0;
28 #if defined FE_TONEAREST && defined FE_TOWARDZERO
29 static int expected_rounding_mode
= FE_TONEAREST
;
32 change_rounding_mode (void)
34 if (fesetround (FE_TOWARDZERO
) == 0)
35 expected_rounding_mode
= FE_TOWARDZERO
;
37 puts ("fesetround (FE_TOWARDZERO) failed, continuing test");
43 static int expected_exceptions
= 0;
46 raise_exception (void)
48 if (feraiseexcept (FE_INVALID
) == 0)
49 expected_exceptions
= FE_INVALID
;
51 puts ("feraiseexcept (FE_INVALID) failed, continuing test");
59 #if defined FE_TONEAREST && defined FE_TOWARDZERO
60 if (fesetround (FE_TONEAREST
) == 0)
62 if (setjmp (env
) == 0)
63 change_rounding_mode ();
66 if (fegetround () == expected_rounding_mode
)
67 puts ("PASS: longjmp preserved rounding mode");
70 puts ("FAIL: longjmp changed rounding mode");
76 puts ("fesetround (FE_TONEAREST) failed, not testing rounding modes");
78 puts ("rounding mode test not supported");
81 if (feclearexcept (FE_ALL_EXCEPT
) == 0)
83 if (setjmp (env
) == 0)
87 if (fetestexcept (FE_INVALID
) == expected_exceptions
)
88 puts ("PASS: longjmp preserved exceptions");
91 puts ("FAIL: longjmp changed exceptions");
97 puts ("feclearexcept (FE_ALL_EXCEPT) failed, not testing exceptions");
99 puts ("exception test not supported");
104 #define TEST_FUNCTION do_test ()
105 #include "../test-skeleton.c"