]> git.ipfire.org Git - thirdparty/glibc.git/blob - math/libm-test-support.h
Build most libm-test support code once per type.
[thirdparty/glibc.git] / math / libm-test-support.h
1 /* Support code for testing libm functions (common declarations).
2 Copyright (C) 1997-2017 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
4
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.
9
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.
14
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/>. */
18
19 #ifndef LIBM_TEST_SUPPORT_H
20 #define LIBM_TEST_SUPPORT_H 1
21
22 #include <complex.h>
23 #include <math.h>
24 #include <float.h>
25 #include <fenv.h>
26 #include <limits.h>
27
28 #include <stdlib.h>
29 #include <stdint.h>
30 #include <stdio.h>
31 #include <tininess.h>
32 #include <math-tests.h>
33 #include <math-tests-arch.h>
34 #include <nan-high-order-bit.h>
35
36 extern const int flag_test_errno;
37 extern const int flag_test_exceptions;
38 extern const int flag_test_finite;
39 extern const int flag_test_inline;
40 extern const int flag_test_mathvec;
41 extern const char test_msg[];
42 extern const char qtype_str[];
43 extern const char doc[];
44
45 /* Possible exceptions */
46 #define NO_EXCEPTION 0x0
47 #define INVALID_EXCEPTION 0x1
48 #define DIVIDE_BY_ZERO_EXCEPTION 0x2
49 #define OVERFLOW_EXCEPTION 0x4
50 #define UNDERFLOW_EXCEPTION 0x8
51 #define INEXACT_EXCEPTION 0x10
52 /* The next flags signals that those exceptions are allowed but not required. */
53 #define INVALID_EXCEPTION_OK 0x20
54 #define DIVIDE_BY_ZERO_EXCEPTION_OK 0x40
55 #define OVERFLOW_EXCEPTION_OK 0x80
56 #define UNDERFLOW_EXCEPTION_OK 0x100
57 /* For "inexact" exceptions, the default is allowed but not required
58 unless INEXACT_EXCEPTION or NO_INEXACT_EXCEPTION is specified. */
59 #define NO_INEXACT_EXCEPTION 0x200
60 #define EXCEPTIONS_OK INVALID_EXCEPTION_OK+DIVIDE_BY_ZERO_EXCEPTION_OK
61 /* Some special test flags, passed together with exceptions. */
62 #define IGNORE_ZERO_INF_SIGN 0x400
63 #define TEST_NAN_SIGN 0x800
64 #define TEST_NAN_PAYLOAD 0x1000
65 #define NO_TEST_INLINE 0x2000
66 #define XFAIL_TEST 0x4000
67 /* Indicate errno settings required or disallowed. */
68 #define ERRNO_UNCHANGED 0x8000
69 #define ERRNO_EDOM 0x10000
70 #define ERRNO_ERANGE 0x20000
71 /* Flags generated by gen-libm-test.pl, not entered here manually. */
72 #define IGNORE_RESULT 0x40000
73 #define NON_FINITE 0x80000
74 #define TEST_SNAN 0x100000
75 #define NO_TEST_MATHVEC 0x200000
76
77 #define __CONCATX(a,b) __CONCAT(a,b)
78
79 #define TYPE_MIN __CONCATX (PREFIX, _MIN)
80 #define TYPE_TRUE_MIN __CONCATX (PREFIX, _TRUE_MIN)
81 #define TYPE_MAX __CONCATX (PREFIX, _MAX)
82 #define MIN_EXP __CONCATX (PREFIX, _MIN_EXP)
83 #define MAX_EXP __CONCATX (PREFIX, _MAX_EXP)
84 #define MANT_DIG __CONCATX (PREFIX, _MANT_DIG)
85
86 /* Format specific test macros. */
87 #define TEST_COND_binary32 (MANT_DIG == 24 \
88 && MIN_EXP == -125 \
89 && MAX_EXP == 128)
90
91 #define TEST_COND_binary64 (MANT_DIG == 53 \
92 && MIN_EXP == -1021 \
93 && MAX_EXP == 1024)
94
95 #define TEST_COND_binary128 (MANT_DIG == 113 \
96 && MIN_EXP == -16381 \
97 && MAX_EXP == 16384)
98
99 #define TEST_COND_ibm128 (MANT_DIG == 106)
100
101 #define TEST_COND_intel96 (MANT_DIG == 64 \
102 && MIN_EXP == -16381 \
103 && MAX_EXP == 16384)
104
105 #define TEST_COND_m68k96 (MANT_DIG == 64 \
106 && MIN_EXP == -16382 \
107 && MAX_EXP == 16384)
108
109 /* The condition ibm128-libgcc is used instead of ibm128 to mark tests
110 where in principle the glibc code is OK but the tests fail because
111 of limitations of the libgcc support for that format (e.g. GCC bug
112 59666, in non-default rounding modes). */
113 #define TEST_COND_ibm128_libgcc TEST_COND_ibm128
114
115 /* Mark a test as expected to fail for ibm128-libgcc. This is used
116 via XFAIL_ROUNDING_IBM128_LIBGCC, which gen-libm-test.pl transforms
117 appropriately for each rounding mode. */
118 #define XFAIL_IBM128_LIBGCC (TEST_COND_ibm128_libgcc ? XFAIL_TEST : 0)
119
120 /* Number of bits in NaN payload. */
121 #if TEST_COND_ibm128
122 # define PAYLOAD_DIG (DBL_MANT_DIG - 2)
123 #else
124 # define PAYLOAD_DIG (MANT_DIG - 2)
125 #endif
126
127 /* Values underflowing only for float. */
128 #if TEST_COND_binary32
129 # define UNDERFLOW_EXCEPTION_FLOAT UNDERFLOW_EXCEPTION
130 # define UNDERFLOW_EXCEPTION_OK_FLOAT UNDERFLOW_EXCEPTION_OK
131 #else
132 # define UNDERFLOW_EXCEPTION_FLOAT 0
133 # define UNDERFLOW_EXCEPTION_OK_FLOAT 0
134 #endif
135
136 /* Values underflowing only for double or types with a larger least
137 positive normal value. */
138 #if TEST_COND_binary32 || TEST_COND_binary64 || TEST_COND_ibm128
139 # define UNDERFLOW_EXCEPTION_DOUBLE UNDERFLOW_EXCEPTION
140 # define UNDERFLOW_EXCEPTION_OK_DOUBLE UNDERFLOW_EXCEPTION_OK
141 #else
142 # define UNDERFLOW_EXCEPTION_DOUBLE 0
143 # define UNDERFLOW_EXCEPTION_OK_DOUBLE 0
144 #endif
145
146 /* Values underflowing only for IBM long double or types with a larger least
147 positive normal value. */
148 #if TEST_COND_binary32 || TEST_COND_ibm128
149 # define UNDERFLOW_EXCEPTION_LDOUBLE_IBM UNDERFLOW_EXCEPTION
150 #else
151 # define UNDERFLOW_EXCEPTION_LDOUBLE_IBM 0
152 #endif
153
154 /* Values underflowing on architectures detecting tininess before
155 rounding, but not on those detecting tininess after rounding. */
156 #define UNDERFLOW_EXCEPTION_BEFORE_ROUNDING (TININESS_AFTER_ROUNDING \
157 ? 0 \
158 : UNDERFLOW_EXCEPTION)
159
160 #if LONG_MAX == 0x7fffffff
161 # define TEST_COND_long32 1
162 # define TEST_COND_long64 0
163 #else
164 # define TEST_COND_long32 0
165 # define TEST_COND_long64 1
166 #endif
167 #define TEST_COND_before_rounding (!TININESS_AFTER_ROUNDING)
168 #define TEST_COND_after_rounding TININESS_AFTER_ROUNDING
169
170 int enable_test (int);
171 void init_max_error (const char *, int);
172 void print_max_error (const char *);
173 void print_complex_max_error (const char *);
174 void check_float (const char *, FLOAT, FLOAT, int);
175 void check_complex (const char *, __complex__ FLOAT, __complex__ FLOAT, int);
176 void check_int (const char *, int, int, int);
177 void check_long (const char *, long int, long int, int);
178 void check_bool (const char *, int, int, int);
179 void check_longlong (const char *, long long int, long long int, int);
180 void check_intmax_t (const char *, intmax_t, intmax_t, int);
181 void check_uintmax_t (const char *, uintmax_t, uintmax_t, int);
182 void libm_test_init (int, char **);
183 int libm_test_finish (void);
184
185 #endif /* LIBM_TEST_SUPPORT_H. */