1 /* Macros for signalling 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_SNAN_H
18 #define _SIGNED_SNAN_H
19
20 #include "signed-nan.h"
21 #include "snan.h"
22
23
24 #if HAVE_SNANF
25
26 /* Returns a signalling 'float' NaN with sign bit == 0 in memory. */
27 _GL_UNUSED static memory_float
28 memory_positive_SNaNf ()
29 {
30 return construct_memory_SNaNf (positive_NaNf ());
31 }
32
33 /* Returns a signalling 'float' NaN with sign bit == 1 in memory. */
34 _GL_UNUSED static memory_float
35 memory_negative_SNaNf ()
36 {
37 return construct_memory_SNaNf (negative_NaNf ());
38 }
39
40 /* Note: On 32-bit x86 processors, as well as on x86_64 processors with
41 CC="gcc -mfpmath=387", the following functions may return a quiet NaN
42 instead. Use the functions with 'memory_' prefix if you need to avoid this.
43 See <https://lists.gnu.org/archive/html/bug-gnulib/2023-10/msg00060.html>
44 for details. */
45
46 /* Returns a signalling 'float' NaN with sign bit == 0. */
47 _GL_UNUSED static float
48 positive_SNaNf ()
49 {
50 return memory_positive_SNaNf ().value;
51 }
52
53 /* Returns a signalling 'float' NaN with sign bit == 1. */
54 _GL_UNUSED static float
55 negative_SNaNf ()
56 {
57 return memory_negative_SNaNf ().value;
58 }
59
60 #endif
61
62
63 #if HAVE_SNAND
64
65 /* Returns a signalling 'double' NaN with sign bit == 0 in memory. */
66 _GL_UNUSED static memory_double
67 memory_positive_SNaNd ()
68 {
69 return construct_memory_SNaNd (positive_NaNd ());
70 }
71
72 /* Returns a signalling 'double' NaN with sign bit == 1 in memory. */
73 _GL_UNUSED static memory_double
74 memory_negative_SNaNd ()
75 {
76 return construct_memory_SNaNd (negative_NaNd ());
77 }
78
79 /* Note: On 32-bit x86 processors, as well as on x86_64 processors with
80 CC="gcc -mfpmath=387", the following functions may return a quiet NaN
81 instead. Use the functions with 'memory_' prefix if you need to avoid this.
82 See <https://lists.gnu.org/archive/html/bug-gnulib/2023-10/msg00060.html>
83 for details. */
84
85 /* Returns a signalling 'double' NaN with sign bit == 0. */
86 _GL_UNUSED static double
87 positive_SNaNd ()
88 {
89 return memory_positive_SNaNd ().value;
90 }
91
92 /* Returns a signalling 'double' NaN with sign bit == 1. */
93 _GL_UNUSED static double
94 negative_SNaNd ()
95 {
96 return memory_negative_SNaNd ().value;
97 }
98
99 #endif
100
101
102 #if HAVE_SNANL
103
104 /* Returns a signalling 'long double' NaN with sign bit == 0 in memory. */
105 _GL_UNUSED static memory_long_double
106 memory_positive_SNaNl ()
107 {
108 return construct_memory_SNaNl (positive_NaNl ());
109 }
110
111 /* Returns a signalling 'long double' NaN with sign bit == 1 in memory. */
112 _GL_UNUSED static memory_long_double
113 memory_negative_SNaNl ()
114 {
115 return construct_memory_SNaNl (negative_NaNl ());
116 }
117
118 /* Note: On 32-bit x86 processors, as well as on x86_64 processors with
119 CC="gcc -mfpmath=387", if HAVE_SAME_LONG_DOUBLE_AS_DOUBLE is 1, the
120 following functions may return a quiet NaN instead. Use the functions
121 with 'memory_' prefix if you need to avoid this. See
122 <https://lists.gnu.org/archive/html/bug-gnulib/2023-10/msg00060.html>
123 for details. */
124
125 /* Returns a signalling 'long double' NaN with sign bit == 0. */
126 _GL_UNUSED static long double
127 positive_SNaNl ()
128 {
129 return memory_positive_SNaNl ().value;
130 }
131
132 /* Returns a signalling 'long double' NaN with sign bit == 1. */
133 _GL_UNUSED static long double
134 negative_SNaNl ()
135 {
136 return memory_negative_SNaNl ().value;
137 }
138
139 #endif
140
141
142 #endif /* _SIGNED_SNAN_H */