test-nearbyint-except-2.c 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. /* Test nearbyint functions do not disable exception traps (bug 19228).
  2. Copyright (C) 2015-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. #include <fenv.h>
  16. #include <math.h>
  17. #include <stdio.h>
  18. #ifndef FE_INEXACT
  19. # define FE_INEXACT 0
  20. #endif
  21. #define TEST_FUNC(NAME, FLOAT, SUFFIX) \
  22. static int \
  23. NAME (void) \
  24. { \
  25. int result = 0; \
  26. volatile FLOAT a, b __attribute__ ((unused)); \
  27. a = 1.5; \
  28. /* nearbyint must work when traps on "inexact" are enabled. */ \
  29. b = nearbyint ## SUFFIX (a); \
  30. /* And it must have left those traps enabled. */ \
  31. if (fegetexcept () == FE_INEXACT) \
  32. puts ("PASS: " #FLOAT); \
  33. else \
  34. { \
  35. puts ("FAIL: " #FLOAT); \
  36. result = 1; \
  37. } \
  38. return result; \
  39. }
  40. TEST_FUNC (float_test, float, f)
  41. TEST_FUNC (double_test, double, )
  42. TEST_FUNC (ldouble_test, long double, l)
  43. static int
  44. do_test (void)
  45. {
  46. if (feenableexcept (FE_INEXACT) == -1)
  47. {
  48. puts ("enabling FE_INEXACT traps failed, cannot test");
  49. return 77;
  50. }
  51. int result = float_test ();
  52. feenableexcept (FE_INEXACT);
  53. result |= double_test ();
  54. feenableexcept (FE_INEXACT);
  55. result |= ldouble_test ();
  56. return result;
  57. }
  58. #define TEST_FUNCTION do_test ()
  59. #include "../test-skeleton.c"