linux: Decorate __libc_fatal error buffer
[glibc.git] / math / test-nearbyint-except-2.c
blobd926e0d5437ad4cecb15b801e82ff28c94a3c623
1 /* Test nearbyint functions do not disable exception traps (bug 19228).
2 Copyright (C) 2015-2023 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 <https://www.gnu.org/licenses/>. */
19 #include <fenv.h>
20 #include <math.h>
21 #include <stdio.h>
23 #ifndef FE_INEXACT
24 # define FE_INEXACT 0
25 #endif
27 #define TEST_FUNC(NAME, FLOAT, SUFFIX) \
28 static int \
29 NAME (void) \
30 { \
31 int result = 0; \
32 volatile FLOAT a, b __attribute__ ((unused)); \
33 a = 1.5; \
34 /* nearbyint must work when traps on "inexact" are enabled. */ \
35 b = nearbyint ## SUFFIX (a); \
36 /* And it must have left those traps enabled. */ \
37 if (fegetexcept () == FE_INEXACT) \
38 puts ("PASS: " #FLOAT); \
39 else \
40 { \
41 puts ("FAIL: " #FLOAT); \
42 result = 1; \
43 } \
44 return result; \
47 TEST_FUNC (float_test, float, f)
48 TEST_FUNC (double_test, double, )
49 TEST_FUNC (ldouble_test, long double, l)
51 static int
52 do_test (void)
54 if (feenableexcept (FE_INEXACT) == -1)
56 puts ("enabling FE_INEXACT traps failed, cannot test");
57 return 77;
59 int result = float_test ();
60 feenableexcept (FE_INEXACT);
61 result |= double_test ();
62 feenableexcept (FE_INEXACT);
63 result |= ldouble_test ();
64 return result;
67 #define TEST_FUNCTION do_test ()
68 #include "../test-skeleton.c"