1 /* A GNU-like <math.h>.
3 Copyright (C) 2002-2003, 2007-2011 Free Software Foundation, Inc.
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.
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.
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/>. */
21 @PRAGMA_SYSTEM_HEADER@
25 /* The include_next requires a split double-inclusion guard. */
26 #@INCLUDE_NEXT_AS_FIRST_DIRECTIVE@ @NEXT_AS_FIRST_DIRECTIVE_MATH_H@
32 /* The definitions of _GL_FUNCDECL_RPL etc. are copied here. */
34 /* The definition of _GL_ARG_NONNULL is copied here. */
36 /* The definition of _GL_WARN_ON_USE is copied here. */
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) \
44 rpl_ ## func ## f (float f) \
49 rpl_ ## func ## d (double d) \
54 rpl_ ## func ## l (long double l) \
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))
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 # if !GNULIB_defined_NAN
78 /* The Compaq (ex-DEC) C 6.4 compiler chokes on the expression 0.0 / 0.0. */
83 static float zero = 0.0f;
88 # define NAN (0.0f / 0.0f)
90 # define GNULIB_defined_NAN 1
94 /* Solaris 10 defines HUGE_VAL, but as a function pointer rather
95 than a floating point constant. */
96 #if @REPLACE_HUGE_VAL@
98 # define HUGE_VAL (1.0 / 0.0)
105 If x finite and nonzero: 0.5 <= |mantissa| < 1.0.
106 If x is zero: mantissa = x, exp = 0.
107 If x is infinite or NaN: mantissa = x, exp unspecified.
108 Store exp in *EXPPTR and return mantissa. */
111 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
112 # define frexp rpl_frexp
114 _GL_FUNCDECL_RPL (frexp, double, (double x, int *expptr) _GL_ARG_NONNULL ((2)));
115 _GL_CXXALIAS_RPL (frexp, double, (double x, int *expptr));
117 _GL_CXXALIAS_SYS (frexp, double, (double x, int *expptr));
119 _GL_CXXALIASWARN (frexp);
120 #elif defined GNULIB_POSIXCHECK
122 /* Assume frexp is always declared. */
123 _GL_WARN_ON_USE (frexp, "frexp is unportable - "
124 "use gnulib module frexp for portability");
129 # if !@HAVE_DECL_LOGB@
130 _GL_EXTERN_C double logb (double x);
132 #elif defined GNULIB_POSIXCHECK
134 # if HAVE_RAW_DECL_LOGB
135 _GL_WARN_ON_USE (logb, "logb is unportable - "
136 "use gnulib module logb for portability");
142 # if !@HAVE_ACOSL@ || !@HAVE_DECL_ACOSL@
143 _GL_FUNCDECL_SYS (acosl, long double, (long double x));
145 _GL_CXXALIAS_SYS (acosl, long double, (long double x));
146 _GL_CXXALIASWARN (acosl);
147 #elif defined GNULIB_POSIXCHECK
149 # if HAVE_RAW_DECL_ACOSL
150 _GL_WARN_ON_USE (acosl, "acosl is unportable - "
151 "use gnulib module mathl for portability");
157 # if !@HAVE_ASINL@ || !@HAVE_DECL_ASINL@
158 _GL_FUNCDECL_SYS (asinl, long double, (long double x));
160 _GL_CXXALIAS_SYS (asinl, long double, (long double x));
161 _GL_CXXALIASWARN (asinl);
162 #elif defined GNULIB_POSIXCHECK
164 # if HAVE_RAW_DECL_ASINL
165 _GL_WARN_ON_USE (asinl, "asinl is unportable - "
166 "use gnulib module mathl for portability");
172 # if !@HAVE_ATANL@ || !@HAVE_DECL_ATANL@
173 _GL_FUNCDECL_SYS (atanl, long double, (long double x));
175 _GL_CXXALIAS_SYS (atanl, long double, (long double x));
176 _GL_CXXALIASWARN (atanl);
177 #elif defined GNULIB_POSIXCHECK
179 # if HAVE_RAW_DECL_ATANL
180 _GL_WARN_ON_USE (atanl, "atanl is unportable - "
181 "use gnulib module mathl for portability");
188 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
189 # define ceilf rpl_ceilf
191 _GL_FUNCDECL_RPL (ceilf, float, (float x));
192 _GL_CXXALIAS_RPL (ceilf, float, (float x));
194 # if !@HAVE_DECL_CEILF@
195 _GL_FUNCDECL_SYS (ceilf, float, (float x));
197 _GL_CXXALIAS_SYS (ceilf, float, (float x));
199 _GL_CXXALIASWARN (ceilf);
200 #elif defined GNULIB_POSIXCHECK
202 # if HAVE_RAW_DECL_CEILF
203 _GL_WARN_ON_USE (ceilf, "ceilf is unportable - "
204 "use gnulib module ceilf for portability");
210 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
211 # define ceil rpl_ceil
213 _GL_FUNCDECL_RPL (ceil, double, (double x));
214 _GL_CXXALIAS_RPL (ceil, double, (double x));
216 _GL_CXXALIAS_SYS (ceil, double, (double x));
218 _GL_CXXALIASWARN (ceil);
223 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
224 # define ceill rpl_ceill
226 _GL_FUNCDECL_RPL (ceill, long double, (long double x));
227 _GL_CXXALIAS_RPL (ceill, long double, (long double x));
229 # if !@HAVE_DECL_CEILL@
230 _GL_FUNCDECL_SYS (ceill, long double, (long double x));
232 _GL_CXXALIAS_SYS (ceill, long double, (long double x));
234 _GL_CXXALIASWARN (ceill);
235 #elif defined GNULIB_POSIXCHECK
237 # if HAVE_RAW_DECL_CEILL
238 _GL_WARN_ON_USE (ceill, "ceill is unportable - "
239 "use gnulib module ceill for portability");
245 # if !@HAVE_COSL@ || !@HAVE_DECL_COSL@
246 _GL_FUNCDECL_SYS (cosl, long double, (long double x));
248 _GL_CXXALIAS_SYS (cosl, long double, (long double x));
249 _GL_CXXALIASWARN (cosl);
250 #elif defined GNULIB_POSIXCHECK
252 # if HAVE_RAW_DECL_COSL
253 _GL_WARN_ON_USE (cosl, "cosl is unportable - "
254 "use gnulib module mathl for portability");
260 # if !@HAVE_EXPL@ || !@HAVE_DECL_EXPL@
261 _GL_FUNCDECL_SYS (expl, long double, (long double x));
263 _GL_CXXALIAS_SYS (expl, long double, (long double x));
264 _GL_CXXALIASWARN (expl);
265 #elif defined GNULIB_POSIXCHECK
267 # if HAVE_RAW_DECL_EXPL
268 _GL_WARN_ON_USE (expl, "expl is unportable - "
269 "use gnulib module mathl for portability");
275 # if @REPLACE_FLOORF@
276 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
277 # define floorf rpl_floorf
279 _GL_FUNCDECL_RPL (floorf, float, (float x));
280 _GL_CXXALIAS_RPL (floorf, float, (float x));
282 # if !@HAVE_DECL_FLOORF@
283 _GL_FUNCDECL_SYS (floorf, float, (float x));
285 _GL_CXXALIAS_SYS (floorf, float, (float x));
287 _GL_CXXALIASWARN (floorf);
288 #elif defined GNULIB_POSIXCHECK
290 # if HAVE_RAW_DECL_FLOORF
291 _GL_WARN_ON_USE (floorf, "floorf is unportable - "
292 "use gnulib module floorf for portability");
298 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
299 # define floor rpl_floor
301 _GL_FUNCDECL_RPL (floor, double, (double x));
302 _GL_CXXALIAS_RPL (floor, double, (double x));
304 _GL_CXXALIAS_SYS (floor, double, (double x));
306 _GL_CXXALIASWARN (floor);
310 # if @REPLACE_FLOORL@
311 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
312 # define floorl rpl_floorl
314 _GL_FUNCDECL_RPL (floorl, long double, (long double x));
315 _GL_CXXALIAS_RPL (floorl, long double, (long double x));
317 # if !@HAVE_DECL_FLOORL@
318 _GL_FUNCDECL_SYS (floorl, long double, (long double x));
320 _GL_CXXALIAS_SYS (floorl, long double, (long double x));
322 _GL_CXXALIASWARN (floorl);
323 #elif defined GNULIB_POSIXCHECK
325 # if HAVE_RAW_DECL_FLOORL
326 _GL_WARN_ON_USE (floorl, "floorl is unportable - "
327 "use gnulib module floorl for portability");
335 If x finite and nonzero: 0.5 <= |mantissa| < 1.0.
336 If x is zero: mantissa = x, exp = 0.
337 If x is infinite or NaN: mantissa = x, exp unspecified.
338 Store exp in *EXPPTR and return mantissa. */
339 #if @GNULIB_FREXPL@ && @REPLACE_FREXPL@
340 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
341 # define frexpl rpl_frexpl
343 _GL_FUNCDECL_RPL (frexpl, long double,
344 (long double x, int *expptr) _GL_ARG_NONNULL ((2)));
345 _GL_CXXALIAS_RPL (frexpl, long double, (long double x, int *expptr));
347 # if !@HAVE_DECL_FREXPL@
348 _GL_FUNCDECL_SYS (frexpl, long double,
349 (long double x, int *expptr) _GL_ARG_NONNULL ((2)));
352 _GL_CXXALIAS_SYS (frexpl, long double, (long double x, int *expptr));
355 #if @GNULIB_FREXPL@ && !(@REPLACE_FREXPL@ && !@HAVE_DECL_FREXPL@)
356 _GL_CXXALIASWARN (frexpl);
358 #if !@GNULIB_FREXPL@ && defined GNULIB_POSIXCHECK
360 # if HAVE_RAW_DECL_FREXPL
361 _GL_WARN_ON_USE (frexpl, "frexpl is unportable - "
362 "use gnulib module frexpl for portability");
367 /* Return x * 2^exp. */
368 #if @GNULIB_LDEXPL@ && @REPLACE_LDEXPL@
369 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
370 # define ldexpl rpl_ldexpl
372 _GL_FUNCDECL_RPL (ldexpl, long double, (long double x, int exp));
373 _GL_CXXALIAS_RPL (ldexpl, long double, (long double x, int exp));
375 # if !@HAVE_DECL_LDEXPL@
376 _GL_FUNCDECL_SYS (ldexpl, long double, (long double x, int exp));
379 _GL_CXXALIAS_SYS (ldexpl, long double, (long double x, int exp));
383 _GL_CXXALIASWARN (ldexpl);
385 #if !@GNULIB_LDEXPL@ && defined GNULIB_POSIXCHECK
387 # if HAVE_RAW_DECL_LDEXPL
388 _GL_WARN_ON_USE (ldexpl, "ldexpl is unportable - "
389 "use gnulib module ldexpl for portability");
395 # if !@HAVE_LOGL@ || !@HAVE_DECL_LOGL@
396 _GL_FUNCDECL_SYS (logl, long double, (long double x));
398 _GL_CXXALIAS_SYS (logl, long double, (long double x));
399 _GL_CXXALIASWARN (logl);
400 #elif defined GNULIB_POSIXCHECK
402 # if HAVE_RAW_DECL_LOGL
403 _GL_WARN_ON_USE (logl, "logl is unportable - "
404 "use gnulib module mathl for portability");
410 # if @REPLACE_ROUNDF@
411 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
413 # define roundf rpl_roundf
415 _GL_FUNCDECL_RPL (roundf, float, (float x));
416 _GL_CXXALIAS_RPL (roundf, float, (float x));
418 # if !@HAVE_DECL_ROUNDF@
419 _GL_FUNCDECL_SYS (roundf, float, (float x));
421 _GL_CXXALIAS_SYS (roundf, float, (float x));
423 _GL_CXXALIASWARN (roundf);
424 #elif defined GNULIB_POSIXCHECK
426 # if HAVE_RAW_DECL_ROUNDF
427 _GL_WARN_ON_USE (roundf, "roundf is unportable - "
428 "use gnulib module roundf for portability");
434 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
436 # define round rpl_round
438 _GL_FUNCDECL_RPL (round, double, (double x));
439 _GL_CXXALIAS_RPL (round, double, (double x));
441 # if !@HAVE_DECL_ROUND@
442 _GL_FUNCDECL_SYS (round, double, (double x));
444 _GL_CXXALIAS_SYS (round, double, (double x));
446 _GL_CXXALIASWARN (round);
447 #elif defined GNULIB_POSIXCHECK
449 # if HAVE_RAW_DECL_ROUND
450 _GL_WARN_ON_USE (round, "round is unportable - "
451 "use gnulib module round for portability");
456 # if @REPLACE_ROUNDL@
457 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
459 # define roundl rpl_roundl
461 _GL_FUNCDECL_RPL (roundl, long double, (long double x));
462 _GL_CXXALIAS_RPL (roundl, long double, (long double x));
464 # if !@HAVE_DECL_ROUNDL@
465 _GL_FUNCDECL_SYS (roundl, long double, (long double x));
467 _GL_CXXALIAS_SYS (roundl, long double, (long double x));
469 _GL_CXXALIASWARN (roundl);
470 #elif defined GNULIB_POSIXCHECK
472 # if HAVE_RAW_DECL_ROUNDL
473 _GL_WARN_ON_USE (roundl, "roundl is unportable - "
474 "use gnulib module roundl for portability");
480 # if !@HAVE_SINL@ || !@HAVE_DECL_SINL@
481 _GL_FUNCDECL_SYS (sinl, long double, (long double x));
483 _GL_CXXALIAS_SYS (sinl, long double, (long double x));
484 _GL_CXXALIASWARN (sinl);
485 #elif defined GNULIB_POSIXCHECK
487 # if HAVE_RAW_DECL_SINL
488 _GL_WARN_ON_USE (sinl, "sinl is unportable - "
489 "use gnulib module mathl for portability");
495 # if !@HAVE_SQRTL@ || !@HAVE_DECL_SQRTL@
496 _GL_FUNCDECL_SYS (sqrtl, long double, (long double x));
498 _GL_CXXALIAS_SYS (sqrtl, long double, (long double x));
499 _GL_CXXALIASWARN (sqrtl);
500 #elif defined GNULIB_POSIXCHECK
502 # if HAVE_RAW_DECL_SQRTL
503 _GL_WARN_ON_USE (sqrtl, "sqrtl is unportable - "
504 "use gnulib module mathl for portability");
510 # if !@HAVE_TANL@ || !@HAVE_DECL_TANL@
511 _GL_FUNCDECL_SYS (tanl, long double, (long double x));
513 _GL_CXXALIAS_SYS (tanl, long double, (long double x));
514 _GL_CXXALIASWARN (tanl);
515 #elif defined GNULIB_POSIXCHECK
517 # if HAVE_RAW_DECL_TANL
518 _GL_WARN_ON_USE (tanl, "tanl is unportable - "
519 "use gnulib module mathl for portability");
525 # if @REPLACE_TRUNCF@
526 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
527 # define truncf rpl_truncf
529 _GL_FUNCDECL_RPL (truncf, float, (float x));
530 _GL_CXXALIAS_RPL (truncf, float, (float x));
532 # if !@HAVE_DECL_TRUNCF@
533 _GL_FUNCDECL_SYS (truncf, float, (float x));
535 _GL_CXXALIAS_SYS (truncf, float, (float x));
537 _GL_CXXALIASWARN (truncf);
538 #elif defined GNULIB_POSIXCHECK
540 # if HAVE_RAW_DECL_TRUNCF
541 _GL_WARN_ON_USE (truncf, "truncf is unportable - "
542 "use gnulib module truncf for portability");
548 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
549 # define trunc rpl_trunc
551 _GL_FUNCDECL_RPL (trunc, double, (double x));
552 _GL_CXXALIAS_RPL (trunc, double, (double x));
554 # if !@HAVE_DECL_TRUNC@
555 _GL_FUNCDECL_SYS (trunc, double, (double x));
557 _GL_CXXALIAS_SYS (trunc, double, (double x));
559 _GL_CXXALIASWARN (trunc);
560 #elif defined GNULIB_POSIXCHECK
562 # if HAVE_RAW_DECL_TRUNC
563 _GL_WARN_ON_USE (trunc, "trunc is unportable - "
564 "use gnulib module trunc for portability");
569 # if @REPLACE_TRUNCL@
570 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
572 # define truncl rpl_truncl
574 _GL_FUNCDECL_RPL (truncl, long double, (long double x));
575 _GL_CXXALIAS_RPL (truncl, long double, (long double x));
577 # if !@HAVE_DECL_TRUNCL@
578 _GL_FUNCDECL_SYS (truncl, long double, (long double x));
580 _GL_CXXALIAS_SYS (truncl, long double, (long double x));
582 _GL_CXXALIASWARN (truncl);
583 #elif defined GNULIB_POSIXCHECK
585 # if HAVE_RAW_DECL_TRUNCL
586 _GL_WARN_ON_USE (truncl, "truncl is unportable - "
587 "use gnulib module truncl for portability");
592 #if @GNULIB_ISFINITE@
593 # if @REPLACE_ISFINITE@
594 _GL_EXTERN_C int gl_isfinitef (float x);
595 _GL_EXTERN_C int gl_isfinited (double x);
596 _GL_EXTERN_C int gl_isfinitel (long double x);
598 # define isfinite(x) \
599 (sizeof (x) == sizeof (long double) ? gl_isfinitel (x) : \
600 sizeof (x) == sizeof (double) ? gl_isfinited (x) : \
603 #elif defined GNULIB_POSIXCHECK
604 # if defined isfinite
605 _GL_WARN_REAL_FLOATING_DECL (isfinite);
607 # define isfinite(x) _GL_WARN_REAL_FLOATING_IMPL (isfinite, x)
614 _GL_EXTERN_C int gl_isinff (float x);
615 _GL_EXTERN_C int gl_isinfd (double x);
616 _GL_EXTERN_C int gl_isinfl (long double x);
619 (sizeof (x) == sizeof (long double) ? gl_isinfl (x) : \
620 sizeof (x) == sizeof (double) ? gl_isinfd (x) : \
623 #elif defined GNULIB_POSIXCHECK
625 _GL_WARN_REAL_FLOATING_DECL (isinf);
627 # define isinf(x) _GL_WARN_REAL_FLOATING_IMPL (isinf, x)
633 /* Test for NaN for 'float' numbers. */
635 /* The original <math.h> included above provides a declaration of isnan macro
636 or (older) isnanf function. */
638 /* GCC 4.0 and newer provides three built-ins for isnan. */
640 # define isnanf(x) __builtin_isnanf ((float)(x))
643 # define isnanf(x) isnan ((float)(x))
646 /* Test whether X is a NaN. */
648 # define isnanf rpl_isnanf
649 _GL_EXTERN_C int isnanf (float x);
654 /* Test for NaN for 'double' numbers.
655 This function is a gnulib extension, unlike isnan() which applied only
656 to 'double' numbers earlier but now is a type-generic macro. */
658 /* The original <math.h> included above provides a declaration of isnan
661 /* GCC 4.0 and newer provides three built-ins for isnan. */
663 # define isnand(x) __builtin_isnan ((double)(x))
666 # define isnand(x) isnan ((double)(x))
669 /* Test whether X is a NaN. */
671 # define isnand rpl_isnand
672 _GL_EXTERN_C int isnand (double x);
677 /* Test for NaN for 'long double' numbers. */
679 /* The original <math.h> included above provides a declaration of isnan
680 macro or (older) isnanl function. */
682 /* GCC 4.0 and newer provides three built-ins for isnan. */
684 # define isnanl(x) __builtin_isnanl ((long double)(x))
687 # define isnanl(x) isnan ((long double)(x))
690 /* Test whether X is a NaN. */
692 # define isnanl rpl_isnanl
693 _GL_EXTERN_C int isnanl (long double x);
697 /* This must come *after* the snippets for GNULIB_ISNANF and GNULIB_ISNANL! */
700 /* We can't just use the isnanf macro (e.g.) as exposed by
701 isnanf.h (e.g.) here, because those may end up being macros
702 that recursively expand back to isnan. So use the gnulib
703 replacements for them directly. */
704 # if @HAVE_ISNANF@ && __GNUC__ >= 4
705 # define gl_isnan_f(x) __builtin_isnanf ((float)(x))
707 _GL_EXTERN_C int rpl_isnanf (float x);
708 # define gl_isnan_f(x) rpl_isnanf (x)
710 # if @HAVE_ISNAND@ && __GNUC__ >= 4
711 # define gl_isnan_d(x) __builtin_isnan ((double)(x))
713 _GL_EXTERN_C int rpl_isnand (double x);
714 # define gl_isnan_d(x) rpl_isnand (x)
716 # if @HAVE_ISNANL@ && __GNUC__ >= 4
717 # define gl_isnan_l(x) __builtin_isnanl ((long double)(x))
719 _GL_EXTERN_C int rpl_isnanl (long double x);
720 # define gl_isnan_l(x) rpl_isnanl (x)
724 (sizeof (x) == sizeof (long double) ? gl_isnan_l (x) : \
725 sizeof (x) == sizeof (double) ? gl_isnan_d (x) : \
730 (sizeof (x) == sizeof (long double) ? __builtin_isnanl ((long double)(x)) : \
731 sizeof (x) == sizeof (double) ? __builtin_isnan ((double)(x)) : \
732 __builtin_isnanf ((float)(x)))
734 /* Ensure isnan is a macro. */
738 #elif defined GNULIB_POSIXCHECK
740 _GL_WARN_REAL_FLOATING_DECL (isnan);
742 # define isnan(x) _GL_WARN_REAL_FLOATING_IMPL (isnan, x)
748 # if @REPLACE_SIGNBIT_USING_GCC@
750 /* GCC 4.0 and newer provides three built-ins for signbit. */
751 # define signbit(x) \
752 (sizeof (x) == sizeof (long double) ? __builtin_signbitl (x) : \
753 sizeof (x) == sizeof (double) ? __builtin_signbit (x) : \
754 __builtin_signbitf (x))
756 # if @REPLACE_SIGNBIT@
758 _GL_EXTERN_C int gl_signbitf (float arg);
759 _GL_EXTERN_C int gl_signbitd (double arg);
760 _GL_EXTERN_C int gl_signbitl (long double arg);
761 # if __GNUC__ >= 2 && !__STRICT_ANSI__
762 # define _GL_NUM_UINT_WORDS(type) \
763 ((sizeof (type) + sizeof (unsigned int) - 1) / sizeof (unsigned int))
764 # if defined FLT_SIGNBIT_WORD && defined FLT_SIGNBIT_BIT && !defined gl_signbitf
765 # define gl_signbitf_OPTIMIZED_MACRO
766 # define gl_signbitf(arg) \
767 ({ union { float _value; \
768 unsigned int _word[_GL_NUM_UINT_WORDS (float)]; \
771 (_m._word[FLT_SIGNBIT_WORD] >> FLT_SIGNBIT_BIT) & 1; \
774 # if defined DBL_SIGNBIT_WORD && defined DBL_SIGNBIT_BIT && !defined gl_signbitd
775 # define gl_signbitd_OPTIMIZED_MACRO
776 # define gl_signbitd(arg) \
777 ({ union { double _value; \
778 unsigned int _word[_GL_NUM_UINT_WORDS (double)]; \
781 (_m._word[DBL_SIGNBIT_WORD] >> DBL_SIGNBIT_BIT) & 1; \
784 # if defined LDBL_SIGNBIT_WORD && defined LDBL_SIGNBIT_BIT && !defined gl_signbitl
785 # define gl_signbitl_OPTIMIZED_MACRO
786 # define gl_signbitl(arg) \
787 ({ union { long double _value; \
788 unsigned int _word[_GL_NUM_UINT_WORDS (long double)]; \
791 (_m._word[LDBL_SIGNBIT_WORD] >> LDBL_SIGNBIT_BIT) & 1; \
795 # define signbit(x) \
796 (sizeof (x) == sizeof (long double) ? gl_signbitl (x) : \
797 sizeof (x) == sizeof (double) ? gl_signbitd (x) : \
800 #elif defined GNULIB_POSIXCHECK
802 _GL_WARN_REAL_FLOATING_DECL (signbit);
804 # define signbit(x) _GL_WARN_REAL_FLOATING_IMPL (signbit, x)
809 #endif /* _GL_MATH_H */
810 #endif /* _GL_MATH_H */