fenv.h 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  1. /* Copyright (C) 1997-2020 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. <https://www.gnu.org/licenses/>. */
  14. /*
  15. * ISO C99 7.6: Floating-point environment <fenv.h>
  16. */
  17. #ifndef _FENV_H
  18. #define _FENV_H 1
  19. #define __GLIBC_INTERNAL_STARTING_HEADER_IMPLEMENTATION
  20. #include <bits/libc-header-start.h>
  21. /* Get the architecture dependend definitions. The following definitions
  22. are expected to be done:
  23. fenv_t type for object representing an entire floating-point
  24. environment
  25. FE_DFL_ENV macro of type pointer to fenv_t to be used as the argument
  26. to functions taking an argument of type fenv_t; in this
  27. case the default environment will be used
  28. fexcept_t type for object representing the floating-point exception
  29. flags including status associated with the flags
  30. femode_t type for object representing floating-point control modes
  31. FE_DFL_MODE macro of type pointer to const femode_t to be used as the
  32. argument to fesetmode; in this case the default control
  33. modes will be used
  34. The following macros are defined iff the implementation supports this
  35. kind of exception.
  36. FE_INEXACT inexact result
  37. FE_DIVBYZERO division by zero
  38. FE_UNDERFLOW result not representable due to underflow
  39. FE_OVERFLOW result not representable due to overflow
  40. FE_INVALID invalid operation
  41. FE_ALL_EXCEPT bitwise OR of all supported exceptions
  42. The next macros are defined iff the appropriate rounding mode is
  43. supported by the implementation.
  44. FE_TONEAREST round to nearest
  45. FE_UPWARD round toward +Inf
  46. FE_DOWNWARD round toward -Inf
  47. FE_TOWARDZERO round toward 0
  48. */
  49. #include <bits/fenv.h>
  50. __BEGIN_DECLS
  51. /* Floating-point exception handling. */
  52. /* Clear the supported exceptions represented by EXCEPTS. */
  53. extern int feclearexcept (int __excepts) __THROW;
  54. /* Store implementation-defined representation of the exception flags
  55. indicated by EXCEPTS in the object pointed to by FLAGP. */
  56. extern int fegetexceptflag (fexcept_t *__flagp, int __excepts) __THROW;
  57. /* Raise the supported exceptions represented by EXCEPTS. */
  58. extern int feraiseexcept (int __excepts) __THROW;
  59. #if __GLIBC_USE (IEC_60559_BFP_EXT_C2X)
  60. /* Set the supported exception flags represented by EXCEPTS, without
  61. causing enabled traps to be taken. */
  62. extern int fesetexcept (int __excepts) __THROW;
  63. #endif
  64. /* Set complete status for exceptions indicated by EXCEPTS according to
  65. the representation in the object pointed to by FLAGP. */
  66. extern int fesetexceptflag (const fexcept_t *__flagp, int __excepts) __THROW;
  67. /* Determine which of subset of the exceptions specified by EXCEPTS are
  68. currently set. */
  69. extern int fetestexcept (int __excepts) __THROW;
  70. #if __GLIBC_USE (IEC_60559_BFP_EXT_C2X)
  71. /* Determine which of subset of the exceptions specified by EXCEPTS
  72. are set in *FLAGP. */
  73. extern int fetestexceptflag (const fexcept_t *__flagp, int __excepts) __THROW;
  74. #endif
  75. /* Rounding control. */
  76. /* Get current rounding direction. */
  77. extern int fegetround (void) __THROW __attribute_pure__;
  78. /* Establish the rounding direction represented by ROUND. */
  79. extern int fesetround (int __rounding_direction) __THROW;
  80. /* Floating-point environment. */
  81. /* Store the current floating-point environment in the object pointed
  82. to by ENVP. */
  83. extern int fegetenv (fenv_t *__envp) __THROW;
  84. /* Save the current environment in the object pointed to by ENVP, clear
  85. exception flags and install a non-stop mode (if available) for all
  86. exceptions. */
  87. extern int feholdexcept (fenv_t *__envp) __THROW;
  88. /* Establish the floating-point environment represented by the object
  89. pointed to by ENVP. */
  90. extern int fesetenv (const fenv_t *__envp) __THROW;
  91. /* Save current exceptions in temporary storage, install environment
  92. represented by object pointed to by ENVP and raise exceptions
  93. according to saved exceptions. */
  94. extern int feupdateenv (const fenv_t *__envp) __THROW;
  95. /* Control modes. */
  96. #if __GLIBC_USE (IEC_60559_BFP_EXT_C2X)
  97. /* Store the current floating-point control modes in the object
  98. pointed to by MODEP. */
  99. extern int fegetmode (femode_t *__modep) __THROW;
  100. /* Establish the floating-point control modes represented by the
  101. object pointed to by MODEP. */
  102. extern int fesetmode (const femode_t *__modep) __THROW;
  103. #endif
  104. /* Include optimization. */
  105. #ifdef __OPTIMIZE__
  106. # include <bits/fenvinline.h>
  107. #endif
  108. /* NaN support. */
  109. #if (__GLIBC_USE (IEC_60559_BFP_EXT_C2X) \
  110. && defined FE_INVALID \
  111. && defined __SUPPORT_SNAN__)
  112. # define FE_SNANS_ALWAYS_SIGNAL 1
  113. #endif
  114. #ifdef __USE_GNU
  115. /* Enable individual exceptions. Will not enable more exceptions than
  116. EXCEPTS specifies. Returns the previous enabled exceptions if all
  117. exceptions are successfully set, otherwise returns -1. */
  118. extern int feenableexcept (int __excepts) __THROW;
  119. /* Disable individual exceptions. Will not disable more exceptions than
  120. EXCEPTS specifies. Returns the previous enabled exceptions if all
  121. exceptions are successfully disabled, otherwise returns -1. */
  122. extern int fedisableexcept (int __excepts) __THROW;
  123. /* Return enabled exceptions. */
  124. extern int fegetexcept (void) __THROW;
  125. #endif
  126. __END_DECLS
  127. #endif /* fenv.h */