maint.mk (sc_Wundef_boolean): Skip test if no config.h.
[gnulib.git] / lib / math.in.h
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 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 General Public License for more details.
14
15    You should have received a copy of the GNU 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 _GL_CXXALIAS_SYS (ceilf, float, (float x));
191 # endif
192 _GL_CXXALIASWARN (ceilf);
193 #elif defined GNULIB_POSIXCHECK
194 # undef ceilf
195 # if HAVE_RAW_DECL_CEILF
196 _GL_WARN_ON_USE (ceilf, "ceilf is unportable - "
197                  "use gnulib module ceilf for portability");
198 # endif
199 #endif
200
201 #if @GNULIB_CEILL@
202 # if @REPLACE_CEILL@
203 #  if !(defined __cplusplus && defined GNULIB_NAMESPACE)
204 #   define ceill rpl_ceill
205 #  endif
206 _GL_FUNCDECL_RPL (ceill, long double, (long double x));
207 _GL_CXXALIAS_RPL (ceill, long double, (long double x));
208 # else
209 _GL_CXXALIAS_SYS (ceill, long double, (long double x));
210 # endif
211 _GL_CXXALIASWARN (ceill);
212 #elif defined GNULIB_POSIXCHECK
213 # undef ceill
214 # if HAVE_RAW_DECL_CEILL
215 _GL_WARN_ON_USE (ceill, "ceill is unportable - "
216                  "use gnulib module ceill for portability");
217 # endif
218 #endif
219
220
221 #if @GNULIB_COSL@
222 # if !@HAVE_COSL@
223 #  if !(defined __cplusplus && defined GNULIB_NAMESPACE)
224 #   undef cosl
225 #   define cosl rpl_cosl
226 #  endif
227 _GL_FUNCDECL_RPL (cosl, long double, (long double x));
228 _GL_CXXALIAS_RPL (cosl, long double, (long double x));
229 # else
230 #  if !@HAVE_DECL_COSL@
231 _GL_FUNCDECL_SYS (cosl, long double, (long double x));
232 #  endif
233 _GL_CXXALIAS_SYS (cosl, long double, (long double x));
234 # endif
235 _GL_CXXALIASWARN (cosl);
236 #elif defined GNULIB_POSIXCHECK
237 # undef cosl
238 # if HAVE_RAW_DECL_COSL
239 _GL_WARN_ON_USE (cosl, "cosl is unportable - "
240                  "use gnulib module mathl for portability");
241 # endif
242 #endif
243
244
245 #if @GNULIB_EXPL@
246 # if !@HAVE_EXPL@ || !@HAVE_DECL_EXPL@
247 _GL_FUNCDECL_SYS (expl, long double, (long double x));
248 # endif
249 _GL_CXXALIAS_SYS (expl, long double, (long double x));
250 _GL_CXXALIASWARN (expl);
251 #elif defined GNULIB_POSIXCHECK
252 # undef expl
253 # if HAVE_RAW_DECL_EXPL
254 _GL_WARN_ON_USE (expl, "expl is unportable - "
255                  "use gnulib module mathl for portability");
256 # endif
257 #endif
258
259
260 #if @GNULIB_FLOORF@
261 # if @REPLACE_FLOORF@
262 #  if !(defined __cplusplus && defined GNULIB_NAMESPACE)
263 #   define floorf rpl_floorf
264 #  endif
265 _GL_FUNCDECL_RPL (floorf, float, (float x));
266 _GL_CXXALIAS_RPL (floorf, float, (float x));
267 #else
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 _GL_CXXALIAS_SYS (floorl, long double, (long double x));
288 # endif
289 _GL_CXXALIASWARN (floorl);
290 #elif defined GNULIB_POSIXCHECK
291 # undef floorl
292 # if HAVE_RAW_DECL_FLOORL
293 _GL_WARN_ON_USE (floorl, "floorl is unportable - "
294                  "use gnulib module floorl for portability");
295 # endif
296 #endif
297
298
299 /* Write x as
300      x = mantissa * 2^exp
301    where
302      If x finite and nonzero: 0.5 <= |mantissa| < 1.0.
303      If x is zero: mantissa = x, exp = 0.
304      If x is infinite or NaN: mantissa = x, exp unspecified.
305    Store exp in *EXPPTR and return mantissa.  */
306 #if @GNULIB_FREXPL@ && @REPLACE_FREXPL@
307 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
308 #  define frexpl rpl_frexpl
309 # endif
310 _GL_FUNCDECL_RPL (frexpl, long double,
311                   (long double x, int *expptr) _GL_ARG_NONNULL ((2)));
312 _GL_CXXALIAS_RPL (frexpl, long double, (long double x, int *expptr));
313 #else
314 # if !@HAVE_DECL_FREXPL@
315 _GL_FUNCDECL_SYS (frexpl, long double,
316                   (long double x, int *expptr) _GL_ARG_NONNULL ((2)));
317 # endif
318 # if @GNULIB_FREXPL@
319 _GL_CXXALIAS_SYS (frexpl, long double, (long double x, int *expptr));
320 # endif
321 #endif
322 #if @GNULIB_FREXPL@
323 _GL_CXXALIASWARN (frexpl);
324 #endif
325 #if !@GNULIB_FREXPL@ && defined GNULIB_POSIXCHECK
326 # undef frexpl
327 # if HAVE_RAW_DECL_FREXPL
328 _GL_WARN_ON_USE (frexpl, "frexpl is unportable - "
329                  "use gnulib module frexpl for portability");
330 # endif
331 #endif
332
333
334 /* Return x * 2^exp.  */
335 #if @GNULIB_LDEXPL@ && @REPLACE_LDEXPL@
336 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
337 #  define ldexpl rpl_ldexpl
338 # endif
339 _GL_FUNCDECL_RPL (ldexpl, long double, (long double x, int exp));
340 _GL_CXXALIAS_RPL (ldexpl, long double, (long double x, int exp));
341 #else
342 # if !@HAVE_DECL_LDEXPL@
343 _GL_FUNCDECL_SYS (ldexpl, long double, (long double x, int exp));
344 # endif
345 # if @GNULIB_LDEXPL@
346 _GL_CXXALIAS_SYS (ldexpl, long double, (long double x, int exp));
347 # endif
348 #endif
349 #if @GNULIB_LDEXPL@
350 _GL_CXXALIASWARN (ldexpl);
351 #endif
352 #if !@GNULIB_LDEXPL@ && defined GNULIB_POSIXCHECK
353 # undef ldexpl
354 # if HAVE_RAW_DECL_LDEXPL
355 _GL_WARN_ON_USE (ldexpl, "ldexpl is unportable - "
356                  "use gnulib module ldexpl for portability");
357 # endif
358 #endif
359
360
361 #if @GNULIB_LOGL@
362 # if !@HAVE_LOGL@
363 #  if !(defined __cplusplus && defined GNULIB_NAMESPACE)
364 #   undef logl
365 #   define logl rpl_logl
366 #  endif
367 _GL_FUNCDECL_RPL (logl, long double, (long double x));
368 _GL_CXXALIAS_RPL (logl, long double, (long double x));
369 # else
370 #  if !@HAVE_DECL_LOGL@
371 _GL_FUNCDECL_SYS (logl, long double, (long double x));
372 #  endif
373 _GL_CXXALIAS_SYS (logl, long double, (long double x));
374 # endif
375 _GL_CXXALIASWARN (logl);
376 #elif defined GNULIB_POSIXCHECK
377 # undef logl
378 # if HAVE_RAW_DECL_LOGL
379 _GL_WARN_ON_USE (logl, "logl is unportable - "
380                  "use gnulib module mathl for portability");
381 # endif
382 #endif
383
384
385 #if @GNULIB_ROUNDF@
386 # if @REPLACE_ROUNDF@
387 #  if !(defined __cplusplus && defined GNULIB_NAMESPACE)
388 #   undef roundf
389 #   define roundf rpl_roundf
390 #  endif
391 _GL_FUNCDECL_RPL (roundf, float, (float x));
392 _GL_CXXALIAS_RPL (roundf, float, (float x));
393 # else
394 _GL_CXXALIAS_SYS (roundf, float, (float x));
395 # endif
396 _GL_CXXALIASWARN (roundf);
397 #elif defined GNULIB_POSIXCHECK
398 # undef roundf
399 # if HAVE_RAW_DECL_ROUNDF
400 _GL_WARN_ON_USE (roundf, "roundf is unportable - "
401                  "use gnulib module roundf for portability");
402 # endif
403 #endif
404
405 #if @GNULIB_ROUND@
406 # if @REPLACE_ROUND@
407 #  if !(defined __cplusplus && defined GNULIB_NAMESPACE)
408 #   undef round
409 #   define round rpl_round
410 #  endif
411 _GL_FUNCDECL_RPL (round, double, (double x));
412 _GL_CXXALIAS_RPL (round, double, (double x));
413 # else
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 _GL_CXXALIAS_SYS (roundl, long double, (long double x));
435 # endif
436 _GL_CXXALIASWARN (roundl);
437 #elif defined GNULIB_POSIXCHECK
438 # undef roundl
439 # if HAVE_RAW_DECL_ROUNDL
440 _GL_WARN_ON_USE (roundl, "roundl is unportable - "
441                  "use gnulib module roundl for portability");
442 # endif
443 #endif
444
445
446 #if @GNULIB_SINL@
447 # if !@HAVE_SINL@
448 #  if !(defined __cplusplus && defined GNULIB_NAMESPACE)
449 #   undef sinl
450 #   define sinl rpl_sinl
451 #  endif
452 _GL_FUNCDECL_RPL (sinl, long double, (long double x));
453 _GL_CXXALIAS_RPL (sinl, long double, (long double x));
454 # else
455 #  if !@HAVE_DECL_SINL@
456 _GL_FUNCDECL_SYS (sinl, long double, (long double x));
457 #  endif
458 _GL_CXXALIAS_SYS (sinl, long double, (long double x));
459 # endif
460 _GL_CXXALIASWARN (sinl);
461 #elif defined GNULIB_POSIXCHECK
462 # undef sinl
463 # if HAVE_RAW_DECL_SINL
464 _GL_WARN_ON_USE (sinl, "sinl is unportable - "
465                  "use gnulib module mathl for portability");
466 # endif
467 #endif
468
469
470 #if @GNULIB_SQRTL@
471 # if !@HAVE_SQRTL@ || !@HAVE_DECL_SQRTL@
472 _GL_FUNCDECL_SYS (sqrtl, long double, (long double x));
473 # endif
474 _GL_CXXALIAS_SYS (sqrtl, long double, (long double x));
475 _GL_CXXALIASWARN (sqrtl);
476 #elif defined GNULIB_POSIXCHECK
477 # undef sqrtl
478 # if HAVE_RAW_DECL_SQRTL
479 _GL_WARN_ON_USE (sqrtl, "sqrtl is unportable - "
480                  "use gnulib module mathl for portability");
481 # endif
482 #endif
483
484
485 #if @GNULIB_TANL@
486 # if !@HAVE_TANL@ || !@HAVE_DECL_TANL@
487 _GL_FUNCDECL_SYS (tanl, long double, (long double x));
488 # endif
489 _GL_CXXALIAS_SYS (tanl, long double, (long double x));
490 _GL_CXXALIASWARN (tanl);
491 #elif defined GNULIB_POSIXCHECK
492 # undef tanl
493 # if HAVE_RAW_DECL_TANL
494 _GL_WARN_ON_USE (tanl, "tanl is unportable - "
495                  "use gnulib module mathl for portability");
496 # endif
497 #endif
498
499
500 #if @GNULIB_TRUNCF@
501 # if !@HAVE_DECL_TRUNCF@
502 #  if !(defined __cplusplus && defined GNULIB_NAMESPACE)
503 #   define truncf rpl_truncf
504 #  endif
505 _GL_FUNCDECL_RPL (truncf, float, (float x));
506 _GL_CXXALIAS_RPL (truncf, float, (float x));
507 # else
508 _GL_CXXALIAS_SYS (truncf, float, (float x));
509 # endif
510 _GL_CXXALIASWARN (truncf);
511 #elif defined GNULIB_POSIXCHECK
512 # undef truncf
513 # if HAVE_RAW_DECL_TRUNCF
514 _GL_WARN_ON_USE (truncf, "truncf is unportable - "
515                  "use gnulib module truncf for portability");
516 # endif
517 #endif
518
519 #if @GNULIB_TRUNC@
520 # if !@HAVE_DECL_TRUNC@
521 #  if !(defined __cplusplus && defined GNULIB_NAMESPACE)
522 #   define trunc rpl_trunc
523 #  endif
524 _GL_FUNCDECL_RPL (trunc, double, (double x));
525 _GL_CXXALIAS_RPL (trunc, double, (double x));
526 # else
527 _GL_CXXALIAS_SYS (trunc, double, (double x));
528 # endif
529 _GL_CXXALIASWARN (trunc);
530 #elif defined GNULIB_POSIXCHECK
531 # undef trunc
532 # if HAVE_RAW_DECL_TRUNC
533 _GL_WARN_ON_USE (trunc, "trunc is unportable - "
534                  "use gnulib module trunc for portability");
535 # endif
536 #endif
537
538 #if @GNULIB_TRUNCL@
539 # if @REPLACE_TRUNCL@
540 #  if !(defined __cplusplus && defined GNULIB_NAMESPACE)
541 #   undef truncl
542 #   define truncl rpl_truncl
543 #  endif
544 _GL_FUNCDECL_RPL (truncl, long double, (long double x));
545 _GL_CXXALIAS_RPL (truncl, long double, (long double x));
546 # else
547 _GL_CXXALIAS_SYS (truncl, long double, (long double x));
548 # endif
549 _GL_CXXALIASWARN (truncl);
550 #elif defined GNULIB_POSIXCHECK
551 # undef truncl
552 # if HAVE_RAW_DECL_TRUNCL
553 _GL_WARN_ON_USE (truncl, "truncl is unportable - "
554                  "use gnulib module truncl for portability");
555 # endif
556 #endif
557
558
559 #if @GNULIB_ISFINITE@
560 # if @REPLACE_ISFINITE@
561 _GL_EXTERN_C int gl_isfinitef (float x);
562 _GL_EXTERN_C int gl_isfinited (double x);
563 _GL_EXTERN_C int gl_isfinitel (long double x);
564 #  undef isfinite
565 #  define isfinite(x) \
566    (sizeof (x) == sizeof (long double) ? gl_isfinitel (x) : \
567     sizeof (x) == sizeof (double) ? gl_isfinited (x) : \
568     gl_isfinitef (x))
569 # endif
570 #elif defined GNULIB_POSIXCHECK
571 # if defined isfinite
572 _GL_WARN_REAL_FLOATING_DECL (isfinite);
573 #  undef isfinite
574 #  define isfinite(x) _GL_WARN_REAL_FLOATING_IMPL (isfinite, x)
575 # endif
576 #endif
577
578
579 #if @GNULIB_ISINF@
580 # if @REPLACE_ISINF@
581 _GL_EXTERN_C int gl_isinff (float x);
582 _GL_EXTERN_C int gl_isinfd (double x);
583 _GL_EXTERN_C int gl_isinfl (long double x);
584 #  undef isinf
585 #  define isinf(x) \
586    (sizeof (x) == sizeof (long double) ? gl_isinfl (x) : \
587     sizeof (x) == sizeof (double) ? gl_isinfd (x) : \
588     gl_isinff (x))
589 # endif
590 #elif defined GNULIB_POSIXCHECK
591 # if defined isinf
592 _GL_WARN_REAL_FLOATING_DECL (isinf);
593 #  undef isinf
594 #  define isinf(x) _GL_WARN_REAL_FLOATING_IMPL (isinf, x)
595 # endif
596 #endif
597
598
599 #if @GNULIB_ISNANF@
600 /* Test for NaN for 'float' numbers.  */
601 # if @HAVE_ISNANF@
602 /* The original <math.h> included above provides a declaration of isnan macro
603    or (older) isnanf function.  */
604 #  if __GNUC__ >= 4
605     /* GCC 4.0 and newer provides three built-ins for isnan.  */
606 #   undef isnanf
607 #   define isnanf(x) __builtin_isnanf ((float)(x))
608 #  elif defined isnan
609 #   undef isnanf
610 #   define isnanf(x) isnan ((float)(x))
611 #  endif
612 # else
613 /* Test whether X is a NaN.  */
614 #  undef isnanf
615 #  define isnanf rpl_isnanf
616 _GL_EXTERN_C int isnanf (float x);
617 # endif
618 #endif
619
620 #if @GNULIB_ISNAND@
621 /* Test for NaN for 'double' numbers.
622    This function is a gnulib extension, unlike isnan() which applied only
623    to 'double' numbers earlier but now is a type-generic macro.  */
624 # if @HAVE_ISNAND@
625 /* The original <math.h> included above provides a declaration of isnan macro.  */
626 #  if __GNUC__ >= 4
627     /* GCC 4.0 and newer provides three built-ins for isnan.  */
628 #   undef isnand
629 #   define isnand(x) __builtin_isnan ((double)(x))
630 #  else
631 #   undef isnand
632 #   define isnand(x) isnan ((double)(x))
633 #  endif
634 # else
635 /* Test whether X is a NaN.  */
636 #  undef isnand
637 #  define isnand rpl_isnand
638 _GL_EXTERN_C int isnand (double x);
639 # endif
640 #endif
641
642 #if @GNULIB_ISNANL@
643 /* Test for NaN for 'long double' numbers.  */
644 # if @HAVE_ISNANL@
645 /* The original <math.h> included above provides a declaration of isnan macro or (older) isnanl function.  */
646 #  if __GNUC__ >= 4
647     /* GCC 4.0 and newer provides three built-ins for isnan.  */
648 #   undef isnanl
649 #   define isnanl(x) __builtin_isnanl ((long double)(x))
650 #  elif defined isnan
651 #   undef isnanl
652 #   define isnanl(x) isnan ((long double)(x))
653 #  endif
654 # else
655 /* Test whether X is a NaN.  */
656 #  undef isnanl
657 #  define isnanl rpl_isnanl
658 _GL_EXTERN_C int isnanl (long double x);
659 # endif
660 #endif
661
662 /* This must come *after* the snippets for GNULIB_ISNANF and GNULIB_ISNANL!  */
663 #if @GNULIB_ISNAN@
664 # if @REPLACE_ISNAN@
665 /* We can't just use the isnanf macro (e.g.) as exposed by
666    isnanf.h (e.g.) here, because those may end up being macros
667    that recursively expand back to isnan.  So use the gnulib
668    replacements for them directly. */
669 #  if @HAVE_ISNANF@ && __GNUC__ >= 4
670 #   define gl_isnan_f(x) __builtin_isnan ((float)(x))
671 #  else
672 _GL_EXTERN_C int rpl_isnanf (float x);
673 #   define gl_isnan_f(x) rpl_isnanf (x)
674 #  endif
675 #  if @HAVE_ISNAND@ && __GNUC__ >= 4
676 #   define gl_isnan_d(x) __builtin_isnan ((double)(x))
677 #  else
678 _GL_EXTERN_C int rpl_isnand (double x);
679 #   define gl_isnan_d(x) rpl_isnand (x)
680 #  endif
681 #  if @HAVE_ISNANL@ && __GNUC__ >= 4
682 #   define gl_isnan_l(x) __builtin_isnan ((long double)(x))
683 #  else
684 _GL_EXTERN_C int rpl_isnanl (long double x);
685 #   define gl_isnan_l(x) rpl_isnanl (x)
686 #  endif
687 #  undef isnan
688 #  define isnan(x) \
689    (sizeof (x) == sizeof (long double) ? gl_isnan_l (x) : \
690     sizeof (x) == sizeof (double) ? gl_isnan_d (x) : \
691     gl_isnan_f (x))
692 # endif
693 #elif defined GNULIB_POSIXCHECK
694 # if defined isnan
695 _GL_WARN_REAL_FLOATING_DECL (isnan);
696 #  undef isnan
697 #  define isnan(x) _GL_WARN_REAL_FLOATING_IMPL (isnan, x)
698 # endif
699 #endif
700
701
702 #if @GNULIB_SIGNBIT@
703 # if @REPLACE_SIGNBIT_USING_GCC@
704 #  undef signbit
705    /* GCC 4.0 and newer provides three built-ins for signbit.  */
706 #  define signbit(x) \
707    (sizeof (x) == sizeof (long double) ? __builtin_signbitl (x) : \
708     sizeof (x) == sizeof (double) ? __builtin_signbit (x) : \
709     __builtin_signbitf (x))
710 # endif
711 # if @REPLACE_SIGNBIT@
712 #  undef signbit
713 _GL_EXTERN_C int gl_signbitf (float arg);
714 _GL_EXTERN_C int gl_signbitd (double arg);
715 _GL_EXTERN_C int gl_signbitl (long double arg);
716 #  if __GNUC__ >= 2 && !__STRICT_ANSI__
717 #   if defined FLT_SIGNBIT_WORD && defined FLT_SIGNBIT_BIT && !defined gl_signbitf
718 #    define gl_signbitf_OPTIMIZED_MACRO
719 #    define gl_signbitf(arg) \
720        ({ union { float _value;                                         \
721                   unsigned int _word[(sizeof (float) + sizeof (unsigned int) - 1) / sizeof (unsigned int)]; \
722                 } _m;                                                   \
723           _m._value = (arg);                                            \
724           (_m._word[FLT_SIGNBIT_WORD] >> FLT_SIGNBIT_BIT) & 1;          \
725         })
726 #   endif
727 #   if defined DBL_SIGNBIT_WORD && defined DBL_SIGNBIT_BIT && !defined gl_signbitd
728 #    define gl_signbitd_OPTIMIZED_MACRO
729 #    define gl_signbitd(arg) \
730        ({ union { double _value;                                                \
731                   unsigned int _word[(sizeof (double) + sizeof (unsigned int) - 1) / sizeof (unsigned int)]; \
732                 } _m;                                                   \
733           _m._value = (arg);                                            \
734           (_m._word[DBL_SIGNBIT_WORD] >> DBL_SIGNBIT_BIT) & 1;          \
735         })
736 #   endif
737 #   if defined LDBL_SIGNBIT_WORD && defined LDBL_SIGNBIT_BIT && !defined gl_signbitl
738 #    define gl_signbitl_OPTIMIZED_MACRO
739 #    define gl_signbitl(arg) \
740        ({ union { long double _value;                                   \
741                   unsigned int _word[(sizeof (long double) + sizeof (unsigned int) - 1) / sizeof (unsigned int)]; \
742                 } _m;                                                   \
743           _m._value = (arg);                                            \
744           (_m._word[LDBL_SIGNBIT_WORD] >> LDBL_SIGNBIT_BIT) & 1;                \
745         })
746 #   endif
747 #  endif
748 #  define signbit(x) \
749    (sizeof (x) == sizeof (long double) ? gl_signbitl (x) : \
750     sizeof (x) == sizeof (double) ? gl_signbitd (x) : \
751     gl_signbitf (x))
752 # endif
753 #elif defined GNULIB_POSIXCHECK
754 # if defined signbit
755 _GL_WARN_REAL_FLOATING_DECL (signbit);
756 #  undef signbit
757 #  define signbit(x) _GL_WARN_REAL_FLOATING_IMPL (signbit, x)
758 # endif
759 #endif
760
761
762 #endif /* _GL_MATH_H */
763 #endif /* _GL_MATH_H */