fenv.c 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. /* Copyright (C) 2012-2015 Free Software Foundation, Inc.
  2. This file is part of the GNU Atomic Library (libatomic).
  3. Libatomic is free software; you can redistribute it and/or modify it
  4. under the terms of the GNU General Public License as published by
  5. the Free Software Foundation; either version 3 of the License, or
  6. (at your option) any later version.
  7. Libatomic is distributed in the hope that it will be useful, but WITHOUT ANY
  8. WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  9. FOR A PARTICULAR PURPOSE. See the GNU General Public License for
  10. more details.
  11. Under Section 7 of GPL version 3, you are granted additional
  12. permissions described in the GCC Runtime Library Exception, version
  13. 3.1, as published by the Free Software Foundation.
  14. You should have received a copy of the GNU General Public License and
  15. a copy of the GCC Runtime Library Exception along with this program;
  16. see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
  17. <http://www.gnu.org/licenses/>. */
  18. #include "libatomic_i.h"
  19. #ifdef HAVE_FENV_H
  20. # include <fenv.h>
  21. #endif
  22. /* Raise the supported floating-point exceptions from EXCEPTS. Other
  23. bits in EXCEPTS are ignored. */
  24. void
  25. __atomic_feraiseexcept (int excepts __attribute__ ((unused)))
  26. {
  27. volatile float r __attribute__ ((unused));
  28. #ifdef FE_INVALID
  29. if (excepts & FE_INVALID)
  30. {
  31. volatile float zero = 0.0f;
  32. r = zero / zero;
  33. }
  34. #endif
  35. #ifdef FE_DIVBYZERO
  36. if (excepts & FE_DIVBYZERO)
  37. {
  38. volatile float zero = 0.0f;
  39. r = 1.0f / zero;
  40. }
  41. #endif
  42. #ifdef FE_OVERFLOW
  43. if (excepts & FE_OVERFLOW)
  44. {
  45. volatile float max = __FLT_MAX__;
  46. r = max * max;
  47. }
  48. #endif
  49. #ifdef FE_UNDERFLOW
  50. if (excepts & FE_UNDERFLOW)
  51. {
  52. volatile float min = __FLT_MIN__;
  53. r = min * min;
  54. }
  55. #endif
  56. #ifdef FE_INEXACT
  57. if (excepts & FE_INEXACT)
  58. {
  59. volatile float three = 3.0f;
  60. r = 1.0f / three;
  61. }
  62. #endif
  63. }