Commit | Line | Data |
---|---|---|
2e65b52f LC |
1 | /* A GNU-like <math.h>. |
2 | ||
3 | Copyright (C) 2002-2003, 2007-2010 Free Software Foundation, Inc. | |
4 | ||
5 | This program is free software: you can redistribute it and/or modify | |
6 | it under the terms of the GNU Lesser General Public License as published by | |
7 | the Free Software Foundation; either version 3 of the License, or | |
8 | (at your option) any later version. | |
9 | ||
10 | This program 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. | |
14 | ||
15 | You should have received a copy of the GNU Lesser General Public License | |
16 | along with this program. If not, see <http://www.gnu.org/licenses/>. */ | |
17 | ||
18 | #ifndef _GL_MATH_H | |
19 | ||
20 | #if __GNUC__ >= 3 | |
21 | @PRAGMA_SYSTEM_HEADER@ | |
22 | #endif | |
23 | ||
24 | /* The include_next requires a split double-inclusion guard. */ | |
25 | #@INCLUDE_NEXT_AS_FIRST_DIRECTIVE@ @NEXT_AS_FIRST_DIRECTIVE_MATH_H@ | |
26 | ||
27 | #ifndef _GL_MATH_H | |
28 | #define _GL_MATH_H | |
29 | ||
30 | ||
31 | /* The definitions of _GL_FUNCDECL_RPL etc. are copied here. */ | |
32 | ||
33 | /* The definition of _GL_ARG_NONNULL is copied here. */ | |
34 | ||
35 | /* The definition of _GL_WARN_ON_USE is copied here. */ | |
36 | ||
37 | /* Helper macros to define a portability warning for the | |
38 | classification macro FUNC called with VALUE. POSIX declares the | |
39 | classification macros with an argument of real-floating (that is, | |
40 | one of float, double, or long double). */ | |
41 | #define _GL_WARN_REAL_FLOATING_DECL(func) \ | |
42 | static inline int \ | |
43 | rpl_ ## func ## f (float f) \ | |
44 | { \ | |
45 | return func (f); \ | |
46 | } \ | |
47 | static inline int \ | |
48 | rpl_ ## func ## d (double d) \ | |
49 | { \ | |
50 | return func (d); \ | |
51 | } \ | |
52 | static inline int \ | |
53 | rpl_ ## func ## l (long double l) \ | |
54 | { \ | |
55 | return func (l); \ | |
56 | } \ | |
57 | _GL_WARN_ON_USE (rpl_ ## func ## f, #func " is unportable - " \ | |
58 | "use gnulib module " #func " for portability"); \ | |
59 | _GL_WARN_ON_USE (rpl_ ## func ## d, #func " is unportable - " \ | |
60 | "use gnulib module " #func " for portability"); \ | |
61 | _GL_WARN_ON_USE (rpl_ ## func ## l, #func " is unportable - " \ | |
62 | "use gnulib module " #func " for portability") | |
63 | #define _GL_WARN_REAL_FLOATING_IMPL(func, value) \ | |
64 | (sizeof (value) == sizeof (float) ? rpl_ ## func ## f (value) \ | |
65 | : sizeof (value) == sizeof (double) ? rpl_ ## func ## d (value) \ | |
66 | : rpl_ ## func ## l (value)) | |
67 | ||
68 | ||
69 | /* POSIX allows platforms that don't support NAN. But all major | |
70 | machines in the past 15 years have supported something close to | |
71 | IEEE NaN, so we define this unconditionally. We also must define | |
72 | it on platforms like Solaris 10, where NAN is present but defined | |
73 | as a function pointer rather than a floating point constant. */ | |
74 | #if !defined NAN || @REPLACE_NAN@ | |
75 | # undef NAN | |
76 | /* The Compaq (ex-DEC) C 6.4 compiler chokes on the expression 0.0 / 0.0. */ | |
77 | # ifdef __DECC | |
78 | static float | |
79 | _NaN () | |
80 | { | |
81 | static float zero = 0.0f; | |
82 | return zero / zero; | |
83 | } | |
84 | # define NAN (_NaN()) | |
85 | # else | |
86 | # define NAN (0.0f / 0.0f) | |
87 | # endif | |
88 | #endif | |
89 | ||
90 | /* Solaris 10 defines HUGE_VAL, but as a function pointer rather | |
91 | than a floating point constant. */ | |
92 | #if @REPLACE_HUGE_VAL@ | |
93 | # undef HUGE_VAL | |
94 | # define HUGE_VAL (1.0 / 0.0) | |
95 | #endif | |
96 | ||
97 | ||
98 | /* Write x as | |
99 | x = mantissa * 2^exp | |
100 | where | |
101 | If x finite and nonzero: 0.5 <= |mantissa| < 1.0. | |
102 | If x is zero: mantissa = x, exp = 0. | |
103 | If x is infinite or NaN: mantissa = x, exp unspecified. | |
104 | Store exp in *EXPPTR and return mantissa. */ | |
105 | #if @GNULIB_FREXP@ | |
106 | # if @REPLACE_FREXP@ | |
107 | # if !(defined __cplusplus && defined GNULIB_NAMESPACE) | |
108 | # define frexp rpl_frexp | |
109 | # endif | |
110 | _GL_FUNCDECL_RPL (frexp, double, (double x, int *expptr) _GL_ARG_NONNULL ((2))); | |
111 | _GL_CXXALIAS_RPL (frexp, double, (double x, int *expptr)); | |
112 | # else | |
113 | _GL_CXXALIAS_SYS (frexp, double, (double x, int *expptr)); | |
114 | # endif | |
115 | _GL_CXXALIASWARN (frexp); | |
116 | #elif defined GNULIB_POSIXCHECK | |
117 | # undef frexp | |
118 | /* Assume frexp is always declared. */ | |
119 | _GL_WARN_ON_USE (frexp, "frexp is unportable - " | |
120 | "use gnulib module frexp for portability"); | |
121 | #endif | |
122 | ||
123 | ||
124 | #if @GNULIB_LOGB@ | |
125 | # if !@HAVE_DECL_LOGB@ | |
126 | _GL_EXTERN_C double logb (double x); | |
127 | # endif | |
128 | #elif defined GNULIB_POSIXCHECK | |
129 | # undef logb | |
130 | # if HAVE_RAW_DECL_LOGB | |
131 | _GL_WARN_ON_USE (logb, "logb is unportable - " | |
132 | "use gnulib module logb for portability"); | |
133 | # endif | |
134 | #endif | |
135 | ||
136 | ||
137 | #if @GNULIB_ACOSL@ | |
138 | # if !@HAVE_ACOSL@ || !@HAVE_DECL_ACOSL@ | |
139 | _GL_FUNCDECL_SYS (acosl, long double, (long double x)); | |
140 | # endif | |
141 | _GL_CXXALIAS_SYS (acosl, long double, (long double x)); | |
142 | _GL_CXXALIASWARN (acosl); | |
143 | #elif defined GNULIB_POSIXCHECK | |
144 | # undef acosl | |
145 | # if HAVE_RAW_DECL_ACOSL | |
146 | _GL_WARN_ON_USE (acosl, "acosl is unportable - " | |
147 | "use gnulib module mathl for portability"); | |
148 | # endif | |
149 | #endif | |
150 | ||
151 | ||
152 | #if @GNULIB_ASINL@ | |
153 | # if !@HAVE_ASINL@ || !@HAVE_DECL_ASINL@ | |
154 | _GL_FUNCDECL_SYS (asinl, long double, (long double x)); | |
155 | # endif | |
156 | _GL_CXXALIAS_SYS (asinl, long double, (long double x)); | |
157 | _GL_CXXALIASWARN (asinl); | |
158 | #elif defined GNULIB_POSIXCHECK | |
159 | # undef asinl | |
160 | # if HAVE_RAW_DECL_ASINL | |
161 | _GL_WARN_ON_USE (asinl, "asinl is unportable - " | |
162 | "use gnulib module mathl for portability"); | |
163 | # endif | |
164 | #endif | |
165 | ||
166 | ||
167 | #if @GNULIB_ATANL@ | |
168 | # if !@HAVE_ATANL@ || !@HAVE_DECL_ATANL@ | |
169 | _GL_FUNCDECL_SYS (atanl, long double, (long double x)); | |
170 | # endif | |
171 | _GL_CXXALIAS_SYS (atanl, long double, (long double x)); | |
172 | _GL_CXXALIASWARN (atanl); | |
173 | #elif defined GNULIB_POSIXCHECK | |
174 | # undef atanl | |
175 | # if HAVE_RAW_DECL_ATANL | |
176 | _GL_WARN_ON_USE (atanl, "atanl is unportable - " | |
177 | "use gnulib module mathl for portability"); | |
178 | # endif | |
179 | #endif | |
180 | ||
181 | ||
182 | #if @GNULIB_CEILF@ | |
183 | # if @REPLACE_CEILF@ | |
184 | # if !(defined __cplusplus && defined GNULIB_NAMESPACE) | |
185 | # define ceilf rpl_ceilf | |
186 | # endif | |
187 | _GL_FUNCDECL_RPL (ceilf, float, (float x)); | |
188 | _GL_CXXALIAS_RPL (ceilf, float, (float x)); | |
189 | # else | |
190 | # if !@HAVE_DECL_CEILF@ | |
191 | _GL_FUNCDECL_SYS (ceilf, float, (float x)); | |
192 | # endif | |
193 | _GL_CXXALIAS_SYS (ceilf, float, (float x)); | |
194 | # endif | |
195 | _GL_CXXALIASWARN (ceilf); | |
196 | #elif defined GNULIB_POSIXCHECK | |
197 | # undef ceilf | |
198 | # if HAVE_RAW_DECL_CEILF | |
199 | _GL_WARN_ON_USE (ceilf, "ceilf is unportable - " | |
200 | "use gnulib module ceilf for portability"); | |
201 | # endif | |
202 | #endif | |
203 | ||
204 | #if @GNULIB_CEILL@ | |
205 | # if @REPLACE_CEILL@ | |
206 | # if !(defined __cplusplus && defined GNULIB_NAMESPACE) | |
207 | # define ceill rpl_ceill | |
208 | # endif | |
209 | _GL_FUNCDECL_RPL (ceill, long double, (long double x)); | |
210 | _GL_CXXALIAS_RPL (ceill, long double, (long double x)); | |
211 | # else | |
212 | # if !@HAVE_DECL_CEILL@ | |
213 | _GL_FUNCDECL_SYS (ceill, long double, (long double x)); | |
214 | # endif | |
215 | _GL_CXXALIAS_SYS (ceill, long double, (long double x)); | |
216 | # endif | |
217 | _GL_CXXALIASWARN (ceill); | |
218 | #elif defined GNULIB_POSIXCHECK | |
219 | # undef ceill | |
220 | # if HAVE_RAW_DECL_CEILL | |
221 | _GL_WARN_ON_USE (ceill, "ceill is unportable - " | |
222 | "use gnulib module ceill for portability"); | |
223 | # endif | |
224 | #endif | |
225 | ||
226 | ||
227 | #if @GNULIB_COSL@ | |
228 | # if !@HAVE_COSL@ || !@HAVE_DECL_COSL@ | |
229 | _GL_FUNCDECL_SYS (cosl, long double, (long double x)); | |
230 | # endif | |
231 | _GL_CXXALIAS_SYS (cosl, long double, (long double x)); | |
232 | _GL_CXXALIASWARN (cosl); | |
233 | #elif defined GNULIB_POSIXCHECK | |
234 | # undef cosl | |
235 | # if HAVE_RAW_DECL_COSL | |
236 | _GL_WARN_ON_USE (cosl, "cosl is unportable - " | |
237 | "use gnulib module mathl for portability"); | |
238 | # endif | |
239 | #endif | |
240 | ||
241 | ||
242 | #if @GNULIB_EXPL@ | |
243 | # if !@HAVE_EXPL@ || !@HAVE_DECL_EXPL@ | |
244 | _GL_FUNCDECL_SYS (expl, long double, (long double x)); | |
245 | # endif | |
246 | _GL_CXXALIAS_SYS (expl, long double, (long double x)); | |
247 | _GL_CXXALIASWARN (expl); | |
248 | #elif defined GNULIB_POSIXCHECK | |
249 | # undef expl | |
250 | # if HAVE_RAW_DECL_EXPL | |
251 | _GL_WARN_ON_USE (expl, "expl is unportable - " | |
252 | "use gnulib module mathl for portability"); | |
253 | # endif | |
254 | #endif | |
255 | ||
256 | ||
257 | #if @GNULIB_FLOORF@ | |
258 | # if @REPLACE_FLOORF@ | |
259 | # if !(defined __cplusplus && defined GNULIB_NAMESPACE) | |
260 | # define floorf rpl_floorf | |
261 | # endif | |
262 | _GL_FUNCDECL_RPL (floorf, float, (float x)); | |
263 | _GL_CXXALIAS_RPL (floorf, float, (float x)); | |
264 | #else | |
265 | # if !@HAVE_DECL_FLOORF@ | |
266 | _GL_FUNCDECL_SYS (floorf, float, (float x)); | |
267 | # endif | |
268 | _GL_CXXALIAS_SYS (floorf, float, (float x)); | |
269 | # endif | |
270 | _GL_CXXALIASWARN (floorf); | |
271 | #elif defined GNULIB_POSIXCHECK | |
272 | # undef floorf | |
273 | # if HAVE_RAW_DECL_FLOORF | |
274 | _GL_WARN_ON_USE (floorf, "floorf is unportable - " | |
275 | "use gnulib module floorf for portability"); | |
276 | # endif | |
277 | #endif | |
278 | ||
279 | #if @GNULIB_FLOORL@ | |
280 | # if @REPLACE_FLOORL@ | |
281 | # if !(defined __cplusplus && defined GNULIB_NAMESPACE) | |
282 | # define floorl rpl_floorl | |
283 | # endif | |
284 | _GL_FUNCDECL_RPL (floorl, long double, (long double x)); | |
285 | _GL_CXXALIAS_RPL (floorl, long double, (long double x)); | |
286 | # else | |
287 | # if !@HAVE_DECL_FLOORL@ | |
288 | _GL_FUNCDECL_SYS (floorl, long double, (long double x)); | |
289 | # endif | |
290 | _GL_CXXALIAS_SYS (floorl, long double, (long double x)); | |
291 | # endif | |
292 | _GL_CXXALIASWARN (floorl); | |
293 | #elif defined GNULIB_POSIXCHECK | |
294 | # undef floorl | |
295 | # if HAVE_RAW_DECL_FLOORL | |
296 | _GL_WARN_ON_USE (floorl, "floorl is unportable - " | |
297 | "use gnulib module floorl for portability"); | |
298 | # endif | |
299 | #endif | |
300 | ||
301 | ||
302 | /* Write x as | |
303 | x = mantissa * 2^exp | |
304 | where | |
305 | If x finite and nonzero: 0.5 <= |mantissa| < 1.0. | |
306 | If x is zero: mantissa = x, exp = 0. | |
307 | If x is infinite or NaN: mantissa = x, exp unspecified. | |
308 | Store exp in *EXPPTR and return mantissa. */ | |
309 | #if @GNULIB_FREXPL@ && @REPLACE_FREXPL@ | |
310 | # if !(defined __cplusplus && defined GNULIB_NAMESPACE) | |
311 | # define frexpl rpl_frexpl | |
312 | # endif | |
313 | _GL_FUNCDECL_RPL (frexpl, long double, | |
314 | (long double x, int *expptr) _GL_ARG_NONNULL ((2))); | |
315 | _GL_CXXALIAS_RPL (frexpl, long double, (long double x, int *expptr)); | |
316 | #else | |
317 | # if !@HAVE_DECL_FREXPL@ | |
318 | _GL_FUNCDECL_SYS (frexpl, long double, | |
319 | (long double x, int *expptr) _GL_ARG_NONNULL ((2))); | |
320 | # endif | |
321 | # if @GNULIB_FREXPL@ | |
322 | _GL_CXXALIAS_SYS (frexpl, long double, (long double x, int *expptr)); | |
323 | # endif | |
324 | #endif | |
325 | #if @GNULIB_FREXPL@ && !(@REPLACE_FREXPL@ && !@HAVE_DECL_FREXPL@) | |
326 | _GL_CXXALIASWARN (frexpl); | |
327 | #endif | |
328 | #if !@GNULIB_FREXPL@ && defined GNULIB_POSIXCHECK | |
329 | # undef frexpl | |
330 | # if HAVE_RAW_DECL_FREXPL | |
331 | _GL_WARN_ON_USE (frexpl, "frexpl is unportable - " | |
332 | "use gnulib module frexpl for portability"); | |
333 | # endif | |
334 | #endif | |
335 | ||
336 | ||
337 | /* Return x * 2^exp. */ | |
338 | #if @GNULIB_LDEXPL@ && @REPLACE_LDEXPL@ | |
339 | # if !(defined __cplusplus && defined GNULIB_NAMESPACE) | |
340 | # define ldexpl rpl_ldexpl | |
341 | # endif | |
342 | _GL_FUNCDECL_RPL (ldexpl, long double, (long double x, int exp)); | |
343 | _GL_CXXALIAS_RPL (ldexpl, long double, (long double x, int exp)); | |
344 | #else | |
345 | # if !@HAVE_DECL_LDEXPL@ | |
346 | _GL_FUNCDECL_SYS (ldexpl, long double, (long double x, int exp)); | |
347 | # endif | |
348 | # if @GNULIB_LDEXPL@ | |
349 | _GL_CXXALIAS_SYS (ldexpl, long double, (long double x, int exp)); | |
350 | # endif | |
351 | #endif | |
352 | #if @GNULIB_LDEXPL@ | |
353 | _GL_CXXALIASWARN (ldexpl); | |
354 | #endif | |
355 | #if !@GNULIB_LDEXPL@ && defined GNULIB_POSIXCHECK | |
356 | # undef ldexpl | |
357 | # if HAVE_RAW_DECL_LDEXPL | |
358 | _GL_WARN_ON_USE (ldexpl, "ldexpl is unportable - " | |
359 | "use gnulib module ldexpl for portability"); | |
360 | # endif | |
361 | #endif | |
362 | ||
363 | ||
364 | #if @GNULIB_LOGL@ | |
365 | # if !@HAVE_LOGL@ || !@HAVE_DECL_LOGL@ | |
366 | _GL_FUNCDECL_SYS (logl, long double, (long double x)); | |
367 | # endif | |
368 | _GL_CXXALIAS_SYS (logl, long double, (long double x)); | |
369 | _GL_CXXALIASWARN (logl); | |
370 | #elif defined GNULIB_POSIXCHECK | |
371 | # undef logl | |
372 | # if HAVE_RAW_DECL_LOGL | |
373 | _GL_WARN_ON_USE (logl, "logl is unportable - " | |
374 | "use gnulib module mathl for portability"); | |
375 | # endif | |
376 | #endif | |
377 | ||
378 | ||
379 | #if @GNULIB_ROUNDF@ | |
380 | # if @REPLACE_ROUNDF@ | |
381 | # if !(defined __cplusplus && defined GNULIB_NAMESPACE) | |
382 | # undef roundf | |
383 | # define roundf rpl_roundf | |
384 | # endif | |
385 | _GL_FUNCDECL_RPL (roundf, float, (float x)); | |
386 | _GL_CXXALIAS_RPL (roundf, float, (float x)); | |
387 | # else | |
388 | # if !@HAVE_DECL_ROUNDF@ | |
389 | _GL_FUNCDECL_SYS (roundf, float, (float x)); | |
390 | # endif | |
391 | _GL_CXXALIAS_SYS (roundf, float, (float x)); | |
392 | # endif | |
393 | _GL_CXXALIASWARN (roundf); | |
394 | #elif defined GNULIB_POSIXCHECK | |
395 | # undef roundf | |
396 | # if HAVE_RAW_DECL_ROUNDF | |
397 | _GL_WARN_ON_USE (roundf, "roundf is unportable - " | |
398 | "use gnulib module roundf for portability"); | |
399 | # endif | |
400 | #endif | |
401 | ||
402 | #if @GNULIB_ROUND@ | |
403 | # if @REPLACE_ROUND@ | |
404 | # if !(defined __cplusplus && defined GNULIB_NAMESPACE) | |
405 | # undef round | |
406 | # define round rpl_round | |
407 | # endif | |
408 | _GL_FUNCDECL_RPL (round, double, (double x)); | |
409 | _GL_CXXALIAS_RPL (round, double, (double x)); | |
410 | # else | |
411 | # if !@HAVE_DECL_ROUND@ | |
412 | _GL_FUNCDECL_SYS (round, double, (double x)); | |
413 | # endif | |
414 | _GL_CXXALIAS_SYS (round, double, (double x)); | |
415 | # endif | |
416 | _GL_CXXALIASWARN (round); | |
417 | #elif defined GNULIB_POSIXCHECK | |
418 | # undef round | |
419 | # if HAVE_RAW_DECL_ROUND | |
420 | _GL_WARN_ON_USE (round, "round is unportable - " | |
421 | "use gnulib module round for portability"); | |
422 | # endif | |
423 | #endif | |
424 | ||
425 | #if @GNULIB_ROUNDL@ | |
426 | # if @REPLACE_ROUNDL@ | |
427 | # if !(defined __cplusplus && defined GNULIB_NAMESPACE) | |
428 | # undef roundl | |
429 | # define roundl rpl_roundl | |
430 | # endif | |
431 | _GL_FUNCDECL_RPL (roundl, long double, (long double x)); | |
432 | _GL_CXXALIAS_RPL (roundl, long double, (long double x)); | |
433 | # else | |
434 | # if !@HAVE_DECL_ROUNDL@ | |
435 | _GL_FUNCDECL_SYS (roundl, long double, (long double x)); | |
436 | # endif | |
437 | _GL_CXXALIAS_SYS (roundl, long double, (long double x)); | |
438 | # endif | |
439 | _GL_CXXALIASWARN (roundl); | |
440 | #elif defined GNULIB_POSIXCHECK | |
441 | # undef roundl | |
442 | # if HAVE_RAW_DECL_ROUNDL | |
443 | _GL_WARN_ON_USE (roundl, "roundl is unportable - " | |
444 | "use gnulib module roundl for portability"); | |
445 | # endif | |
446 | #endif | |
447 | ||
448 | ||
449 | #if @GNULIB_SINL@ | |
450 | # if !@HAVE_SINL@ || !@HAVE_DECL_SINL@ | |
451 | _GL_FUNCDECL_SYS (sinl, long double, (long double x)); | |
452 | # endif | |
453 | _GL_CXXALIAS_SYS (sinl, long double, (long double x)); | |
454 | _GL_CXXALIASWARN (sinl); | |
455 | #elif defined GNULIB_POSIXCHECK | |
456 | # undef sinl | |
457 | # if HAVE_RAW_DECL_SINL | |
458 | _GL_WARN_ON_USE (sinl, "sinl is unportable - " | |
459 | "use gnulib module mathl for portability"); | |
460 | # endif | |
461 | #endif | |
462 | ||
463 | ||
464 | #if @GNULIB_SQRTL@ | |
465 | # if !@HAVE_SQRTL@ || !@HAVE_DECL_SQRTL@ | |
466 | _GL_FUNCDECL_SYS (sqrtl, long double, (long double x)); | |
467 | # endif | |
468 | _GL_CXXALIAS_SYS (sqrtl, long double, (long double x)); | |
469 | _GL_CXXALIASWARN (sqrtl); | |
470 | #elif defined GNULIB_POSIXCHECK | |
471 | # undef sqrtl | |
472 | # if HAVE_RAW_DECL_SQRTL | |
473 | _GL_WARN_ON_USE (sqrtl, "sqrtl is unportable - " | |
474 | "use gnulib module mathl for portability"); | |
475 | # endif | |
476 | #endif | |
477 | ||
478 | ||
479 | #if @GNULIB_TANL@ | |
480 | # if !@HAVE_TANL@ || !@HAVE_DECL_TANL@ | |
481 | _GL_FUNCDECL_SYS (tanl, long double, (long double x)); | |
482 | # endif | |
483 | _GL_CXXALIAS_SYS (tanl, long double, (long double x)); | |
484 | _GL_CXXALIASWARN (tanl); | |
485 | #elif defined GNULIB_POSIXCHECK | |
486 | # undef tanl | |
487 | # if HAVE_RAW_DECL_TANL | |
488 | _GL_WARN_ON_USE (tanl, "tanl is unportable - " | |
489 | "use gnulib module mathl for portability"); | |
490 | # endif | |
491 | #endif | |
492 | ||
493 | ||
494 | #if @GNULIB_TRUNCF@ | |
495 | # if !@HAVE_DECL_TRUNCF@ | |
496 | _GL_FUNCDECL_SYS (truncf, float, (float x)); | |
497 | # endif | |
498 | _GL_CXXALIAS_SYS (truncf, float, (float x)); | |
499 | _GL_CXXALIASWARN (truncf); | |
500 | #elif defined GNULIB_POSIXCHECK | |
501 | # undef truncf | |
502 | # if HAVE_RAW_DECL_TRUNCF | |
503 | _GL_WARN_ON_USE (truncf, "truncf is unportable - " | |
504 | "use gnulib module truncf for portability"); | |
505 | # endif | |
506 | #endif | |
507 | ||
508 | #if @GNULIB_TRUNC@ | |
509 | # if !@HAVE_DECL_TRUNC@ | |
510 | _GL_FUNCDECL_SYS (trunc, double, (double x)); | |
511 | # endif | |
512 | _GL_CXXALIAS_SYS (trunc, double, (double x)); | |
513 | _GL_CXXALIASWARN (trunc); | |
514 | #elif defined GNULIB_POSIXCHECK | |
515 | # undef trunc | |
516 | # if HAVE_RAW_DECL_TRUNC | |
517 | _GL_WARN_ON_USE (trunc, "trunc is unportable - " | |
518 | "use gnulib module trunc for portability"); | |
519 | # endif | |
520 | #endif | |
521 | ||
522 | #if @GNULIB_TRUNCL@ | |
523 | # if @REPLACE_TRUNCL@ | |
524 | # if !(defined __cplusplus && defined GNULIB_NAMESPACE) | |
525 | # undef truncl | |
526 | # define truncl rpl_truncl | |
527 | # endif | |
528 | _GL_FUNCDECL_RPL (truncl, long double, (long double x)); | |
529 | _GL_CXXALIAS_RPL (truncl, long double, (long double x)); | |
530 | # else | |
531 | # if !@HAVE_DECL_TRUNCL@ | |
532 | _GL_FUNCDECL_SYS (truncl, long double, (long double x)); | |
533 | # endif | |
534 | _GL_CXXALIAS_SYS (truncl, long double, (long double x)); | |
535 | # endif | |
536 | _GL_CXXALIASWARN (truncl); | |
537 | #elif defined GNULIB_POSIXCHECK | |
538 | # undef truncl | |
539 | # if HAVE_RAW_DECL_TRUNCL | |
540 | _GL_WARN_ON_USE (truncl, "truncl is unportable - " | |
541 | "use gnulib module truncl for portability"); | |
542 | # endif | |
543 | #endif | |
544 | ||
545 | ||
546 | #if @GNULIB_ISFINITE@ | |
547 | # if @REPLACE_ISFINITE@ | |
548 | _GL_EXTERN_C int gl_isfinitef (float x); | |
549 | _GL_EXTERN_C int gl_isfinited (double x); | |
550 | _GL_EXTERN_C int gl_isfinitel (long double x); | |
551 | # undef isfinite | |
552 | # define isfinite(x) \ | |
553 | (sizeof (x) == sizeof (long double) ? gl_isfinitel (x) : \ | |
554 | sizeof (x) == sizeof (double) ? gl_isfinited (x) : \ | |
555 | gl_isfinitef (x)) | |
556 | # endif | |
557 | #elif defined GNULIB_POSIXCHECK | |
558 | # if defined isfinite | |
559 | _GL_WARN_REAL_FLOATING_DECL (isfinite); | |
560 | # undef isfinite | |
561 | # define isfinite(x) _GL_WARN_REAL_FLOATING_IMPL (isfinite, x) | |
562 | # endif | |
563 | #endif | |
564 | ||
565 | ||
566 | #if @GNULIB_ISINF@ | |
567 | # if @REPLACE_ISINF@ | |
568 | _GL_EXTERN_C int gl_isinff (float x); | |
569 | _GL_EXTERN_C int gl_isinfd (double x); | |
570 | _GL_EXTERN_C int gl_isinfl (long double x); | |
571 | # undef isinf | |
572 | # define isinf(x) \ | |
573 | (sizeof (x) == sizeof (long double) ? gl_isinfl (x) : \ | |
574 | sizeof (x) == sizeof (double) ? gl_isinfd (x) : \ | |
575 | gl_isinff (x)) | |
576 | # endif | |
577 | #elif defined GNULIB_POSIXCHECK | |
578 | # if defined isinf | |
579 | _GL_WARN_REAL_FLOATING_DECL (isinf); | |
580 | # undef isinf | |
581 | # define isinf(x) _GL_WARN_REAL_FLOATING_IMPL (isinf, x) | |
582 | # endif | |
583 | #endif | |
584 | ||
585 | ||
586 | #if @GNULIB_ISNANF@ | |
587 | /* Test for NaN for 'float' numbers. */ | |
588 | # if @HAVE_ISNANF@ | |
589 | /* The original <math.h> included above provides a declaration of isnan macro | |
590 | or (older) isnanf function. */ | |
591 | # if __GNUC__ >= 4 | |
592 | /* GCC 4.0 and newer provides three built-ins for isnan. */ | |
593 | # undef isnanf | |
594 | # define isnanf(x) __builtin_isnanf ((float)(x)) | |
595 | # elif defined isnan | |
596 | # undef isnanf | |
597 | # define isnanf(x) isnan ((float)(x)) | |
598 | # endif | |
599 | # else | |
600 | /* Test whether X is a NaN. */ | |
601 | # undef isnanf | |
602 | # define isnanf rpl_isnanf | |
603 | _GL_EXTERN_C int isnanf (float x); | |
604 | # endif | |
605 | #endif | |
606 | ||
607 | #if @GNULIB_ISNAND@ | |
608 | /* Test for NaN for 'double' numbers. | |
609 | This function is a gnulib extension, unlike isnan() which applied only | |
610 | to 'double' numbers earlier but now is a type-generic macro. */ | |
611 | # if @HAVE_ISNAND@ | |
612 | /* The original <math.h> included above provides a declaration of isnan macro. */ | |
613 | # if __GNUC__ >= 4 | |
614 | /* GCC 4.0 and newer provides three built-ins for isnan. */ | |
615 | # undef isnand | |
616 | # define isnand(x) __builtin_isnan ((double)(x)) | |
617 | # else | |
618 | # undef isnand | |
619 | # define isnand(x) isnan ((double)(x)) | |
620 | # endif | |
621 | # else | |
622 | /* Test whether X is a NaN. */ | |
623 | # undef isnand | |
624 | # define isnand rpl_isnand | |
625 | _GL_EXTERN_C int isnand (double x); | |
626 | # endif | |
627 | #endif | |
628 | ||
629 | #if @GNULIB_ISNANL@ | |
630 | /* Test for NaN for 'long double' numbers. */ | |
631 | # if @HAVE_ISNANL@ | |
632 | /* The original <math.h> included above provides a declaration of isnan macro or (older) isnanl function. */ | |
633 | # if __GNUC__ >= 4 | |
634 | /* GCC 4.0 and newer provides three built-ins for isnan. */ | |
635 | # undef isnanl | |
636 | # define isnanl(x) __builtin_isnanl ((long double)(x)) | |
637 | # elif defined isnan | |
638 | # undef isnanl | |
639 | # define isnanl(x) isnan ((long double)(x)) | |
640 | # endif | |
641 | # else | |
642 | /* Test whether X is a NaN. */ | |
643 | # undef isnanl | |
644 | # define isnanl rpl_isnanl | |
645 | _GL_EXTERN_C int isnanl (long double x); | |
646 | # endif | |
647 | #endif | |
648 | ||
649 | /* This must come *after* the snippets for GNULIB_ISNANF and GNULIB_ISNANL! */ | |
650 | #if @GNULIB_ISNAN@ | |
651 | # if @REPLACE_ISNAN@ | |
652 | /* We can't just use the isnanf macro (e.g.) as exposed by | |
653 | isnanf.h (e.g.) here, because those may end up being macros | |
654 | that recursively expand back to isnan. So use the gnulib | |
655 | replacements for them directly. */ | |
656 | # if @HAVE_ISNANF@ && __GNUC__ >= 4 | |
657 | # define gl_isnan_f(x) __builtin_isnan ((float)(x)) | |
658 | # else | |
659 | _GL_EXTERN_C int rpl_isnanf (float x); | |
660 | # define gl_isnan_f(x) rpl_isnanf (x) | |
661 | # endif | |
662 | # if @HAVE_ISNAND@ && __GNUC__ >= 4 | |
663 | # define gl_isnan_d(x) __builtin_isnan ((double)(x)) | |
664 | # else | |
665 | _GL_EXTERN_C int rpl_isnand (double x); | |
666 | # define gl_isnan_d(x) rpl_isnand (x) | |
667 | # endif | |
668 | # if @HAVE_ISNANL@ && __GNUC__ >= 4 | |
669 | # define gl_isnan_l(x) __builtin_isnan ((long double)(x)) | |
670 | # else | |
671 | _GL_EXTERN_C int rpl_isnanl (long double x); | |
672 | # define gl_isnan_l(x) rpl_isnanl (x) | |
673 | # endif | |
674 | # undef isnan | |
675 | # define isnan(x) \ | |
676 | (sizeof (x) == sizeof (long double) ? gl_isnan_l (x) : \ | |
677 | sizeof (x) == sizeof (double) ? gl_isnan_d (x) : \ | |
678 | gl_isnan_f (x)) | |
679 | # endif | |
680 | #elif defined GNULIB_POSIXCHECK | |
681 | # if defined isnan | |
682 | _GL_WARN_REAL_FLOATING_DECL (isnan); | |
683 | # undef isnan | |
684 | # define isnan(x) _GL_WARN_REAL_FLOATING_IMPL (isnan, x) | |
685 | # endif | |
686 | #endif | |
687 | ||
688 | ||
689 | #if @GNULIB_SIGNBIT@ | |
690 | # if @REPLACE_SIGNBIT_USING_GCC@ | |
691 | # undef signbit | |
692 | /* GCC 4.0 and newer provides three built-ins for signbit. */ | |
693 | # define signbit(x) \ | |
694 | (sizeof (x) == sizeof (long double) ? __builtin_signbitl (x) : \ | |
695 | sizeof (x) == sizeof (double) ? __builtin_signbit (x) : \ | |
696 | __builtin_signbitf (x)) | |
697 | # endif | |
698 | # if @REPLACE_SIGNBIT@ | |
699 | # undef signbit | |
700 | _GL_EXTERN_C int gl_signbitf (float arg); | |
701 | _GL_EXTERN_C int gl_signbitd (double arg); | |
702 | _GL_EXTERN_C int gl_signbitl (long double arg); | |
703 | # if __GNUC__ >= 2 && !__STRICT_ANSI__ | |
704 | # if defined FLT_SIGNBIT_WORD && defined FLT_SIGNBIT_BIT && !defined gl_signbitf | |
705 | # define gl_signbitf_OPTIMIZED_MACRO | |
706 | # define gl_signbitf(arg) \ | |
707 | ({ union { float _value; \ | |
708 | unsigned int _word[(sizeof (float) + sizeof (unsigned int) - 1) / sizeof (unsigned int)]; \ | |
709 | } _m; \ | |
710 | _m._value = (arg); \ | |
711 | (_m._word[FLT_SIGNBIT_WORD] >> FLT_SIGNBIT_BIT) & 1; \ | |
712 | }) | |
713 | # endif | |
714 | # if defined DBL_SIGNBIT_WORD && defined DBL_SIGNBIT_BIT && !defined gl_signbitd | |
715 | # define gl_signbitd_OPTIMIZED_MACRO | |
716 | # define gl_signbitd(arg) \ | |
717 | ({ union { double _value; \ | |
718 | unsigned int _word[(sizeof (double) + sizeof (unsigned int) - 1) / sizeof (unsigned int)]; \ | |
719 | } _m; \ | |
720 | _m._value = (arg); \ | |
721 | (_m._word[DBL_SIGNBIT_WORD] >> DBL_SIGNBIT_BIT) & 1; \ | |
722 | }) | |
723 | # endif | |
724 | # if defined LDBL_SIGNBIT_WORD && defined LDBL_SIGNBIT_BIT && !defined gl_signbitl | |
725 | # define gl_signbitl_OPTIMIZED_MACRO | |
726 | # define gl_signbitl(arg) \ | |
727 | ({ union { long double _value; \ | |
728 | unsigned int _word[(sizeof (long double) + sizeof (unsigned int) - 1) / sizeof (unsigned int)]; \ | |
729 | } _m; \ | |
730 | _m._value = (arg); \ | |
731 | (_m._word[LDBL_SIGNBIT_WORD] >> LDBL_SIGNBIT_BIT) & 1; \ | |
732 | }) | |
733 | # endif | |
734 | # endif | |
735 | # define signbit(x) \ | |
736 | (sizeof (x) == sizeof (long double) ? gl_signbitl (x) : \ | |
737 | sizeof (x) == sizeof (double) ? gl_signbitd (x) : \ | |
738 | gl_signbitf (x)) | |
739 | # endif | |
740 | #elif defined GNULIB_POSIXCHECK | |
741 | # if defined signbit | |
742 | _GL_WARN_REAL_FLOATING_DECL (signbit); | |
743 | # undef signbit | |
744 | # define signbit(x) _GL_WARN_REAL_FLOATING_IMPL (signbit, x) | |
745 | # endif | |
746 | #endif | |
747 | ||
748 | ||
749 | #endif /* _GL_MATH_H */ | |
750 | #endif /* _GL_MATH_H */ |