1 /* Copyright (C) 1997-2025 Free Software Foundation, Inc.
2 
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 
8    The GNU C Library is distributed in the hope that it will be useful,
9    but WITHOUT ANY WARRANTY; without even the implied warranty of
10    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
11    Lesser General Public License for more details.
12 
13    You should have received a copy of the GNU Lesser General Public
14    License along with the GNU C Library.  If not, see
15    <https://www.gnu.org/licenses/>.  */
16 
17 #ifndef _FENV_H
18 # error "Never use <bits/fenv.h> directly; include <fenv.h> instead."
19 #endif
20 
21 
22 #if defined __HAVE_68881__ || defined __HAVE_FPU__ || defined __mcffpu__
23 
24 /* Define bits representing the exception.  We use the bit positions of
25    the appropriate bits in the FPSR Accrued Exception Byte.  */
26 enum
27   {
28     FE_INEXACT =
29 # define FE_INEXACT	(1 << 3)
30       FE_INEXACT,
31     FE_DIVBYZERO =
32 # define FE_DIVBYZERO	(1 << 4)
33       FE_DIVBYZERO,
34     FE_UNDERFLOW =
35 # define FE_UNDERFLOW	(1 << 5)
36       FE_UNDERFLOW,
37     FE_OVERFLOW =
38 # define FE_OVERFLOW	(1 << 6)
39       FE_OVERFLOW,
40     FE_INVALID =
41 # define FE_INVALID	(1 << 7)
42       FE_INVALID
43   };
44 
45 # define FE_ALL_EXCEPT \
46 	(FE_INEXACT | FE_DIVBYZERO | FE_UNDERFLOW | FE_OVERFLOW | FE_INVALID)
47 
48 /* The m68k FPU supports all of the four defined rounding modes.  We use
49    the bit positions in the FPCR Mode Control Byte as the values for the
50    appropriate macros.  */
51 enum
52   {
53     FE_TONEAREST =
54 # define FE_TONEAREST	0
55       FE_TONEAREST,
56     FE_TOWARDZERO =
57 # define FE_TOWARDZERO	(1 << 4)
58       FE_TOWARDZERO,
59     FE_DOWNWARD =
60 # define FE_DOWNWARD	(2 << 4)
61       FE_DOWNWARD,
62     FE_UPWARD =
63 # define FE_UPWARD	(3 << 4)
64       FE_UPWARD
65   };
66 
67 #else
68 
69 /* In the soft-float case, only rounding to nearest is supported, with
70    no exceptions.  */
71 
72 # define FE_ALL_EXCEPT 0
73 
74 enum
75   {
76     __FE_UNDEFINED = -1,
77 
78     FE_TONEAREST =
79 # define FE_TONEAREST	0
80       FE_TONEAREST
81   };
82 
83 #endif
84 
85 
86 /* Type representing exception flags.  */
87 typedef unsigned int fexcept_t;
88 
89 
90 #if defined __HAVE_68881__ || defined __HAVE_FPU__ || defined __mcffpu__
91 
92 /* Type representing floating-point environment.  This structure
93    corresponds to the layout of the block written by `fmovem'.  */
94 typedef struct
95   {
96     unsigned int __control_register;
97     unsigned int __status_register;
98     unsigned int __instruction_address;
99   }
100 fenv_t;
101 
102 #else
103 
104 /* Keep ABI compatibility with the type used in the generic
105    bits/fenv.h, formerly used for no-FPU ColdFire.  */
106 typedef struct
107   {
108     fexcept_t __excepts;
109   }
110 fenv_t;
111 
112 #endif
113 
114 /* If the default argument is used we use this value.  */
115 #define FE_DFL_ENV	((const fenv_t *) -1)
116 
117 #if defined __USE_GNU && (defined __HAVE_68881__	\
118 			  || defined __HAVE_FPU__	\
119 			  || defined __mcffpu__)
120 /* Floating-point environment where none of the exceptions are masked.  */
121 # define FE_NOMASK_ENV	((const fenv_t *) -2)
122 #endif
123 
124 /* Type representing floating-point control modes.  */
125 typedef unsigned int femode_t;
126 
127 /* Default floating-point control modes.  */
128 # define FE_DFL_MODE	((const femode_t *) -1L)
129