1 /* Macros for quiet not-a-number.
2 Copyright (C) 2023 Free Software Foundation, Inc.
3
4 This program is free software: you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation, either version 3 of the License, or
7 (at your option) any later version.
8
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
13
14 You should have received a copy of the GNU General Public License
15 along with this program. If not, see <https://www.gnu.org/licenses/>. */
16
17 #ifndef _SIGNED_NAN_H
18 #define _SIGNED_NAN_H
19
20 #include <math.h>
21
22 #include "nan.h"
23
24
25 /* Returns a quiet 'float' NaN with sign bit == 0. */
26 _GL_UNUSED static float
27 positive_NaNf ()
28 {
29 /* 'volatile' works around a GCC bug:
30 <https://gcc.gnu.org/bugzilla/show_bug.cgi?id=111655> */
31 float volatile nan = NaNf ();
32 return (signbit (nan) ? - nan : nan);
33 }
34
35 /* Returns a quiet 'float' NaN with sign bit == 1. */
36 _GL_UNUSED static float
37 negative_NaNf ()
38 {
39 /* 'volatile' works around a GCC bug:
40 <https://gcc.gnu.org/bugzilla/show_bug.cgi?id=111655> */
41 float volatile nan = NaNf ();
42 return (signbit (nan) ? nan : - nan);
43 }
44
45
46 /* Returns a quiet 'double' NaN with sign bit == 0. */
47 _GL_UNUSED static double
48 positive_NaNd ()
49 {
50 /* 'volatile' works around a GCC bug:
51 <https://gcc.gnu.org/bugzilla/show_bug.cgi?id=111655> */
52 double volatile nan = NaNd ();
53 return (signbit (nan) ? - nan : nan);
54 }
55
56 /* Returns a quiet 'double' NaN with sign bit == 1. */
57 _GL_UNUSED static double
58 negative_NaNd ()
59 {
60 /* 'volatile' works around a GCC bug:
61 <https://gcc.gnu.org/bugzilla/show_bug.cgi?id=111655> */
62 double volatile nan = NaNd ();
63 return (signbit (nan) ? nan : - nan);
64 }
65
66
67 /* Returns a quiet 'long double' NaN with sign bit == 0. */
68 _GL_UNUSED static long double
69 positive_NaNl ()
70 {
71 /* 'volatile' works around a GCC bug:
72 <https://gcc.gnu.org/bugzilla/show_bug.cgi?id=111655> */
73 long double volatile nan = NaNl ();
74 return (signbit (nan) ? - nan : nan);
75 }
76
77 /* Returns a quiet 'long double' NaN with sign bit == 1. */
78 _GL_UNUSED static long double
79 negative_NaNl ()
80 {
81 /* 'volatile' works around a GCC bug:
82 <https://gcc.gnu.org/bugzilla/show_bug.cgi?id=111655> */
83 long double volatile nan = NaNl ();
84 return (signbit (nan) ? nan : - nan);
85 }
86
87
88 #endif /* _SIGNED_NAN_H */