Debian Codegraph @

gnulib-tests/signed-snan.h

raw
1 /* Macros for signalling not-a-number.
2 Copyright (C) 2023-2025 Free Software Foundation, Inc.
3
4 This file is free software: you can redistribute it and/or modify
5 it under the terms of the GNU Lesser General Public License as
6 published by the Free Software Foundation; either version 2.1 of the
7 License, or (at your option) any later version.
8
9 This file 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 Lesser General Public License for more details.
13
14 You should have received a copy of the GNU Lesser 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 #ifdef __cplusplus
24 extern "C" {
25 #endif
26
27
28 #if HAVE_SNANF
29
30 /* Returns a signalling 'float' NaN with sign bit == 0 in memory. */
31 _GL_UNUSED static memory_float
32 memory_positive_SNaNf ()
33 {
34 return construct_memory_SNaNf (positive_NaNf ());
35 }
36
37 /* Returns a signalling 'float' NaN with sign bit == 1 in memory. */
38 _GL_UNUSED static memory_float
39 memory_negative_SNaNf ()
40 {
41 return construct_memory_SNaNf (negative_NaNf ());
42 }
43
44 /* Note: On 32-bit x86 processors, as well as on x86_64 processors with
45 CC="gcc -mfpmath=387", the following functions may return a quiet NaN
46 instead. Use the functions with 'memory_' prefix if you need to avoid this.
47 See <https://lists.gnu.org/archive/html/bug-gnulib/2023-10/msg00060.html>
48 for details. */
49
50 /* Returns a signalling 'float' NaN with sign bit == 0. */
51 _GL_UNUSED static float
52 positive_SNaNf ()
53 {
54 return memory_positive_SNaNf ().value;
55 }
56
57 /* Returns a signalling 'float' NaN with sign bit == 1. */
58 _GL_UNUSED static float
59 negative_SNaNf ()
60 {
61 return memory_negative_SNaNf ().value;
62 }
63
64 #endif
65
66
67 #if HAVE_SNAND
68
69 /* Returns a signalling 'double' NaN with sign bit == 0 in memory. */
70 _GL_UNUSED static memory_double
71 memory_positive_SNaNd ()
72 {
73 return construct_memory_SNaNd (positive_NaNd ());
74 }
75
76 /* Returns a signalling 'double' NaN with sign bit == 1 in memory. */
77 _GL_UNUSED static memory_double
78 memory_negative_SNaNd ()
79 {
80 return construct_memory_SNaNd (negative_NaNd ());
81 }
82
83 /* Note: On 32-bit x86 processors, as well as on x86_64 processors with
84 CC="gcc -mfpmath=387", the following functions may return a quiet NaN
85 instead. Use the functions with 'memory_' prefix if you need to avoid this.
86 See <https://lists.gnu.org/archive/html/bug-gnulib/2023-10/msg00060.html>
87 for details. */
88
89 /* Returns a signalling 'double' NaN with sign bit == 0. */
90 _GL_UNUSED static double
91 positive_SNaNd ()
92 {
93 return memory_positive_SNaNd ().value;
94 }
95
96 /* Returns a signalling 'double' NaN with sign bit == 1. */
97 _GL_UNUSED static double
98 negative_SNaNd ()
99 {
100 return memory_negative_SNaNd ().value;
101 }
102
103 #endif
104
105
106 #if HAVE_SNANL
107
108 /* Returns a signalling 'long double' NaN with sign bit == 0 in memory. */
109 _GL_UNUSED static memory_long_double
110 memory_positive_SNaNl ()
111 {
112 return construct_memory_SNaNl (positive_NaNl ());
113 }
114
115 /* Returns a signalling 'long double' NaN with sign bit == 1 in memory. */
116 _GL_UNUSED static memory_long_double
117 memory_negative_SNaNl ()
118 {
119 return construct_memory_SNaNl (negative_NaNl ());
120 }
121
122 /* Note: On 32-bit x86 processors, as well as on x86_64 processors with
123 CC="gcc -mfpmath=387", if HAVE_SAME_LONG_DOUBLE_AS_DOUBLE is 1, the
124 following functions may return a quiet NaN instead. Use the functions
125 with 'memory_' prefix if you need to avoid this. See
126 <https://lists.gnu.org/archive/html/bug-gnulib/2023-10/msg00060.html>
127 for details. */
128
129 /* Returns a signalling 'long double' NaN with sign bit == 0. */
130 _GL_UNUSED static long double
131 positive_SNaNl ()
132 {
133 return memory_positive_SNaNl ().value;
134 }
135
136 /* Returns a signalling 'long double' NaN with sign bit == 1. */
137 _GL_UNUSED static long double
138 negative_SNaNl ()
139 {
140 return memory_negative_SNaNl ().value;
141 }
142
143 #endif
144
145
146 #ifdef __cplusplus
147 }
148 #endif
149
150 #endif /* _SIGNED_SNAN_H */