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