fenv.h 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. /* Copyright (C) 1997-2025 Free Software Foundation, Inc.
  2. The GNU C Library is free software; you can redistribute it and/or
  3. modify it under the terms of the GNU Lesser General Public
  4. License as published by the Free Software Foundation; either
  5. version 2.1 of the License, or (at your option) any later version.
  6. The GNU C Library is distributed in the hope that it will be useful,
  7. but WITHOUT ANY WARRANTY; without even the implied warranty of
  8. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  9. Lesser General Public License for more details.
  10. You should have received a copy of the GNU Lesser General Public
  11. License along with the GNU C Library; if not, see
  12. <https://www.gnu.org/licenses/>. */
  13. #ifndef _FENV_H
  14. # error "Never use <bits/fenv.h> directly; include <fenv.h> instead."
  15. #endif
  16. #include <bits/wordsize.h>
  17. /* Define bits representing the exception. We use the bit positions
  18. of the appropriate accrued exception bits from the FSR. */
  19. enum
  20. {
  21. FE_INVALID =
  22. #define FE_INVALID (1 << 9)
  23. FE_INVALID,
  24. FE_OVERFLOW =
  25. #define FE_OVERFLOW (1 << 8)
  26. FE_OVERFLOW,
  27. FE_UNDERFLOW =
  28. #define FE_UNDERFLOW (1 << 7)
  29. FE_UNDERFLOW,
  30. FE_DIVBYZERO =
  31. #define FE_DIVBYZERO (1 << 6)
  32. FE_DIVBYZERO,
  33. FE_INEXACT =
  34. #define FE_INEXACT (1 << 5)
  35. FE_INEXACT
  36. };
  37. #define FE_ALL_EXCEPT \
  38. (FE_INEXACT | FE_DIVBYZERO | FE_UNDERFLOW | FE_OVERFLOW | FE_INVALID)
  39. /* The Sparc FPU supports all of the four defined rounding modes. We
  40. use again the bit positions in the FPU control word as the values
  41. for the appropriate macros. */
  42. enum
  43. {
  44. FE_TONEAREST =
  45. #define FE_TONEAREST (0 << 30)
  46. FE_TONEAREST,
  47. FE_TOWARDZERO =
  48. #define FE_TOWARDZERO (1 << 30)
  49. FE_TOWARDZERO,
  50. FE_UPWARD =
  51. #define FE_UPWARD (-0x7fffffff - 1) /* (2 << 30) */
  52. FE_UPWARD,
  53. FE_DOWNWARD =
  54. #define FE_DOWNWARD (-0x40000000) /* (3 << 30) */
  55. FE_DOWNWARD
  56. };
  57. #define __FE_ROUND_MASK (3U << 30)
  58. /* Type representing exception flags. */
  59. typedef unsigned long int fexcept_t;
  60. /* Type representing floating-point environment. */
  61. typedef unsigned long int fenv_t;
  62. /* If the default argument is used we use this value. */
  63. #define FE_DFL_ENV ((const fenv_t *) -1)
  64. #ifdef __USE_GNU
  65. /* Floating-point environment where none of the exception is masked. */
  66. # define FE_NOMASK_ENV ((const fenv_t *) -2)
  67. #endif
  68. /* Type representing floating-point control modes. */
  69. typedef unsigned long int femode_t;
  70. /* Default floating-point control modes. */
  71. # define FE_DFL_MODE ((const femode_t *) -1L)