fenv.h 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  1. /* Copyright (C) 1997, 1998, 1999, 2004, 2006 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. #include <features.h>
  18. #ifdef __CONFIG_E500__
  19. /* Define bits representing the exception. We use the bit positions of
  20. the appropriate bits in the SPEFSCR... */
  21. enum
  22. {
  23. FE_INEXACT = 1 << (63 - 42),
  24. #define FE_INEXACT FE_INEXACT
  25. FE_INVALID = 1 << (63 - 43),
  26. #define FE_INVALID FE_INVALID
  27. FE_DIVBYZERO = 1 << (63 - 44),
  28. #define FE_DIVBYZERO FE_DIVBYZERO
  29. FE_UNDERFLOW = 1 << (63 - 45),
  30. #define FE_UNDERFLOW FE_UNDERFLOW
  31. FE_OVERFLOW = 1 << (63 - 46)
  32. #define FE_OVERFLOW FE_OVERFLOW
  33. };
  34. #else /* PowerPC 6xx floating-point. */
  35. /* Define bits representing the exception. We use the bit positions of
  36. the appropriate bits in the FPSCR... */
  37. enum
  38. {
  39. FE_INEXACT = 1 << (31 - 6),
  40. #define FE_INEXACT FE_INEXACT
  41. FE_DIVBYZERO = 1 << (31 - 5),
  42. #define FE_DIVBYZERO FE_DIVBYZERO
  43. FE_UNDERFLOW = 1 << (31 - 4),
  44. #define FE_UNDERFLOW FE_UNDERFLOW
  45. FE_OVERFLOW = 1 << (31 - 3),
  46. #define FE_OVERFLOW FE_OVERFLOW
  47. /* ... except for FE_INVALID, for which we use bit 31. FE_INVALID
  48. actually corresponds to bits 7 through 12 and 21 through 23
  49. in the FPSCR, but we can't use that because the current draft
  50. says that it must be a power of 2. Instead we use bit 2 which
  51. is the summary bit for all the FE_INVALID exceptions, which
  52. kind of makes sense. */
  53. FE_INVALID = 1 << (31 - 2),
  54. #define FE_INVALID FE_INVALID
  55. #ifdef __USE_GNU
  56. /* Breakdown of the FE_INVALID bits. Setting FE_INVALID on an
  57. input to a routine is equivalent to setting all of these bits;
  58. FE_INVALID will be set on output from a routine iff one of
  59. these bits is set. Note, though, that you can't disable or
  60. enable these exceptions individually. */
  61. /* Operation with SNaN. */
  62. FE_INVALID_SNAN = 1 << (31 - 7),
  63. # define FE_INVALID_SNAN FE_INVALID_SNAN
  64. /* Inf - Inf */
  65. FE_INVALID_ISI = 1 << (31 - 8),
  66. # define FE_INVALID_ISI FE_INVALID_ISI
  67. /* Inf / Inf */
  68. FE_INVALID_IDI = 1 << (31 - 9),
  69. # define FE_INVALID_IDI FE_INVALID_IDI
  70. /* 0 / 0 */
  71. FE_INVALID_ZDZ = 1 << (31 - 10),
  72. # define FE_INVALID_ZDZ FE_INVALID_ZDZ
  73. /* Inf * 0 */
  74. FE_INVALID_IMZ = 1 << (31 - 11),
  75. # define FE_INVALID_IMZ FE_INVALID_IMZ
  76. /* Comparison with NaN or SNaN. */
  77. FE_INVALID_COMPARE = 1 << (31 - 12),
  78. # define FE_INVALID_COMPARE FE_INVALID_COMPARE
  79. /* Invalid operation flag for software (not set by hardware). */
  80. /* Note that some chips don't have this implemented, presumably
  81. because no-one expected anyone to write software for them %-). */
  82. FE_INVALID_SOFTWARE = 1 << (31 - 21),
  83. # define FE_INVALID_SOFTWARE FE_INVALID_SOFTWARE
  84. /* Square root of negative number (including -Inf). */
  85. /* Note that some chips don't have this implemented. */
  86. FE_INVALID_SQRT = 1 << (31 - 22),
  87. # define FE_INVALID_SQRT FE_INVALID_SQRT
  88. /* Conversion-to-integer of a NaN or a number too large or too small. */
  89. FE_INVALID_INTEGER_CONVERSION = 1 << (31 - 23)
  90. # define FE_INVALID_INTEGER_CONVERSION FE_INVALID_INTEGER_CONVERSION
  91. # define FE_ALL_INVALID \
  92. (FE_INVALID_SNAN | FE_INVALID_ISI | FE_INVALID_IDI | FE_INVALID_ZDZ \
  93. | FE_INVALID_IMZ | FE_INVALID_COMPARE | FE_INVALID_SOFTWARE \
  94. | FE_INVALID_SQRT | FE_INVALID_INTEGER_CONVERSION)
  95. #endif /* __USE_GNU */
  96. };
  97. #endif /* __CONFIG_E500__ */
  98. #define FE_ALL_EXCEPT \
  99. (FE_INEXACT | FE_DIVBYZERO | FE_UNDERFLOW | FE_OVERFLOW | FE_INVALID)
  100. /* PowerPC chips support all of the four defined rounding modes. We
  101. use the bit pattern in the FPSCR as the values for the
  102. appropriate macros. */
  103. enum
  104. {
  105. FE_TONEAREST = 0,
  106. #define FE_TONEAREST FE_TONEAREST
  107. FE_TOWARDZERO = 1,
  108. #define FE_TOWARDZERO FE_TOWARDZERO
  109. FE_UPWARD = 2,
  110. #define FE_UPWARD FE_UPWARD
  111. FE_DOWNWARD = 3
  112. #define FE_DOWNWARD FE_DOWNWARD
  113. };
  114. /* Type representing exception flags. */
  115. typedef unsigned int fexcept_t;
  116. /* Type representing floating-point environment. We leave it as 'double'
  117. for efficiency reasons (rather than writing it to a 32-bit integer). */
  118. typedef double fenv_t;
  119. /* If the default argument is used we use this value. */
  120. extern const fenv_t __fe_dfl_env;
  121. #define FE_DFL_ENV (&__fe_dfl_env)
  122. #ifdef __USE_GNU
  123. /* Floating-point environment where all exceptions are enabled. Note that
  124. this is not sufficient to give you SIGFPE. */
  125. extern const fenv_t __fe_enabled_env;
  126. # define FE_ENABLED_ENV (&__fe_enabled_env)
  127. /* Floating-point environment with (processor-dependent) non-IEEE floating
  128. point. */
  129. extern const fenv_t __fe_nonieee_env;
  130. # define FE_NONIEEE_ENV (&__fe_nonieee_env)
  131. /* Floating-point environment with all exceptions enabled. Note that
  132. just evaluating this value will set the processor into 'FPU
  133. exceptions imprecise recoverable' mode, which may cause a significant
  134. performance penalty (but have no other visible effect). */
  135. extern const fenv_t *__fe_nomask_env (void);
  136. # define FE_NOMASK_ENV (__fe_nomask_env ())
  137. #endif /* __USE_GNU */