exp2l: Work around a NetBSD 10.0/i386 bug.
[gnulib.git] / lib / fenv.in.h
blob422cafeec7ee2f48f64bd096863353575bb4c301
1 /* A GNU-like <fenv.h>.
3 Copyright (C) 1997-2024 Free Software Foundation, Inc.
5 This file is free software: you can redistribute it and/or modify
6 it under the terms of the GNU Lesser General Public License as
7 published by the Free Software Foundation; either version 2.1 of the
8 License, or (at your option) any later version.
10 This file is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU Lesser General Public License for more details.
15 You should have received a copy of the GNU Lesser General Public License
16 along with this program. If not, see <https://www.gnu.org/licenses/>. */
18 /* Based on glibc/sysdeps/<cpu>/bits/fenv.h. */
20 #if __GNUC__ >= 3
21 @PRAGMA_SYSTEM_HEADER@
22 #endif
23 @PRAGMA_COLUMNS@
25 #ifndef _@GUARD_PREFIX@_FENV_H
27 /* The include_next requires a split double-inclusion guard. */
28 #if @HAVE_FENV_H@
29 # @INCLUDE_NEXT@ @NEXT_FENV_H@
30 #endif
32 #ifndef _@GUARD_PREFIX@_FENV_H
33 #define _@GUARD_PREFIX@_FENV_H
35 /* This file uses GNULIB_POSIXCHECK. */
36 #if !_GL_CONFIG_H_INCLUDED
37 #error "Please include config.h first."
38 #endif
40 /* The definitions of _GL_FUNCDECL_RPL etc. are copied here. */
42 /* The definition of _GL_WARN_ON_USE is copied here. */
45 /* We cannot implement the #pragmas here; this needs to be done in the
46 compiler. */
49 /* ISO C 99 § 7.6.4 Environment
50 ISO C 23 § 7.6.6 Environment */
52 #if !@HAVE_FENV_H@
54 # if (defined __x86_64__ || defined _M_X64) || (defined __i386 || defined _M_IX86)
56 typedef struct
58 /* 7 32-bit words, see <https://stackoverflow.com/questions/10337750/> */
59 unsigned short __control_word; /* fctrl register */
60 unsigned short __reserved1;
61 unsigned short __status_word; /* fstat register */
62 unsigned short __reserved2;
63 unsigned short __tags;
64 unsigned short __reserved3;
65 unsigned int __instruction_pointer; /* eip register */
66 unsigned short __instruction_selector; /* cs register */
67 unsigned int __opcode : 11;
68 unsigned int __reserved4 : 5;
69 unsigned int __data_pointer;
70 unsigned short __data_selector;
71 unsigned short __reserved5;
72 # ifdef __x86_64__
73 unsigned int __mxcsr; /* mxcsr register */
74 # endif
76 fenv_t;
78 # elif defined __aarch64__ /* arm64 */
80 typedef struct
82 unsigned int __fpcr; /* fpcr register */
83 unsigned int __fpsr; /* fpsr register */
85 fenv_t;
87 # elif defined __arm__
89 typedef struct
91 unsigned int __cw; /* fpscr register */
93 fenv_t;
95 # elif defined __alpha
97 typedef unsigned long fenv_t;
99 # elif defined __hppa
101 typedef struct
103 unsigned int __status_word; /* floating point status register */
104 } fenv_t;
106 # elif defined __ia64__
108 typedef unsigned long fenv_t; /* fpsr = floating point status register */
110 # elif defined __m68k__
112 typedef struct
114 unsigned int __control_register; /* fpcr = floating point control register */
115 unsigned int __status_register; /* fpsr = floating point status register */
116 unsigned int __instruction_address; /* floating point instruction register */
118 fenv_t;
120 # elif defined __mips__ || defined __loongarch__
122 typedef struct
124 unsigned int __fp_control_register; /* floating point control and status register */
126 fenv_t;
128 # elif defined __powerpc__
130 typedef double /* yuck! */ fenv_t; /* fpscr register */
132 # elif defined __riscv
134 typedef unsigned int fenv_t; /* fcsr register */
136 # elif defined __s390__ || defined __s390x__
138 typedef struct
140 unsigned int __fpc; /* fpc = floating point control register */
142 fenv_t;
144 # elif defined __sh__
146 typedef struct
148 unsigned int __fpscr; /* fpscr register */
150 fenv_t;
152 # elif defined __sparc
154 typedef unsigned long fenv_t; /* fsr = floating point state register */
156 #else
158 /* A dummy fallback. */
160 typedef unsigned long fenv_t;
162 # endif
164 # define FE_DFL_ENV ((const fenv_t *) (-1))
166 #else
168 # if !HAVE_FE_DFL_ENV
169 # undef FE_DFL_ENV
170 # define FE_DFL_ENV ((const fenv_t *) (-1))
171 # endif
173 #endif
175 #if @GNULIB_FEGETENV@
176 /* Stores the thread's current floating-point environment in *ENVP and
177 returns zero. Upon failure, it returns non-zero. */
178 # if @REPLACE_FEGETENV@ || (!@HAVE_FEGETENV@ && defined __FreeBSD__) /* has an inline definition */
179 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
180 # undef fegetenv
181 # define fegetenv rpl_fegetenv
182 # endif
183 _GL_FUNCDECL_RPL (fegetenv, int, (fenv_t *envp));
184 _GL_CXXALIAS_RPL (fegetenv, int, (fenv_t *envp));
185 # else
186 # if !@HAVE_FEGETENV@
187 _GL_FUNCDECL_SYS (fegetenv, int, (fenv_t *envp));
188 # endif
189 _GL_CXXALIAS_SYS (fegetenv, int, (fenv_t *envp));
190 # endif
191 _GL_CXXALIASWARN (fegetenv);
192 #endif
194 #if @GNULIB_FESETENV@
195 /* Activates the given object *ENVP as the thread's current floating-point
196 environment, without raising floating-point exceptions, and returns zero.
197 ENVP may be FE_DFL_ENV.
198 Upon failure, it returns non-zero. */
199 # if @REPLACE_FESETENV@ || (!@HAVE_FESETENV@ && defined __FreeBSD__) /* has an inline definition */
200 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
201 # undef fesetenv
202 # define fesetenv rpl_fesetenv
203 # endif
204 _GL_FUNCDECL_RPL (fesetenv, int, (fenv_t const *envp));
205 _GL_CXXALIAS_RPL (fesetenv, int, (fenv_t const *envp));
206 # else
207 # if !@HAVE_FESETENV@
208 _GL_FUNCDECL_SYS (fesetenv, int, (fenv_t const *envp));
209 # endif
210 _GL_CXXALIAS_SYS (fesetenv, int, (fenv_t const *envp));
211 # endif
212 _GL_CXXALIASWARN (fesetenv);
213 #endif
215 #if @GNULIB_FEUPDATEENV@
216 /* Activates the given object *ENVP as the thread's current floating-point
217 environment, raising exactly those floating-point exceptions that were
218 raised before, and returns zero.
219 ENVP may be FE_DFL_ENV.
220 Upon failure, it returns non-zero. */
221 # if @REPLACE_FEUPDATEENV@ || (!@HAVE_FEUPDATEENV@ && (defined __FreeBSD__ || defined _MSC_VER)) /* has an inline definition */
222 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
223 # undef feupdateenv
224 # define feupdateenv rpl_feupdateenv
225 # endif
226 _GL_FUNCDECL_RPL (feupdateenv, int, (fenv_t const *envp));
227 _GL_CXXALIAS_RPL (feupdateenv, int, (fenv_t const *envp));
228 # else
229 # if !@HAVE_FEUPDATEENV@
230 _GL_FUNCDECL_SYS (feupdateenv, int, (fenv_t const *envp));
231 # endif
232 _GL_CXXALIAS_SYS (feupdateenv, int, (fenv_t const *envp));
233 # endif
234 _GL_CXXALIASWARN (feupdateenv);
235 #endif
237 #if @GNULIB_FEHOLDEXCEPT@
238 /* Stores the thread's current floating-point environment in *ENVP, clears
239 the floating-point exception status flags, disables trapping for all
240 floating-point exceptions, and returns zero. Upon failure, it returns
241 non-zero. */
242 # if @REPLACE_FEHOLDEXCEPT@ || (!@HAVE_FEHOLDEXCEPT@ && defined __FreeBSD__) /* has an inline definition */
243 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
244 # undef feholdexcept
245 # define feholdexcept rpl_feholdexcept
246 # endif
247 _GL_FUNCDECL_RPL (feholdexcept, int, (fenv_t *envp));
248 _GL_CXXALIAS_RPL (feholdexcept, int, (fenv_t *envp));
249 # else
250 # if !@HAVE_FEHOLDEXCEPT@
251 _GL_FUNCDECL_SYS (feholdexcept, int, (fenv_t *envp));
252 # endif
253 _GL_CXXALIAS_SYS (feholdexcept, int, (fenv_t *envp));
254 # endif
255 _GL_CXXALIASWARN (feholdexcept);
256 #endif
259 /* ISO C 99 § 7.6.3 Rounding
260 ISO C 23 § 7.6.5 Rounding */
262 #if !@HAVE_FENV_H@
264 # if (defined __x86_64__ || defined _M_X64) || (defined __i386 || defined _M_IX86)
266 /* Attention: MSVC has different values for these macros! */
267 # define FE_TONEAREST (0 << 10)
268 # define FE_DOWNWARD (1 << 10)
269 # define FE_UPWARD (2 << 10)
270 # define FE_TOWARDZERO (3 << 10)
272 # elif defined __aarch64__ /* arm64 */
274 /* Attention: FreeBSD libc has these values shifted right by 22 bits! */
275 # define FE_TONEAREST (0 << 22)
276 # define FE_UPWARD (1 << 22)
277 # define FE_DOWNWARD (2 << 22)
278 # define FE_TOWARDZERO (3 << 22)
280 # elif defined __arm__
282 # define FE_TONEAREST (0 << 22)
283 # if !defined __SOFTFP__
284 # define FE_UPWARD (1 << 22)
285 # define FE_DOWNWARD (2 << 22)
286 # define FE_TOWARDZERO (3 << 22)
287 # endif
289 # elif defined __alpha
291 # define FE_TOWARDZERO 0
292 # define FE_DOWNWARD 1
293 # define FE_TONEAREST 2
294 # define FE_UPWARD 3
296 # elif defined __hppa
298 # define FE_TONEAREST (0 << 9)
299 # define FE_TOWARDZERO (1 << 9)
300 # define FE_UPWARD (2 << 9)
301 # define FE_DOWNWARD (3 << 9)
303 # elif defined __ia64__
305 # define FE_TONEAREST 0
306 # define FE_DOWNWARD 1
307 # define FE_UPWARD 2
308 # define FE_TOWARDZERO 3
310 # elif defined __m68k__
312 # define FE_TONEAREST (0 << 4)
313 # define FE_TOWARDZERO (1 << 4)
314 # define FE_DOWNWARD (2 << 4)
315 # define FE_UPWARD (3 << 4)
317 # elif defined __mips__
319 # define FE_TONEAREST 0
320 # define FE_TOWARDZERO 1
321 # define FE_UPWARD 2
322 # define FE_DOWNWARD 3
324 # elif defined __loongarch__
326 # define FE_TONEAREST (0 << 8)
327 # define FE_TOWARDZERO (1 << 8)
328 # define FE_UPWARD (2 << 8)
329 # define FE_DOWNWARD (3 << 8)
331 # elif defined __powerpc__
333 /* Attention: AIX has different values for these macros! */
334 # define FE_TONEAREST 0
335 # define FE_TOWARDZERO 1
336 # define FE_UPWARD 2
337 # define FE_DOWNWARD 3
339 # elif defined __riscv
341 /* Attention: FreeBSD libc has these values shifted left by 5 bits! */
342 # define FE_TONEAREST 0
343 # define FE_TOWARDZERO 1
344 # define FE_DOWNWARD 2
345 # define FE_UPWARD 3
346 # if 0 /* non-standard */
347 # define FE_TONEARESTMAXMAGNITUDE 4
348 # endif
350 # elif defined __s390__ || defined __s390x__
352 # define FE_TONEAREST 0
353 # define FE_TOWARDZERO 1
354 # define FE_UPWARD 2
355 # define FE_DOWNWARD 3
357 # elif defined __sh__
359 # define FE_TONEAREST 0
360 # define FE_TOWARDZERO 1
362 # elif defined __sparc
364 /* Attention: FreeBSD libc has these values shifted right by 30 bits! */
365 # define FE_TONEAREST (0U << 30)
366 # define FE_TOWARDZERO (1U << 30)
367 # define FE_UPWARD (2U << 30)
368 # define FE_DOWNWARD (3U << 30)
370 #else
372 /* A dummy fallback. */
374 # define FE_TONEAREST 0
376 # endif
378 #endif
380 #if @GNULIB_FEGETROUND@
381 /* Returns the current rounding direction. */
382 # if @REPLACE_FEGETROUND@ || (!@HAVE_FEGETROUND@ && (defined __GLIBC__ || defined __FreeBSD__)) /* has an inline definition */
383 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
384 # undef fegetround
385 # define fegetround rpl_fegetround
386 # endif
387 _GL_FUNCDECL_RPL (fegetround, int, (void));
388 _GL_CXXALIAS_RPL (fegetround, int, (void));
389 # else
390 # if !@HAVE_FEGETROUND@
391 _GL_FUNCDECL_SYS (fegetround, int, (void));
392 # endif
393 _GL_CXXALIAS_SYS (fegetround, int, (void));
394 # endif
395 _GL_CXXALIASWARN (fegetround);
396 #endif
398 #if @GNULIB_FESETROUND@
399 /* Sets the rounding direction of the current thread.
400 Returns zero if the argument is valid and the operation was thus successful.
401 Returns non-zero upon failure. */
402 # if @REPLACE_FESETROUND@ || (!@HAVE_FESETROUND@ && defined __FreeBSD__) /* has an inline definition */
403 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
404 # undef fesetround
405 # define fesetround rpl_fesetround
406 # endif
407 _GL_FUNCDECL_RPL (fesetround, int, (int rounding_direction));
408 _GL_CXXALIAS_RPL (fesetround, int, (int rounding_direction));
409 # else
410 # if !@HAVE_FESETROUND@
411 _GL_FUNCDECL_SYS (fesetround, int, (int rounding_direction));
412 # endif
413 _GL_CXXALIAS_SYS (fesetround, int, (int rounding_direction));
414 # endif
415 _GL_CXXALIASWARN (fesetround);
416 #endif
419 /* ISO C 99 § 7.6.2 Floating-point exceptions
420 ISO C 23 § 7.6.4 Floating-point exceptions
421 API without fexcept_t */
423 #if !@HAVE_FENV_H@
425 # if (defined __x86_64__ || defined _M_X64) || (defined __i386 || defined _M_IX86)
427 /* Attention: MSVC has different values for these macros! */
428 # define FE_INVALID (1 << 0)
429 # if 0 /* non-standard */
430 # define FE_DENORMAL (1 << 1)
431 # endif
432 # define FE_DIVBYZERO (1 << 2)
433 # define FE_OVERFLOW (1 << 3)
434 # define FE_UNDERFLOW (1 << 4)
435 # define FE_INEXACT (1 << 5)
437 # elif defined __aarch64__ /* arm64 */ || defined __arm__
439 # define FE_INVALID (1U << 0)
440 # define FE_DIVBYZERO (1U << 1)
441 # define FE_OVERFLOW (1U << 2)
442 # define FE_UNDERFLOW (1U << 3)
443 # define FE_INEXACT (1U << 4)
445 # elif defined __alpha
447 /* Attention: The *BSDs have these values shifted right by 17 bits! */
448 # define FE_INVALID (1UL << 17)
449 # define FE_DIVBYZERO (1UL << 18)
450 # define FE_OVERFLOW (1UL << 19)
451 # define FE_UNDERFLOW (1UL << 20)
452 # define FE_INEXACT (1UL << 21)
453 # if 0 /* non-standard */
454 # define FE_DENORMAL (1UL << 22)
455 # endif
457 # elif defined __hppa
459 # define FE_INEXACT (1U << 0)
460 # define FE_UNDERFLOW (1U << 1)
461 # define FE_OVERFLOW (1U << 2)
462 # define FE_DIVBYZERO (1U << 3)
463 # define FE_INVALID (1U << 4)
465 # elif defined __ia64__
467 # define FE_INVALID (1UL << 0)
468 # if 0 /* non-standard */
469 # define FE_UNNORMAL (1UL << 1)
470 # endif
471 # define FE_DIVBYZERO (1UL << 2)
472 # define FE_OVERFLOW (1UL << 3)
473 # define FE_UNDERFLOW (1UL << 4)
474 # define FE_INEXACT (1UL << 5)
476 # elif defined __m68k__
478 # define FE_INEXACT (1U << 3)
479 # define FE_DIVBYZERO (1U << 4)
480 # define FE_UNDERFLOW (1U << 5)
481 # define FE_OVERFLOW (1U << 6)
482 # define FE_INVALID (1U << 7)
484 # elif defined __mips__
486 # define FE_INEXACT (1 << 2)
487 # define FE_UNDERFLOW (1 << 3)
488 # define FE_OVERFLOW (1 << 4)
489 # define FE_DIVBYZERO (1 << 5)
490 # define FE_INVALID (1 << 6)
492 # elif defined __loongarch__
494 # define FE_INEXACT (1U << 16)
495 # define FE_UNDERFLOW (1U << 17)
496 # define FE_OVERFLOW (1U << 18)
497 # define FE_DIVBYZERO (1U << 19)
498 # define FE_INVALID (1U << 20)
500 # elif defined __powerpc__
502 # define FE_INEXACT (1U << 25)
503 # define FE_DIVBYZERO (1U << 26)
504 # define FE_UNDERFLOW (1U << 27)
505 # define FE_OVERFLOW (1U << 28)
506 # define FE_INVALID (1U << 29)
508 # elif defined __riscv
510 # define FE_INEXACT (1U << 0)
511 # define FE_UNDERFLOW (1U << 1)
512 # define FE_OVERFLOW (1U << 2)
513 # define FE_DIVBYZERO (1U << 3)
514 # define FE_INVALID (1U << 4)
516 # elif defined __s390__ || defined __s390x__
518 /* Attention: musl libc has these values shifted left by 16 bits! */
519 # define FE_INEXACT (1U << 3)
520 # define FE_UNDERFLOW (1U << 4)
521 # define FE_OVERFLOW (1U << 5)
522 # define FE_DIVBYZERO (1U << 6)
523 # define FE_INVALID (1U << 7)
525 # elif defined __sh__
527 # define FE_INEXACT (1 << 2)
528 # define FE_UNDERFLOW (1 << 3)
529 # define FE_OVERFLOW (1 << 4)
530 # define FE_DIVBYZERO (1 << 5)
531 # define FE_INVALID (1 << 6)
533 # elif defined __sparc
535 /* Attention: Solaris has these values shifted right by 5 bits! */
536 # define FE_INEXACT (1UL << 5)
537 # define FE_DIVBYZERO (1UL << 6)
538 # define FE_UNDERFLOW (1UL << 7)
539 # define FE_OVERFLOW (1UL << 8)
540 # define FE_INVALID (1UL << 9)
542 # endif
544 # define FE_ALL_EXCEPT \
545 (FE_DIVBYZERO | FE_INEXACT | FE_INVALID | FE_OVERFLOW | FE_UNDERFLOW)
547 #endif
549 #if @GNULIB_FECLEAREXCEPT@
550 /* Clears the specified exception flags, and returns 0.
551 Upon failure, it returns non-zero. */
552 # if @REPLACE_FECLEAREXCEPT@ || (!@HAVE_FECLEAREXCEPT@ && (defined __GLIBC__ || defined __FreeBSD__)) /* has an inline definition */
553 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
554 # undef feclearexcept
555 # define feclearexcept rpl_feclearexcept
556 # endif
557 _GL_FUNCDECL_RPL (feclearexcept, int, (int exceptions));
558 _GL_CXXALIAS_RPL (feclearexcept, int, (int exceptions));
559 # else
560 # if !@HAVE_FECLEAREXCEPT@
561 _GL_FUNCDECL_SYS (feclearexcept, int, (int exceptions));
562 # endif
563 _GL_CXXALIAS_SYS (feclearexcept, int, (int exceptions));
564 # endif
565 _GL_CXXALIASWARN (feclearexcept);
566 #endif
568 #if @GNULIB_FERAISEEXCEPT@
569 /* Sets the specified exception flags, triggering handlers or traps if enabled,
570 and returns 0. Upon failure, it returns non-zero. */
571 # if @REPLACE_FERAISEEXCEPT@ || (!@HAVE_FERAISEEXCEPT@ && (defined __GLIBC__ || defined __FreeBSD__ || defined _MSC_VER)) /* has an inline definition */
572 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
573 # undef feraiseexcept
574 # define feraiseexcept rpl_feraiseexcept
575 # endif
576 _GL_FUNCDECL_RPL (feraiseexcept, int, (int exceptions));
577 _GL_CXXALIAS_RPL (feraiseexcept, int, (int exceptions));
578 # else
579 # if !@HAVE_FERAISEEXCEPT@
580 _GL_FUNCDECL_SYS (feraiseexcept, int, (int exceptions));
581 # endif
582 _GL_CXXALIAS_SYS (feraiseexcept, int, (int exceptions));
583 # endif
584 _GL_CXXALIASWARN (feraiseexcept);
585 #endif
587 #if @GNULIB_FETESTEXCEPT@
588 /* Returns a bitmask of those exception flags among EXCEPTIONS that are
589 currently set. */
590 # if @REPLACE_FETESTEXCEPT@ || (!@HAVE_FETESTEXCEPT@ && defined __FreeBSD__) /* has an inline definition */
591 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
592 # undef fetestexcept
593 # define fetestexcept rpl_fetestexcept
594 # endif
595 _GL_FUNCDECL_RPL (fetestexcept, int, (int exceptions));
596 _GL_CXXALIAS_RPL (fetestexcept, int, (int exceptions));
597 # else
598 # if !@HAVE_FETESTEXCEPT@
599 _GL_FUNCDECL_SYS (fetestexcept, int, (int exceptions));
600 # endif
601 _GL_CXXALIAS_SYS (fetestexcept, int, (int exceptions));
602 # endif
603 _GL_CXXALIASWARN (fetestexcept);
604 #endif
606 /* Added in ISO C 23 § 7.6.4 Floating-point exceptions. */
608 #if @GNULIB_FESETEXCEPT@
609 /* Sets the specified exception flags, without triggering handlers or traps,
610 and returns 0. Upon failure, it returns non-zero. */
611 # if @REPLACE_FESETEXCEPT@
612 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
613 # undef fesetexcept
614 # define fesetexcept rpl_fesetexcept
615 # endif
616 _GL_FUNCDECL_RPL (fesetexcept, int, (int exceptions));
617 _GL_CXXALIAS_RPL (fesetexcept, int, (int exceptions));
618 # else
619 # if !@HAVE_FESETEXCEPT@
620 _GL_FUNCDECL_SYS (fesetexcept, int, (int exceptions));
621 # endif
622 _GL_CXXALIAS_SYS (fesetexcept, int, (int exceptions));
623 # endif
624 _GL_CXXALIASWARN (fesetexcept);
625 #elif defined GNULIB_POSIXCHECK
626 # undef fesetexcept
627 # if HAVE_RAW_DECL_FESETEXCEPT
628 _GL_WARN_ON_USE (fesetexcept, "fesetexcept is unportable - "
629 "use gnulib module fenv-exceptions-tracking-c23 for portability");
630 # endif
631 #endif
634 /* GNU extensions. */
636 #if @GNULIB_FEENABLEEXCEPT@
637 /* Enables trapping for the floating-point exceptions denoted by the bit mask
638 EXCEPTIONS.
639 Returns the bit mask of floating-point exceptions for which trapping was
640 enabled before the call, or -1 upon failure.
641 Note: This function is a misnomer. It does not enable the specified
642 floating-point exceptions; it enables *trapping* on them. It should better
643 be called 'feenabletraps'. */
644 # if @REPLACE_FEENABLEEXCEPT@ || (!@HAVE_FEENABLEEXCEPT@ && defined __FreeBSD__) /* has an inline definition */
645 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
646 # undef feenableexcept
647 # define feenableexcept rpl_feenableexcept
648 # endif
649 _GL_FUNCDECL_RPL (feenableexcept, int, (int exceptions));
650 _GL_CXXALIAS_RPL (feenableexcept, int, (int exceptions));
651 # else
652 # if !@HAVE_FEENABLEEXCEPT@
653 _GL_FUNCDECL_SYS (feenableexcept, int, (int exceptions));
654 # endif
655 _GL_CXXALIAS_SYS (feenableexcept, int, (int exceptions));
656 # endif
657 _GL_CXXALIASWARN (feenableexcept);
658 #elif defined GNULIB_POSIXCHECK
659 # undef feenableexcept
660 # if HAVE_RAW_DECL_FEENABLEEXCEPT
661 _GL_WARN_ON_USE (feenableexcept, "feenableexcept is unportable - "
662 "use gnulib module fenv-exceptions-trapping for portability");
663 # endif
664 #endif
666 #if @GNULIB_FEDISABLEEXCEPT@
667 /* Disables trapping for the floating-point exceptions denoted by the bit mask
668 EXCEPTIONS.
669 Returns the bit mask of floating-point exceptions for which trapping was
670 enabled before the call, or -1 upon failure.
671 Note: This function is a misnomer. It does not disable the specified
672 floating-point exceptions; it disables *trapping* on them. It should better
673 be called 'fedisabletraps'. */
674 # if @REPLACE_FEDISABLEEXCEPT@ || (!@HAVE_FEDISABLEEXCEPT@ && defined __FreeBSD__) /* has an inline definition */
675 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
676 # undef fedisableexcept
677 # define fedisableexcept rpl_fedisableexcept
678 # endif
679 _GL_FUNCDECL_RPL (fedisableexcept, int, (int exceptions));
680 _GL_CXXALIAS_RPL (fedisableexcept, int, (int exceptions));
681 # else
682 # if !@HAVE_FEDISABLEEXCEPT@
683 _GL_FUNCDECL_SYS (fedisableexcept, int, (int exceptions));
684 # endif
685 _GL_CXXALIAS_SYS (fedisableexcept, int, (int exceptions));
686 # endif
687 _GL_CXXALIASWARN (fedisableexcept);
688 #elif defined GNULIB_POSIXCHECK
689 # undef fedisableexcept
690 # if HAVE_RAW_DECL_FEDISABLEEXCEPT
691 _GL_WARN_ON_USE (fedisableexcept, "fedisableexcept is unportable - "
692 "use gnulib module fenv-exceptions-trapping for portability");
693 # endif
694 #endif
696 #if @GNULIB_FEGETEXCEPT@
697 /* Returns the bit mask of floating-point exceptions for which trapping is
698 enabled.
699 Note: This function is an even bigger misnomer:
700 - It does not test for the specified floating-point exceptions;
701 fetestexcept() does that. It tests whether *trapping* on these
702 exceptions is enabled.
703 - It is in no way the opposite of fesetexcept().
704 It should better be called 'fegettraps'. */
705 # if @REPLACE_FEGETEXCEPT@ || (!@HAVE_FEGETEXCEPT@ && defined __FreeBSD__) /* has an inline definition */
706 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
707 # undef fegetexcept
708 # define fegetexcept rpl_fegetexcept
709 # endif
710 _GL_FUNCDECL_RPL (fegetexcept, int, (void));
711 _GL_CXXALIAS_RPL (fegetexcept, int, (void));
712 # else
713 # if !@HAVE_FEGETEXCEPT@
714 _GL_FUNCDECL_SYS (fegetexcept, int, (void));
715 # endif
716 _GL_CXXALIAS_SYS (fegetexcept, int, (void));
717 # endif
718 _GL_CXXALIASWARN (fegetexcept);
719 #elif defined GNULIB_POSIXCHECK
720 # undef fegetexcept
721 # if HAVE_RAW_DECL_FEGETEXCEPT
722 _GL_WARN_ON_USE (fegetexcept, "fegetexcept is unportable - "
723 "use gnulib module fenv-exceptions-trapping for portability");
724 # endif
725 #endif
728 /* ISO C 99 § 7.6.2 Floating-point exceptions
729 ISO C 23 § 7.6.4 Floating-point exceptions
730 API with fexcept_t.
731 The return type changed from 'void' to 'int' in ISO C 11. */
733 #if !@HAVE_FENV_H@
735 # if (defined __x86_64__ || defined _M_X64) || (defined __i386 || defined _M_IX86)
737 typedef unsigned short fexcept_t;
739 # elif defined __aarch64__ /* arm64 */ || defined __arm__
741 typedef unsigned int fexcept_t;
743 # elif defined __alpha
745 typedef unsigned long fexcept_t;
747 # elif defined __hppa
749 typedef unsigned int fexcept_t;
751 # elif defined __ia64__
753 typedef unsigned long fexcept_t;
755 # elif defined __m68k__
757 typedef unsigned int fexcept_t;
759 # elif defined __mips__
761 typedef unsigned short fexcept_t;
763 # elif defined __loongarch__
765 typedef unsigned int fexcept_t;
767 # elif defined __powerpc__
769 typedef unsigned int fexcept_t;
771 # elif defined __riscv
773 typedef unsigned int fexcept_t;
775 # elif defined __s390__ || defined __s390x__
777 typedef unsigned int fexcept_t;
779 # elif defined __sh__
781 typedef unsigned short fexcept_t;
783 # elif defined __sparc
785 typedef unsigned long fexcept_t;
787 # else
789 /* A dummy fallback. */
791 typedef unsigned long fexcept_t;
793 # endif
795 #endif
797 #if @GNULIB_FEGETEXCEPTFLAG@
798 /* Stores the current floating-point exception status flags denoted
799 by EXCEPTIONS in *SAVED_FLAGS. */
800 # if @REPLACE_FEGETEXCEPTFLAG@ || (!@HAVE_FEGETEXCEPTFLAG@ && defined __FreeBSD__) /* has an inline definition */
801 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
802 # undef fegetexceptflag
803 # define fegetexceptflag rpl_fegetexceptflag
804 # endif
805 _GL_FUNCDECL_RPL (fegetexceptflag, int,
806 (fexcept_t *saved_flags, int exceptions));
807 _GL_CXXALIAS_RPL (fegetexceptflag, int,
808 (fexcept_t *saved_flags, int exceptions));
809 # else
810 # if !@HAVE_FEGETEXCEPTFLAG@
811 _GL_FUNCDECL_SYS (fegetexceptflag, int,
812 (fexcept_t *saved_flags, int exceptions));
813 # endif
814 _GL_CXXALIAS_SYS (fegetexceptflag, int,
815 (fexcept_t *saved_flags, int exceptions));
816 # endif
817 _GL_CXXALIASWARN (fegetexceptflag);
818 #endif
820 #if @GNULIB_FESETEXCEPTFLAG@
821 /* Copies the flags denoted by EXCEPTIONS from *SAVED_FLAGS to the
822 floating-point exception status flags. */
823 # if @REPLACE_FESETEXCEPTFLAG@ || (!@HAVE_FESETEXCEPTFLAG@ && defined __FreeBSD__) /* has an inline definition */
824 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
825 # undef fesetexceptflag
826 # define fesetexceptflag rpl_fesetexceptflag
827 # endif
828 _GL_FUNCDECL_RPL (fesetexceptflag, int,
829 (fexcept_t const *saved_flags, int exceptions));
830 _GL_CXXALIAS_RPL (fesetexceptflag, int,
831 (fexcept_t const *saved_flags, int exceptions));
832 # else
833 # if !@HAVE_FESETEXCEPTFLAG@
834 _GL_FUNCDECL_SYS (fesetexceptflag, int,
835 (fexcept_t const *saved_flags, int exceptions));
836 # endif
837 _GL_CXXALIAS_SYS (fesetexceptflag, int,
838 (fexcept_t const *saved_flags, int exceptions));
839 # endif
840 _GL_CXXALIASWARN (fesetexceptflag);
841 #endif
843 /* Added in ISO C 23 § 7.6.4 Floating-point exceptions. */
845 #if @GNULIB_FETESTEXCEPTFLAG@
846 /* Copies the flags denoted by EXCEPTIONS from *SAVED_FLAGS to the
847 floating-point exception status flags. */
848 # if 0
849 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
850 # undef fetestexceptflag
851 # define fetestexceptflag rpl_fetestexceptflag
852 # endif
853 _GL_FUNCDECL_RPL (fetestexceptflag, int,
854 (fexcept_t const *saved_flags, int exceptions));
855 _GL_CXXALIAS_RPL (fetestexceptflag, int,
856 (fexcept_t const *saved_flags, int exceptions));
857 # else
858 # if !@HAVE_FETESTEXCEPTFLAG@
859 _GL_FUNCDECL_SYS (fetestexceptflag, int,
860 (fexcept_t const *saved_flags, int exceptions));
861 # endif
862 _GL_CXXALIAS_SYS (fetestexceptflag, int,
863 (fexcept_t const *saved_flags, int exceptions));
864 # endif
865 _GL_CXXALIASWARN (fetestexceptflag);
866 #elif defined GNULIB_POSIXCHECK
867 # undef fetestexceptflag
868 # if HAVE_RAW_DECL_FETESTEXCEPTFLAG
869 _GL_WARN_ON_USE (fetestexceptflag, "fetestexceptflag is unportable - "
870 "use gnulib module fenv-exceptions-state-c23 for portability");
871 # endif
872 #endif
875 #endif /* _@GUARD_PREFIX@_FENV_H */
876 #endif /* _@GUARD_PREFIX@_FENV_H */