fenv.h 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. /* Copyright (C) 2004-2021 Free Software Foundation, Inc.
  2. This file is part of the GNU C Library.
  3. The GNU C Library is free software; you can redistribute it and/or
  4. modify it under the terms of the GNU Lesser General Public License as
  5. published by the Free Software Foundation; either version 2.1 of the
  6. License, or (at your option) any later version.
  7. The GNU C Library is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  10. Lesser General Public License for more details.
  11. You should have received a copy of the GNU Lesser General Public
  12. License along with the GNU C Library; if not, see
  13. <https://www.gnu.org/licenses/>. */
  14. #ifndef _FENV_H
  15. # error "Never use <bits/fenv.h> directly; include <fenv.h> instead."
  16. #endif
  17. /* Define bits representing exceptions in the FPSR status word. */
  18. enum
  19. {
  20. FE_INVALID =
  21. #define FE_INVALID 1
  22. FE_INVALID,
  23. FE_DIVBYZERO =
  24. #define FE_DIVBYZERO 2
  25. FE_DIVBYZERO,
  26. FE_OVERFLOW =
  27. #define FE_OVERFLOW 4
  28. FE_OVERFLOW,
  29. FE_UNDERFLOW =
  30. #define FE_UNDERFLOW 8
  31. FE_UNDERFLOW,
  32. FE_INEXACT =
  33. #define FE_INEXACT 16
  34. FE_INEXACT,
  35. };
  36. /* Amount to shift by to convert an exception bit in FPSR to a an
  37. exception bit mask in FPCR. */
  38. #define FE_EXCEPT_SHIFT 8
  39. /* All supported exceptions. */
  40. #define FE_ALL_EXCEPT \
  41. (FE_INVALID | FE_DIVBYZERO | FE_OVERFLOW | FE_UNDERFLOW | FE_INEXACT)
  42. /* Define bits representing rounding modes in the FPCR Rmode field. */
  43. #define FE_TONEAREST 0x000000
  44. #define FE_UPWARD 0x400000
  45. #define FE_DOWNWARD 0x800000
  46. #define FE_TOWARDZERO 0xc00000
  47. /* Type representing exception flags. */
  48. typedef unsigned int fexcept_t;
  49. /* Type representing floating-point environment. */
  50. typedef struct
  51. {
  52. unsigned int __fpcr;
  53. unsigned int __fpsr;
  54. }
  55. fenv_t;
  56. /* If the default argument is used we use this value. */
  57. #define FE_DFL_ENV ((const fenv_t *) -1l)
  58. #ifdef __USE_GNU
  59. /* Floating-point environment where none of the exceptions are masked. */
  60. # define FE_NOMASK_ENV ((const fenv_t *) -2)
  61. #endif
  62. #if __GLIBC_USE (IEC_60559_BFP_EXT_C2X)
  63. /* Type representing floating-point control modes. */
  64. typedef unsigned int femode_t;
  65. /* Default floating-point control modes. */
  66. # define FE_DFL_MODE ((const femode_t *) -1L)
  67. #endif