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