fenv.h 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. /* Copyright (C) 2004-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 License as
  4. published by the Free Software Foundation; either version 2.1 of the
  5. 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. /* Define bits representing exceptions in the FPSR status word. */
  17. enum
  18. {
  19. FE_INVALID =
  20. #define FE_INVALID 1
  21. FE_INVALID,
  22. FE_DIVBYZERO =
  23. #define FE_DIVBYZERO 2
  24. FE_DIVBYZERO,
  25. FE_OVERFLOW =
  26. #define FE_OVERFLOW 4
  27. FE_OVERFLOW,
  28. FE_UNDERFLOW =
  29. #define FE_UNDERFLOW 8
  30. FE_UNDERFLOW,
  31. FE_INEXACT =
  32. #define FE_INEXACT 16
  33. FE_INEXACT,
  34. };
  35. /* Amount to shift by to convert an exception bit in FPSR to a an
  36. exception bit mask in FPCR. */
  37. #define FE_EXCEPT_SHIFT 8
  38. /* All supported exceptions. */
  39. #define FE_ALL_EXCEPT \
  40. (FE_INVALID | FE_DIVBYZERO | FE_OVERFLOW | FE_UNDERFLOW | FE_INEXACT)
  41. /* Define bits representing rounding modes in the FPCR Rmode field. */
  42. #define FE_TONEAREST 0x000000
  43. #define FE_UPWARD 0x400000
  44. #define FE_DOWNWARD 0x800000
  45. #define FE_TOWARDZERO 0xc00000
  46. /* Type representing exception flags. */
  47. typedef unsigned int fexcept_t;
  48. /* Type representing floating-point environment. */
  49. typedef struct
  50. {
  51. unsigned int __fpcr;
  52. unsigned int __fpsr;
  53. }
  54. fenv_t;
  55. /* If the default argument is used we use this value. */
  56. #define FE_DFL_ENV ((const fenv_t *) -1l)
  57. #ifdef __USE_GNU
  58. /* Floating-point environment where none of the exceptions are masked. */
  59. # define FE_NOMASK_ENV ((const fenv_t *) -2)
  60. #endif
  61. /* Type representing floating-point control modes. */
  62. typedef unsigned int femode_t;
  63. /* Default floating-point control modes. */
  64. # define FE_DFL_MODE ((const femode_t *) -1L)