Fix tests-printers handling for cross compiling.
[glibc.git] / math / test-nearbyint-except-2.c
blobcb4114916ba6e0d26082d364498773670cc8f9b8
1 /* Test nearbyint functions do not disable exception traps (bug 19228).
2 Copyright (C) 2015-2016 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 <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 #ifndef NO_LONG_DOUBLE
50 TEST_FUNC (ldouble_test, long double, l)
51 #endif
53 static int
54 do_test (void)
56 if (feenableexcept (FE_INEXACT) == -1)
58 puts ("enabling FE_INEXACT traps failed, cannot test");
59 return 77;
61 int result = float_test ();
62 feenableexcept (FE_INEXACT);
63 result |= double_test ();
64 #ifndef NO_LONG_DOUBLE
65 feenableexcept (FE_INEXACT);
66 result |= ldouble_test ();
67 #endif
68 return result;
71 #define TEST_FUNCTION do_test ()
72 #include "../test-skeleton.c"