fenv.h 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. /* Copyright (C) 1997-2019 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
  5. License as published by the Free Software Foundation; either
  6. version 2.1 of the 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. <http://www.gnu.org/licenses/>. */
  14. #ifndef _FENV_H
  15. # error "Never use <bits/fenv.h> directly; include <fenv.h> instead."
  16. #endif
  17. #if defined __HAVE_68881__ || defined __HAVE_FPU__ || defined __mcffpu__
  18. /* Define bits representing the exception. We use the bit positions of
  19. the appropriate bits in the FPSR Accrued Exception Byte. */
  20. enum
  21. {
  22. FE_INEXACT =
  23. # define FE_INEXACT (1 << 3)
  24. FE_INEXACT,
  25. FE_DIVBYZERO =
  26. # define FE_DIVBYZERO (1 << 4)
  27. FE_DIVBYZERO,
  28. FE_UNDERFLOW =
  29. # define FE_UNDERFLOW (1 << 5)
  30. FE_UNDERFLOW,
  31. FE_OVERFLOW =
  32. # define FE_OVERFLOW (1 << 6)
  33. FE_OVERFLOW,
  34. FE_INVALID =
  35. # define FE_INVALID (1 << 7)
  36. FE_INVALID
  37. };
  38. # define FE_ALL_EXCEPT \
  39. (FE_INEXACT | FE_DIVBYZERO | FE_UNDERFLOW | FE_OVERFLOW | FE_INVALID)
  40. /* The m68k FPU supports all of the four defined rounding modes. We use
  41. the bit positions in the FPCR Mode Control Byte as the values for the
  42. appropriate macros. */
  43. enum
  44. {
  45. FE_TONEAREST =
  46. # define FE_TONEAREST 0
  47. FE_TONEAREST,
  48. FE_TOWARDZERO =
  49. # define FE_TOWARDZERO (1 << 4)
  50. FE_TOWARDZERO,
  51. FE_DOWNWARD =
  52. # define FE_DOWNWARD (2 << 4)
  53. FE_DOWNWARD,
  54. FE_UPWARD =
  55. # define FE_UPWARD (3 << 4)
  56. FE_UPWARD
  57. };
  58. #else
  59. /* In the soft-float case, only rounding to nearest is supported, with
  60. no exceptions. */
  61. # define FE_ALL_EXCEPT 0
  62. enum
  63. {
  64. __FE_UNDEFINED = -1,
  65. FE_TONEAREST =
  66. # define FE_TONEAREST 0
  67. FE_TONEAREST
  68. };
  69. #endif
  70. /* Type representing exception flags. */
  71. typedef unsigned int fexcept_t;
  72. #if defined __HAVE_68881__ || defined __HAVE_FPU__ || defined __mcffpu__
  73. /* Type representing floating-point environment. This structure
  74. corresponds to the layout of the block written by `fmovem'. */
  75. typedef struct
  76. {
  77. unsigned int __control_register;
  78. unsigned int __status_register;
  79. unsigned int __instruction_address;
  80. }
  81. fenv_t;
  82. #else
  83. /* Keep ABI compatibility with the type used in the generic
  84. bits/fenv.h, formerly used for no-FPU ColdFire. */
  85. typedef struct
  86. {
  87. fexcept_t __excepts;
  88. }
  89. fenv_t;
  90. #endif
  91. /* If the default argument is used we use this value. */
  92. #define FE_DFL_ENV ((const fenv_t *) -1)
  93. #if defined __USE_GNU && (defined __HAVE_68881__ \
  94. || defined __HAVE_FPU__ \
  95. || defined __mcffpu__)
  96. /* Floating-point environment where none of the exceptions are masked. */
  97. # define FE_NOMASK_ENV ((const fenv_t *) -2)
  98. #endif
  99. #if __GLIBC_USE (IEC_60559_BFP_EXT)
  100. /* Type representing floating-point control modes. */
  101. typedef unsigned int femode_t;
  102. /* Default floating-point control modes. */
  103. # define FE_DFL_MODE ((const femode_t *) -1L)
  104. #endif