fenv.h 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. //
  2. // Copyright 2026 Aarav Ravindra Kharade
  3. //
  4. // Licensed under the Apache License, Version 2.0 (the "License");
  5. // you may not use this file except in compliance with the License.
  6. // You may obtain a copy of the License at
  7. //
  8. // http://www.apache.org/licenses/LICENSE-2.0
  9. //
  10. // Unless required by applicable law or agreed to in writing, software
  11. // distributed under the License is distributed on an "AS IS" BASIS,
  12. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. // See the License for the specific language governing permissions and
  14. // limitations under the License.
  15. //
  16. /* Copyright (C) 1997-2026 Free Software Foundation, Inc.
  17. This file is part of the GNU C Library.
  18. The GNU C Library is free software; you can redistribute it and/or
  19. modify it under the terms of the GNU Lesser General Public
  20. License as published by the Free Software Foundation; either
  21. version 2.1 of the License, or (at your option) any later version.
  22. The GNU C Library is distributed in the hope that it will be useful,
  23. but WITHOUT ANY WARRANTY; without even the implied warranty of
  24. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  25. Lesser General Public License for more details.
  26. You should have received a copy of the GNU Lesser General Public
  27. License along with the GNU C Library; if not, see
  28. <https://www.gnu.org/licenses/>. */
  29. #ifndef _FENV_H
  30. # error "Never use <bits/fenv.h> directly; include <fenv.h> instead."
  31. #endif
  32. /* Define bits representing the exception. We use the bit positions
  33. of the appropriate bits in the FPU control word. */
  34. enum
  35. {
  36. FE_INVALID =
  37. #define FE_INVALID 0x01
  38. FE_INVALID,
  39. __FE_DENORM = 0x02,
  40. FE_DIVBYZERO =
  41. #define FE_DIVBYZERO 0x04
  42. FE_DIVBYZERO,
  43. FE_OVERFLOW =
  44. #define FE_OVERFLOW 0x08
  45. FE_OVERFLOW,
  46. FE_UNDERFLOW =
  47. #define FE_UNDERFLOW 0x10
  48. FE_UNDERFLOW,
  49. FE_INEXACT =
  50. #define FE_INEXACT 0x20
  51. FE_INEXACT
  52. };
  53. #define FE_ALL_EXCEPT \
  54. (FE_INEXACT | FE_DIVBYZERO | FE_UNDERFLOW | FE_OVERFLOW | FE_INVALID)
  55. /* The ix87 FPU supports all of the four defined rounding modes. We
  56. use again the bit positions in the FPU control word as the values
  57. for the appropriate macros. */
  58. enum
  59. {
  60. FE_TONEAREST =
  61. #define FE_TONEAREST 0
  62. FE_TONEAREST,
  63. FE_DOWNWARD =
  64. #define FE_DOWNWARD 0x400
  65. FE_DOWNWARD,
  66. FE_UPWARD =
  67. #define FE_UPWARD 0x800
  68. FE_UPWARD,
  69. FE_TOWARDZERO =
  70. #define FE_TOWARDZERO 0xc00
  71. FE_TOWARDZERO
  72. };
  73. /* Type representing exception flags. */
  74. typedef unsigned short int fexcept_t;
  75. /* Type representing floating-point environment. This structure
  76. corresponds to the layout of the block written by the `fstenv'
  77. instruction and has additional fields for the contents of the MXCSR
  78. register as written by the `stmxcsr' instruction. */
  79. typedef struct
  80. {
  81. unsigned short int __control_word;
  82. unsigned short int __glibc_reserved1;
  83. unsigned short int __status_word;
  84. unsigned short int __glibc_reserved2;
  85. unsigned short int __tags;
  86. unsigned short int __glibc_reserved3;
  87. unsigned int __eip;
  88. unsigned short int __cs_selector;
  89. unsigned int __opcode:11;
  90. unsigned int __glibc_reserved4:5;
  91. unsigned int __data_offset;
  92. unsigned short int __data_selector;
  93. unsigned short int __glibc_reserved5;
  94. #ifdef __x86_64__
  95. unsigned int __mxcsr;
  96. #endif
  97. }
  98. fenv_t;
  99. /* If the default argument is used we use this value. */
  100. #define FE_DFL_ENV ((const fenv_t *) -1)
  101. #ifdef __USE_GNU
  102. /* Floating-point environment where none of the exception is masked. */
  103. # define FE_NOMASK_ENV ((const fenv_t *) -2)
  104. #endif
  105. #if __GLIBC_USE (IEC_60559_BFP_EXT_C23)
  106. /* Type representing floating-point control modes. */
  107. typedef struct
  108. {
  109. unsigned short int __control_word;
  110. unsigned short int __glibc_reserved;
  111. unsigned int __mxcsr;
  112. }
  113. femode_t;
  114. /* Default floating-point control modes. */
  115. # define FE_DFL_MODE ((const femode_t *) -1L)
  116. #endif