fenv.h 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  1. /* Copyright (C) 1997-2026 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 dependent 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. #if __GLIBC_USE (ISOC23)
  52. # define __STDC_VERSION_FENV_H__ 202311L
  53. #endif
  54. /* Floating-point exception handling. */
  55. /* Clear the supported exceptions represented by EXCEPTS. */
  56. extern int feclearexcept (int __excepts) __THROW;
  57. /* Store implementation-defined representation of the exception flags
  58. indicated by EXCEPTS in the object pointed to by FLAGP. */
  59. extern int fegetexceptflag (fexcept_t *__flagp, int __excepts) __THROW;
  60. /* Raise the supported exceptions represented by EXCEPTS. */
  61. extern int feraiseexcept (int __excepts) __THROW;
  62. #if __GLIBC_USE (IEC_60559_BFP_EXT_C23)
  63. /* Set the supported exception flags represented by EXCEPTS, without
  64. causing enabled traps to be taken. */
  65. extern int fesetexcept (int __excepts) __THROW;
  66. #endif
  67. /* Set complete status for exceptions indicated by EXCEPTS according to
  68. the representation in the object pointed to by FLAGP. */
  69. extern int fesetexceptflag (const fexcept_t *__flagp, int __excepts) __THROW;
  70. /* Determine which of subset of the exceptions specified by EXCEPTS are
  71. currently set. */
  72. extern int fetestexcept (int __excepts) __THROW;
  73. #if __GLIBC_USE (IEC_60559_BFP_EXT_C23)
  74. /* Determine which of subset of the exceptions specified by EXCEPTS
  75. are set in *FLAGP. */
  76. extern int fetestexceptflag (const fexcept_t *__flagp, int __excepts) __THROW;
  77. #endif
  78. /* Rounding control. */
  79. /* Get current rounding direction. */
  80. extern int fegetround (void) __THROW __attribute_pure__;
  81. /* Establish the rounding direction represented by ROUND. */
  82. extern int fesetround (int __rounding_direction) __THROW;
  83. /* Floating-point environment. */
  84. /* Store the current floating-point environment in the object pointed
  85. to by ENVP. */
  86. extern int fegetenv (fenv_t *__envp) __THROW;
  87. /* Save the current environment in the object pointed to by ENVP, clear
  88. exception flags and install a non-stop mode (if available) for all
  89. exceptions. */
  90. extern int feholdexcept (fenv_t *__envp) __THROW;
  91. /* Establish the floating-point environment represented by the object
  92. pointed to by ENVP. */
  93. extern int fesetenv (const fenv_t *__envp) __THROW;
  94. /* Save current exceptions in temporary storage, install environment
  95. represented by object pointed to by ENVP and raise exceptions
  96. according to saved exceptions. */
  97. extern int feupdateenv (const fenv_t *__envp) __THROW;
  98. /* Control modes. */
  99. #if __GLIBC_USE (IEC_60559_BFP_EXT_C23)
  100. /* Store the current floating-point control modes in the object
  101. pointed to by MODEP. */
  102. extern int fegetmode (femode_t *__modep) __THROW;
  103. /* Establish the floating-point control modes represented by the
  104. object pointed to by MODEP. */
  105. extern int fesetmode (const femode_t *__modep) __THROW;
  106. #endif
  107. /* NaN support. */
  108. #if (__GLIBC_USE (IEC_60559_BFP_EXT_C23) \
  109. && defined FE_INVALID \
  110. && defined __SUPPORT_SNAN__)
  111. # define FE_SNANS_ALWAYS_SIGNAL 1
  112. #endif
  113. #ifdef __USE_GNU
  114. /* Enable individual exceptions. Will not enable more exceptions than
  115. EXCEPTS specifies. Returns the previous enabled exceptions if all
  116. exceptions are successfully set, otherwise returns -1. */
  117. extern int feenableexcept (int __excepts) __THROW;
  118. /* Disable individual exceptions. Will not disable more exceptions than
  119. EXCEPTS specifies. Returns the previous enabled exceptions if all
  120. exceptions are successfully disabled, otherwise returns -1. */
  121. extern int fedisableexcept (int __excepts) __THROW;
  122. /* Return enabled exceptions. */
  123. extern int fegetexcept (void) __THROW;
  124. #endif
  125. __END_DECLS
  126. #endif /* fenv.h */