libm-test-support.h 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190
  1. /* Support code for testing libm functions (common declarations).
  2. Copyright (C) 1997-2019 Free Software Foundation, Inc.
  3. This file is part of the GNU C Library.
  4. The GNU C Library is free software; you can redistribute it and/or
  5. modify it under the terms of the GNU Lesser General Public
  6. License as published by the Free Software Foundation; either
  7. version 2.1 of the License, or (at your option) any later version.
  8. The GNU C Library is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  11. Lesser General Public License for more details.
  12. You should have received a copy of the GNU Lesser General Public
  13. License along with the GNU C Library; if not, see
  14. <http://www.gnu.org/licenses/>. */
  15. #ifndef LIBM_TEST_SUPPORT_H
  16. #define LIBM_TEST_SUPPORT_H 1
  17. #include <complex.h>
  18. #include <math.h>
  19. #include <float.h>
  20. #include <fenv.h>
  21. #include <limits.h>
  22. #include <stdlib.h>
  23. #include <stdint.h>
  24. #include <stdio.h>
  25. #include <tininess.h>
  26. #include <math-tests.h>
  27. #include <nan-high-order-bit.h>
  28. extern const int flag_test_errno;
  29. extern const int flag_test_exceptions;
  30. extern const int flag_test_finite;
  31. extern const int flag_test_inline;
  32. extern const int flag_test_mathvec;
  33. extern const int snan_tests_arg;
  34. extern const char test_msg[];
  35. extern const char qtype_str[];
  36. extern const char doc[];
  37. /* Possible exceptions */
  38. #define NO_EXCEPTION 0x0
  39. #define INVALID_EXCEPTION 0x1
  40. #define DIVIDE_BY_ZERO_EXCEPTION 0x2
  41. #define OVERFLOW_EXCEPTION 0x4
  42. #define UNDERFLOW_EXCEPTION 0x8
  43. #define INEXACT_EXCEPTION 0x10
  44. /* The next flags signals that those exceptions are allowed but not required. */
  45. #define INVALID_EXCEPTION_OK 0x20
  46. #define DIVIDE_BY_ZERO_EXCEPTION_OK 0x40
  47. #define OVERFLOW_EXCEPTION_OK 0x80
  48. #define UNDERFLOW_EXCEPTION_OK 0x100
  49. /* For "inexact" exceptions, the default is allowed but not required
  50. unless INEXACT_EXCEPTION or NO_INEXACT_EXCEPTION is specified. */
  51. #define NO_INEXACT_EXCEPTION 0x200
  52. /* Some special test flags, passed together with exceptions. */
  53. #define IGNORE_ZERO_INF_SIGN 0x400
  54. #define TEST_NAN_SIGN 0x800
  55. #define TEST_NAN_PAYLOAD 0x1000
  56. #define NO_TEST_INLINE 0x2000
  57. #define XFAIL_TEST 0x4000
  58. /* Indicate errno settings required or disallowed. */
  59. #define ERRNO_UNCHANGED 0x8000
  60. #define ERRNO_EDOM 0x10000
  61. #define ERRNO_ERANGE 0x20000
  62. /* Flags generated by gen-libm-test.py, not entered here manually. */
  63. #define IGNORE_RESULT 0x40000
  64. #define NON_FINITE 0x80000
  65. #define TEST_SNAN 0x100000
  66. #define NO_TEST_MATHVEC 0x200000
  67. #define __CONCATX(a,b) __CONCAT(a,b)
  68. #define TYPE_MIN __CONCATX (PREFIX, _MIN)
  69. #define TYPE_TRUE_MIN __CONCATX (PREFIX, _TRUE_MIN)
  70. #define TYPE_MAX __CONCATX (PREFIX, _MAX)
  71. #define MIN_EXP __CONCATX (PREFIX, _MIN_EXP)
  72. #define MAX_EXP __CONCATX (PREFIX, _MAX_EXP)
  73. #define MANT_DIG __CONCATX (PREFIX, _MANT_DIG)
  74. #define ARG_TYPE_MIN __CONCATX (ARG_PREFIX, _MIN)
  75. #define ARG_TYPE_TRUE_MIN __CONCATX (ARG_PREFIX, _TRUE_MIN)
  76. #define ARG_TYPE_MAX __CONCATX (ARG_PREFIX, _MAX)
  77. #define ARG_MIN_EXP __CONCATX (ARG_PREFIX, _MIN_EXP)
  78. #define ARG_MAX_EXP __CONCATX (ARG_PREFIX, _MAX_EXP)
  79. #define ARG_MANT_DIG __CONCATX (ARG_PREFIX, _MANT_DIG)
  80. /* Format specific test macros. */
  81. #define TEST_COND_binary32 (MANT_DIG == 24 \
  82. && MIN_EXP == -125 \
  83. && MAX_EXP == 128)
  84. #define TEST_COND_binary64 (MANT_DIG == 53 \
  85. && MIN_EXP == -1021 \
  86. && MAX_EXP == 1024)
  87. #define TEST_COND_binary128 (MANT_DIG == 113 \
  88. && MIN_EXP == -16381 \
  89. && MAX_EXP == 16384)
  90. #define TEST_COND_ibm128 (MANT_DIG == 106)
  91. #define TEST_COND_arg_ibm128 (ARG_MANT_DIG == 106)
  92. #define TEST_COND_intel96 (MANT_DIG == 64 \
  93. && MIN_EXP == -16381 \
  94. && MAX_EXP == 16384)
  95. #define TEST_COND_m68k96 (MANT_DIG == 64 \
  96. && MIN_EXP == -16382 \
  97. && MAX_EXP == 16384)
  98. /* The condition ibm128-libgcc is used instead of ibm128 to mark tests
  99. where in principle the glibc code is OK but the tests fail because
  100. of limitations of the libgcc support for that format (e.g. GCC bug
  101. 59666, in non-default rounding modes). */
  102. #ifdef ARG_FLOAT
  103. # define TEST_COND_ibm128_libgcc (TEST_COND_ibm128 || TEST_COND_arg_ibm128)
  104. #else
  105. # define TEST_COND_ibm128_libgcc TEST_COND_ibm128
  106. #endif
  107. /* Mark a test as expected to fail for ibm128-libgcc. This is used
  108. via XFAIL_ROUNDING_IBM128_LIBGCC, which gen-libm-test.py transforms
  109. appropriately for each rounding mode. */
  110. #define XFAIL_IBM128_LIBGCC (TEST_COND_ibm128_libgcc ? XFAIL_TEST : 0)
  111. /* On some architectures, glibc can be built with compilers that do
  112. not have suitable built-in functions for setting the payload of a
  113. _Float128 NaN. */
  114. #if ((defined __x86_64__ || defined __i386__ || defined __ia64__) \
  115. && !__GNUC_PREREQ (7, 0))
  116. # define XFAIL_FLOAT128_PAYLOAD (TEST_COND_binary128 ? XFAIL_TEST : 0)
  117. #else
  118. # define XFAIL_FLOAT128_PAYLOAD 0
  119. #endif
  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. /* For narrowing functions, whether the argument format can represent
  127. all the given argument values. */
  128. #define TEST_COND_arg_fmt(MAX_EXP, NUM_ONES, MIN_EXP, MAX_PREC) \
  129. (((MAX_EXP) < ARG_MAX_EXP) \
  130. && (!TEST_COND_arg_ibm128 \
  131. || (MAX_EXP) < ARG_MAX_EXP - 1 \
  132. || (NUM_ONES) <= 53) \
  133. && (MIN_EXP) >= ARG_MIN_EXP - ARG_MANT_DIG \
  134. && (MAX_PREC) <= ARG_MANT_DIG)
  135. /* Values underflowing on architectures detecting tininess before
  136. rounding, but not on those detecting tininess after rounding. */
  137. #define UNDERFLOW_EXCEPTION_BEFORE_ROUNDING (TININESS_AFTER_ROUNDING \
  138. ? 0 \
  139. : UNDERFLOW_EXCEPTION)
  140. #if LONG_MAX == 0x7fffffff
  141. # define TEST_COND_long32 1
  142. # define TEST_COND_long64 0
  143. #else
  144. # define TEST_COND_long32 0
  145. # define TEST_COND_long64 1
  146. #endif
  147. #define TEST_COND_before_rounding (!TININESS_AFTER_ROUNDING)
  148. #define TEST_COND_after_rounding TININESS_AFTER_ROUNDING
  149. int enable_test (int);
  150. void init_max_error (const char *, int, int);
  151. void print_max_error (const char *);
  152. void print_complex_max_error (const char *);
  153. void check_float (const char *, FLOAT, FLOAT, int);
  154. void check_complex (const char *, CFLOAT, CFLOAT, int);
  155. void check_int (const char *, int, int, int);
  156. void check_long (const char *, long int, long int, int);
  157. void check_bool (const char *, int, int, int);
  158. void check_longlong (const char *, long long int, long long int, int);
  159. void check_intmax_t (const char *, intmax_t, intmax_t, int);
  160. void check_uintmax_t (const char *, uintmax_t, uintmax_t, int);
  161. void libm_test_init (int, char **);
  162. int libm_test_finish (void);
  163. #endif /* LIBM_TEST_SUPPORT_H. */