test-tgmath-ret.c 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. /* Test compilation of tgmath macros.
  2. Copyright (C) 2003-2019 Free Software Foundation, Inc.
  3. This file is part of the GNU C Library.
  4. Contributed by Andreas Jaeger <aj@suse.de>, 2003.
  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. The GNU C Library is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  12. Lesser General Public License for more details.
  13. You should have received a copy of the GNU Lesser General Public
  14. License along with the GNU C Library; if not, see
  15. <http://www.gnu.org/licenses/>. */
  16. #include <math.h>
  17. #include <complex.h>
  18. #include <tgmath.h>
  19. #include <stdint.h>
  20. #include <stdio.h>
  21. static float fx;
  22. static double dx;
  23. static long double lx;
  24. static int rm = FP_INT_UPWARD;
  25. static unsigned int width = 64;
  26. static int errors = 0;
  27. static void
  28. our_error (const char *c)
  29. {
  30. puts (c);
  31. ++errors;
  32. }
  33. /* First function where the return type is constant. */
  34. #define CHECK_RET_CONST_TYPE(func, rettype, arg, name, ...) \
  35. if (sizeof (func (arg, ## __VA_ARGS__)) != sizeof (rettype)) \
  36. our_error ("Return size of " #func " is wrong with " #name " argument");
  37. #define CHECK_RET_CONST_FLOAT(func, rettype, ...) \
  38. CHECK_RET_CONST_TYPE (func, rettype, fx, float, ## __VA_ARGS__)
  39. #define CHECK_RET_CONST_DOUBLE(func, rettype, ...) \
  40. CHECK_RET_CONST_TYPE (func, rettype, dx, double, ## __VA_ARGS__)
  41. #define CHECK_RET_CONST_LDOUBLE(func, rettype, ...) \
  42. CHECK_RET_CONST_TYPE (func, rettype, lx, long double, ## __VA_ARGS__)
  43. #define CHECK_RET_CONST(func, rettype, ...) \
  44. static void \
  45. check_return_ ##func (void) \
  46. { \
  47. CHECK_RET_CONST_FLOAT (func, rettype, ## __VA_ARGS__) \
  48. CHECK_RET_CONST_DOUBLE (func, rettype, ## __VA_ARGS__) \
  49. CHECK_RET_CONST_LDOUBLE (func, rettype, ## __VA_ARGS__) \
  50. }
  51. CHECK_RET_CONST(ilogb, int)
  52. CHECK_RET_CONST(llogb, long)
  53. CHECK_RET_CONST(lrint, long)
  54. CHECK_RET_CONST(lround, long)
  55. CHECK_RET_CONST(llrint, long long)
  56. CHECK_RET_CONST(llround, long long)
  57. CHECK_RET_CONST(fromfp, intmax_t, rm, width)
  58. CHECK_RET_CONST(ufromfp, uintmax_t, rm, width)
  59. CHECK_RET_CONST(fromfpx, intmax_t, rm, width)
  60. CHECK_RET_CONST(ufromfpx, uintmax_t, rm, width)
  61. static int
  62. do_test (void)
  63. {
  64. check_return_ilogb ();
  65. check_return_llogb ();
  66. check_return_lrint ();
  67. check_return_lround ();
  68. check_return_llrint ();
  69. check_return_llround ();
  70. check_return_fromfp ();
  71. check_return_ufromfp ();
  72. check_return_fromfpx ();
  73. check_return_ufromfpx ();
  74. printf ("%Zd\n", sizeof(carg (lx)));
  75. return errors != 0;
  76. }
  77. #define TEST_FUNCTION do_test ()
  78. #include "../test-skeleton.c"