xref: /freebsd/contrib/llvm-project/clang/lib/Headers/float.h (revision 0fca6ea1d4eea4c934cfff25ac9ee8ad6fe95583)
1 /*===---- float.h - Characteristics of floating point types ----------------===
2  *
3  * Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4  * See https://llvm.org/LICENSE.txt for license information.
5  * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6  *
7  *===-----------------------------------------------------------------------===
8  */
9 
10 #ifndef __CLANG_FLOAT_H
11 #define __CLANG_FLOAT_H
12 
13 #if defined(__MVS__) && __has_include_next(<float.h>)
14 #include_next <float.h>
15 #else
16 
17 /* If we're on MinGW, fall back to the system's float.h, which might have
18  * additional definitions provided for Windows.
19  * For more details see http://msdn.microsoft.com/en-us/library/y0ybw9fy.aspx
20  *
21  * Also fall back on Darwin and AIX to allow additional definitions and
22  * implementation-defined values.
23  */
24 #if (defined(__APPLE__) || defined(__MINGW32__) || defined(_MSC_VER) ||        \
25      defined(_AIX)) &&                                                         \
26     __STDC_HOSTED__ && __has_include_next(<float.h>)
27 
28 /* Prior to Apple's 10.7 SDK, float.h SDK header used to apply an extra level
29  * of #include_next<float.h> to keep Metrowerks compilers happy. Avoid this
30  * extra indirection.
31  */
32 #ifdef __APPLE__
33 #define _FLOAT_H_
34 #endif
35 
36 #  include_next <float.h>
37 
38 /* Undefine anything that we'll be redefining below. */
39 #  undef FLT_EVAL_METHOD
40 #  undef FLT_ROUNDS
41 #  undef FLT_RADIX
42 #  undef FLT_MANT_DIG
43 #  undef DBL_MANT_DIG
44 #  undef LDBL_MANT_DIG
45 #if (defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L) ||              \
46     !defined(__STRICT_ANSI__) ||                                               \
47     (defined(__cplusplus) && __cplusplus >= 201103L) ||                        \
48     (__STDC_HOSTED__ && defined(_AIX) && defined(_ALL_SOURCE))
49 #    undef DECIMAL_DIG
50 #  endif
51 #  undef FLT_DIG
52 #  undef DBL_DIG
53 #  undef LDBL_DIG
54 #  undef FLT_MIN_EXP
55 #  undef DBL_MIN_EXP
56 #  undef LDBL_MIN_EXP
57 #  undef FLT_MIN_10_EXP
58 #  undef DBL_MIN_10_EXP
59 #  undef LDBL_MIN_10_EXP
60 #  undef FLT_MAX_EXP
61 #  undef DBL_MAX_EXP
62 #  undef LDBL_MAX_EXP
63 #  undef FLT_MAX_10_EXP
64 #  undef DBL_MAX_10_EXP
65 #  undef LDBL_MAX_10_EXP
66 #  undef FLT_MAX
67 #  undef DBL_MAX
68 #  undef LDBL_MAX
69 #  undef FLT_EPSILON
70 #  undef DBL_EPSILON
71 #  undef LDBL_EPSILON
72 #  undef FLT_MIN
73 #  undef DBL_MIN
74 #  undef LDBL_MIN
75 #if (defined(__STDC_VERSION__) && __STDC_VERSION__ >= 201112L) ||              \
76     !defined(__STRICT_ANSI__) ||                                               \
77     (defined(__cplusplus) && __cplusplus >= 201703L) ||                        \
78     (__STDC_HOSTED__ && defined(_AIX) && defined(_ALL_SOURCE))
79 #    undef FLT_TRUE_MIN
80 #    undef DBL_TRUE_MIN
81 #    undef LDBL_TRUE_MIN
82 #    undef FLT_DECIMAL_DIG
83 #    undef DBL_DECIMAL_DIG
84 #    undef LDBL_DECIMAL_DIG
85 #    undef FLT_HAS_SUBNORM
86 #    undef DBL_HAS_SUBNORM
87 #    undef LDBL_HAS_SUBNORM
88 #  endif
89 #if (defined(__STDC_VERSION__) && __STDC_VERSION__ >= 202311L) ||              \
90     !defined(__STRICT_ANSI__)
91 #    undef FLT_NORM_MAX
92 #    undef DBL_NORM_MAX
93 #    undef LDBL_NORM_MAX
94 #endif
95 #endif
96 
97 #if (defined(__STDC_VERSION__) && __STDC_VERSION__ >= 202311L) ||              \
98     !defined(__STRICT_ANSI__)
99 #  undef INFINITY
100 #  undef NAN
101 #endif
102 
103 /* Characteristics of floating point types, C99 5.2.4.2.2 */
104 
105 #if (defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L) ||              \
106     (defined(__cplusplus) && __cplusplus >= 201103L)
107 #define FLT_EVAL_METHOD __FLT_EVAL_METHOD__
108 #endif
109 #define FLT_ROUNDS (__builtin_flt_rounds())
110 #define FLT_RADIX __FLT_RADIX__
111 
112 #define FLT_MANT_DIG __FLT_MANT_DIG__
113 #define DBL_MANT_DIG __DBL_MANT_DIG__
114 #define LDBL_MANT_DIG __LDBL_MANT_DIG__
115 
116 #if (defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L) ||              \
117     !defined(__STRICT_ANSI__) ||                                               \
118     (defined(__cplusplus) && __cplusplus >= 201103L) ||                        \
119     (__STDC_HOSTED__ && defined(_AIX) && defined(_ALL_SOURCE))
120 #  define DECIMAL_DIG __DECIMAL_DIG__
121 #endif
122 
123 #define FLT_DIG __FLT_DIG__
124 #define DBL_DIG __DBL_DIG__
125 #define LDBL_DIG __LDBL_DIG__
126 
127 #define FLT_MIN_EXP __FLT_MIN_EXP__
128 #define DBL_MIN_EXP __DBL_MIN_EXP__
129 #define LDBL_MIN_EXP __LDBL_MIN_EXP__
130 
131 #define FLT_MIN_10_EXP __FLT_MIN_10_EXP__
132 #define DBL_MIN_10_EXP __DBL_MIN_10_EXP__
133 #define LDBL_MIN_10_EXP __LDBL_MIN_10_EXP__
134 
135 #define FLT_MAX_EXP __FLT_MAX_EXP__
136 #define DBL_MAX_EXP __DBL_MAX_EXP__
137 #define LDBL_MAX_EXP __LDBL_MAX_EXP__
138 
139 #define FLT_MAX_10_EXP __FLT_MAX_10_EXP__
140 #define DBL_MAX_10_EXP __DBL_MAX_10_EXP__
141 #define LDBL_MAX_10_EXP __LDBL_MAX_10_EXP__
142 
143 #define FLT_MAX __FLT_MAX__
144 #define DBL_MAX __DBL_MAX__
145 #define LDBL_MAX __LDBL_MAX__
146 
147 #define FLT_EPSILON __FLT_EPSILON__
148 #define DBL_EPSILON __DBL_EPSILON__
149 #define LDBL_EPSILON __LDBL_EPSILON__
150 
151 #define FLT_MIN __FLT_MIN__
152 #define DBL_MIN __DBL_MIN__
153 #define LDBL_MIN __LDBL_MIN__
154 
155 #if (defined(__STDC_VERSION__) && __STDC_VERSION__ >= 201112L) ||              \
156     !defined(__STRICT_ANSI__) ||                                               \
157     (defined(__cplusplus) && __cplusplus >= 201703L) ||                        \
158     (__STDC_HOSTED__ && defined(_AIX) && defined(_ALL_SOURCE))
159 #  define FLT_TRUE_MIN __FLT_DENORM_MIN__
160 #  define DBL_TRUE_MIN __DBL_DENORM_MIN__
161 #  define LDBL_TRUE_MIN __LDBL_DENORM_MIN__
162 #  define FLT_DECIMAL_DIG __FLT_DECIMAL_DIG__
163 #  define DBL_DECIMAL_DIG __DBL_DECIMAL_DIG__
164 #  define LDBL_DECIMAL_DIG __LDBL_DECIMAL_DIG__
165 #  define FLT_HAS_SUBNORM __FLT_HAS_DENORM__
166 #  define DBL_HAS_SUBNORM __DBL_HAS_DENORM__
167 #  define LDBL_HAS_SUBNORM __LDBL_HAS_DENORM__
168 #endif
169 
170 #if (defined(__STDC_VERSION__) && __STDC_VERSION__ >= 202311L) ||              \
171     !defined(__STRICT_ANSI__)
172    /* C23 5.2.5.3.3p29-30 */
173 #  define INFINITY (__builtin_inff())
174 #  define NAN (__builtin_nanf(""))
175    /* C23 5.2.5.3.3p32 */
176 #  define FLT_NORM_MAX __FLT_NORM_MAX__
177 #  define DBL_NORM_MAX __DBL_NORM_MAX__
178 #  define LDBL_NORM_MAX __LDBL_NORM_MAX__
179 #endif
180 
181 #ifdef __STDC_WANT_IEC_60559_TYPES_EXT__
182 #  define FLT16_MANT_DIG    __FLT16_MANT_DIG__
183 #  define FLT16_DECIMAL_DIG __FLT16_DECIMAL_DIG__
184 #  define FLT16_DIG         __FLT16_DIG__
185 #  define FLT16_MIN_EXP     __FLT16_MIN_EXP__
186 #  define FLT16_MIN_10_EXP  __FLT16_MIN_10_EXP__
187 #  define FLT16_MAX_EXP     __FLT16_MAX_EXP__
188 #  define FLT16_MAX_10_EXP  __FLT16_MAX_10_EXP__
189 #  define FLT16_MAX         __FLT16_MAX__
190 #  define FLT16_EPSILON     __FLT16_EPSILON__
191 #  define FLT16_MIN         __FLT16_MIN__
192 #  define FLT16_TRUE_MIN    __FLT16_TRUE_MIN__
193 #endif /* __STDC_WANT_IEC_60559_TYPES_EXT__ */
194 
195 #endif /* __MVS__ */
196 #endif /* __CLANG_FLOAT_H */
197