Use Linux 5.19 in build-many-glibcs.py
[glibc.git] / math / libm-test-support.h
blob47fd50a3be150dfe8c1a6f091a2ec1528ef021bc
1 /* Support code for testing libm functions (common declarations).
2 Copyright (C) 1997-2022 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 #ifndef LIBM_TEST_SUPPORT_H
20 #define LIBM_TEST_SUPPORT_H 1
22 #include <complex.h>
23 #include <math.h>
24 #include <float.h>
25 #include <fenv.h>
26 #include <limits.h>
28 #include <stdlib.h>
29 #include <stdint.h>
30 #include <stdio.h>
31 #include <tininess.h>
32 #include <math-tests.h>
33 #include <nan-high-order-bit.h>
35 extern const int flag_test_errno;
36 extern const int flag_test_exceptions;
37 extern const int flag_test_mathvec;
38 extern const int snan_tests_arg;
39 extern const char test_msg[];
40 extern const char qtype_str[];
41 extern const char doc[];
43 /* Possible exceptions */
44 #define NO_EXCEPTION 0x0
45 #define INVALID_EXCEPTION 0x1
46 #define DIVIDE_BY_ZERO_EXCEPTION 0x2
47 #define OVERFLOW_EXCEPTION 0x4
48 #define UNDERFLOW_EXCEPTION 0x8
49 #define INEXACT_EXCEPTION 0x10
50 /* The next flags signals that those exceptions are allowed but not required. */
51 #define INVALID_EXCEPTION_OK 0x20
52 #define DIVIDE_BY_ZERO_EXCEPTION_OK 0x40
53 #define OVERFLOW_EXCEPTION_OK 0x80
54 #define UNDERFLOW_EXCEPTION_OK 0x100
55 /* For "inexact" exceptions, the default is allowed but not required
56 unless INEXACT_EXCEPTION or NO_INEXACT_EXCEPTION is specified. */
57 #define NO_INEXACT_EXCEPTION 0x200
58 /* Some special test flags, passed together with exceptions. */
59 #define IGNORE_ZERO_INF_SIGN 0x400
60 #define TEST_NAN_SIGN 0x800
61 #define TEST_NAN_PAYLOAD 0x1000
62 #define XFAIL_TEST 0x4000
63 /* Indicate errno settings required or disallowed. */
64 #define ERRNO_UNCHANGED 0x8000
65 #define ERRNO_EDOM 0x10000
66 #define ERRNO_ERANGE 0x20000
67 /* Flags generated by gen-libm-test.py, not entered here manually. */
68 #define IGNORE_RESULT 0x40000
69 #define TEST_SNAN 0x100000
70 #define NO_TEST_MATHVEC 0x200000
72 #define __CONCATX(a,b) __CONCAT(a,b)
74 #define TYPE_MIN __CONCATX (PREFIX, _MIN)
75 #define TYPE_TRUE_MIN __CONCATX (PREFIX, _TRUE_MIN)
76 #define TYPE_MAX __CONCATX (PREFIX, _MAX)
77 #define MIN_EXP __CONCATX (PREFIX, _MIN_EXP)
78 #define MAX_EXP __CONCATX (PREFIX, _MAX_EXP)
79 #define MANT_DIG __CONCATX (PREFIX, _MANT_DIG)
81 #define ARG_TYPE_MIN __CONCATX (ARG_PREFIX, _MIN)
82 #define ARG_TYPE_TRUE_MIN __CONCATX (ARG_PREFIX, _TRUE_MIN)
83 #define ARG_TYPE_MAX __CONCATX (ARG_PREFIX, _MAX)
84 #define ARG_MIN_EXP __CONCATX (ARG_PREFIX, _MIN_EXP)
85 #define ARG_MAX_EXP __CONCATX (ARG_PREFIX, _MAX_EXP)
86 #define ARG_MANT_DIG __CONCATX (ARG_PREFIX, _MANT_DIG)
88 /* Format specific test macros. */
89 #define TEST_COND_binary32 (MANT_DIG == 24 \
90 && MIN_EXP == -125 \
91 && MAX_EXP == 128)
93 #define TEST_COND_binary64 (MANT_DIG == 53 \
94 && MIN_EXP == -1021 \
95 && MAX_EXP == 1024)
97 #define TEST_COND_binary128 (MANT_DIG == 113 \
98 && MIN_EXP == -16381 \
99 && MAX_EXP == 16384)
101 #define TEST_COND_ibm128 (MANT_DIG == 106)
103 #define TEST_COND_arg_ibm128 (ARG_MANT_DIG == 106)
105 #define TEST_COND_intel96 (MANT_DIG == 64 \
106 && MIN_EXP == -16381 \
107 && MAX_EXP == 16384)
109 #define TEST_COND_m68k96 (MANT_DIG == 64 \
110 && MIN_EXP == -16382 \
111 && MAX_EXP == 16384)
113 /* The condition ibm128-libgcc is used instead of ibm128 to mark tests
114 where in principle the glibc code is OK but the tests fail because
115 of limitations of the libgcc support for that format (e.g. GCC bug
116 59666, in non-default rounding modes). */
117 #ifdef ARG_FLOAT
118 # define TEST_COND_ibm128_libgcc (TEST_COND_ibm128 || TEST_COND_arg_ibm128)
119 #else
120 # define TEST_COND_ibm128_libgcc TEST_COND_ibm128
121 #endif
123 /* Mark a test as expected to fail for ibm128-libgcc. This is used
124 via XFAIL_ROUNDING_IBM128_LIBGCC, which gen-libm-test.py transforms
125 appropriately for each rounding mode. */
126 #define XFAIL_IBM128_LIBGCC (TEST_COND_ibm128_libgcc ? XFAIL_TEST : 0)
128 /* On some architectures, glibc can be built with compilers that do
129 not have suitable built-in functions for setting the payload of a
130 _Float128 NaN. */
131 #if ((defined __x86_64__ || defined __i386__ || defined __ia64__) \
132 && !__GNUC_PREREQ (7, 0))
133 # define XFAIL_FLOAT128_PAYLOAD (TEST_COND_binary128 ? XFAIL_TEST : 0)
134 #else
135 # define XFAIL_FLOAT128_PAYLOAD 0
136 #endif
138 /* Number of bits in NaN payload. */
139 #if TEST_COND_ibm128
140 # define PAYLOAD_DIG (DBL_MANT_DIG - 2)
141 #else
142 # define PAYLOAD_DIG (MANT_DIG - 2)
143 #endif
145 /* For narrowing functions, whether the argument format can represent
146 all the given argument values. */
147 #define TEST_COND_arg_fmt(MAX_EXP, NUM_ONES, MIN_EXP, MAX_PREC) \
148 (((MAX_EXP) < ARG_MAX_EXP) \
149 && (!TEST_COND_arg_ibm128 \
150 || (MAX_EXP) < ARG_MAX_EXP - 1 \
151 || (NUM_ONES) <= 53) \
152 && (MIN_EXP) >= ARG_MIN_EXP - ARG_MANT_DIG \
153 && (MAX_PREC) <= ARG_MANT_DIG)
155 /* Values underflowing on architectures detecting tininess before
156 rounding, but not on those detecting tininess after rounding. */
157 #define UNDERFLOW_EXCEPTION_BEFORE_ROUNDING (TININESS_AFTER_ROUNDING \
158 ? 0 \
159 : UNDERFLOW_EXCEPTION)
161 #if LONG_MAX == 0x7fffffff
162 # define TEST_COND_long32 1
163 # define TEST_COND_long64 0
164 #else
165 # define TEST_COND_long32 0
166 # define TEST_COND_long64 1
167 #endif
168 #define TEST_COND_before_rounding (!TININESS_AFTER_ROUNDING)
169 #define TEST_COND_after_rounding TININESS_AFTER_ROUNDING
171 int enable_test (int);
172 void init_max_error (const char *, int, int);
173 void print_max_error (const char *);
174 void print_complex_max_error (const char *);
175 void check_float (const char *, FLOAT, FLOAT, int);
176 void check_complex (const char *, CFLOAT, CFLOAT, int);
177 void check_int (const char *, int, int, int);
178 void check_long (const char *, long int, long int, int);
179 void check_bool (const char *, int, int, int);
180 void check_longlong (const char *, long long int, long long int, int);
181 void check_intmax_t (const char *, intmax_t, intmax_t, int);
182 void check_uintmax_t (const char *, uintmax_t, uintmax_t, int);
183 void libm_test_init (int, char **);
184 int libm_test_finish (void);
186 #endif /* LIBM_TEST_SUPPORT_H. */