tst-tininess.c 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. /* Test that tininess.h is correct for this architecture.
  2. Copyright (C) 2012-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 <float.h>
  17. #include <stdio.h>
  18. #include <tininess.h>
  19. volatile float a = 0x1.fffp-126;
  20. volatile float b = 0x1.0008p-1;
  21. volatile float c;
  22. volatile float m = FLT_MIN;
  23. volatile float mm;
  24. static int
  25. do_test (void)
  26. {
  27. int result = 0;
  28. #ifdef FE_UNDERFLOW
  29. feclearexcept (FE_ALL_EXCEPT);
  30. mm = m * m;
  31. if (!fetestexcept (FE_UNDERFLOW))
  32. {
  33. puts ("underflow exception not supported at runtime, cannot test");
  34. return 0;
  35. }
  36. feclearexcept (FE_ALL_EXCEPT);
  37. c = a * b;
  38. if (fetestexcept (FE_UNDERFLOW))
  39. {
  40. if (TININESS_AFTER_ROUNDING)
  41. {
  42. puts ("tininess.h says after rounding, "
  43. "but detected before rounding");
  44. result = 1;
  45. }
  46. }
  47. else
  48. {
  49. if (!TININESS_AFTER_ROUNDING)
  50. {
  51. puts ("tininess.h says before rounding, "
  52. "but detected after rounding");
  53. result = 1;
  54. }
  55. }
  56. #else
  57. puts ("underflow exception not supported at compile time, cannot test");
  58. #endif
  59. return result;
  60. }
  61. #define TEST_FUNCTION do_test ()
  62. #include "../test-skeleton.c"