Avoid gcc warnings because of #pragma GCC system_header on older gcc.
[gnulib.git] / lib / math.in.h
1 /* A GNU-like <math.h>.
2
3    Copyright (C) 2002-2003, 2007-2008 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@ @NEXT_MATH_H@
26
27 #ifndef _GL_MATH_H
28 #define _GL_MATH_H
29
30
31 /* The definition of GL_LINK_WARNING is copied here.  */
32
33
34 #ifdef __cplusplus
35 extern "C" {
36 #endif
37
38
39 /* POSIX allows platforms that don't support NAN.  But all major
40    machines in the past 15 years have supported something close to
41    IEEE NaN, so we define this unconditionally.  We also must define
42    it on platforms like Solaris 10, where NAN is present but defined
43    as a function pointer rather than a floating point constant.  */
44 #if !defined NAN || @REPLACE_NAN@
45 # undef NAN
46   /* The Compaq (ex-DEC) C 6.4 compiler chokes on the expression 0.0 / 0.0.  */
47 # ifdef __DECC
48 static float
49 _NaN ()
50 {
51   static float zero = 0.0f;
52   return zero / zero;
53 }
54 #  define NAN (_NaN())
55 # else
56 #  define NAN (0.0f / 0.0f)
57 # endif
58 #endif
59
60 /* Solaris 10 defines HUGE_VAL, but as a function pointer rather
61    than a floating point constant.  */
62 #if @REPLACE_HUGE_VAL@
63 # undef HUGE_VAL
64 # define HUGE_VAL (1.0 / 0.0)
65 #endif
66
67 /* Write x as
68      x = mantissa * 2^exp
69    where
70      If x finite and nonzero: 0.5 <= |mantissa| < 1.0.
71      If x is zero: mantissa = x, exp = 0.
72      If x is infinite or NaN: mantissa = x, exp unspecified.
73    Store exp in *EXPPTR and return mantissa.  */
74 #if @GNULIB_FREXP@
75 # if @REPLACE_FREXP@
76 #  define frexp rpl_frexp
77 extern double frexp (double x, int *expptr);
78 # endif
79 #elif defined GNULIB_POSIXCHECK
80 # undef frexp
81 # define frexp(x,e) \
82     (GL_LINK_WARNING ("frexp is unportable - " \
83                       "use gnulib module frexp for portability"), \
84      frexp (x, e))
85 #endif
86
87
88 #if @GNULIB_MATHL@ || !@HAVE_DECL_ACOSL@
89 extern long double acosl (long double x);
90 #endif
91 #if !@GNULIB_MATHL@ && defined GNULIB_POSIXCHECK
92 # undef acosl
93 # define acosl(x) \
94     (GL_LINK_WARNING ("acosl is unportable - " \
95                       "use gnulib module mathl for portability"), \
96      acosl (x))
97 #endif
98
99
100 #if @GNULIB_MATHL@ || !@HAVE_DECL_ASINL@
101 extern long double asinl (long double x);
102 #endif
103 #if !@GNULIB_MATHL@ && defined GNULIB_POSIXCHECK
104 # undef asinl
105 # define asinl(x) \
106     (GL_LINK_WARNING ("asinl is unportable - " \
107                       "use gnulib module mathl for portability"), \
108      asinl (x))
109 #endif
110
111
112 #if @GNULIB_MATHL@ || !@HAVE_DECL_ATANL@
113 extern long double atanl (long double x);
114 #endif
115 #if !@GNULIB_MATHL@ && defined GNULIB_POSIXCHECK
116 # undef atanl
117 # define atanl(x) \
118     (GL_LINK_WARNING ("atanl is unportable - " \
119                       "use gnulib module mathl for portability"), \
120      atanl (x))
121 #endif
122
123
124 #if @GNULIB_CEILF@
125 # if @REPLACE_CEILF@
126 #  define ceilf rpl_ceilf
127 extern float ceilf (float x);
128 # endif
129 #elif defined GNULIB_POSIXCHECK
130 # undef ceilf
131 # define ceilf(x) \
132     (GL_LINK_WARNING ("ceilf is unportable - " \
133                       "use gnulib module ceilf for portability"), \
134      ceilf (x))
135 #endif
136
137 #if @GNULIB_CEILL@
138 # if @REPLACE_CEILL@
139 #  define ceill rpl_ceill
140 extern long double ceill (long double x);
141 # endif
142 #elif defined GNULIB_POSIXCHECK
143 # undef ceill
144 # define ceill(x) \
145     (GL_LINK_WARNING ("ceill is unportable - " \
146                       "use gnulib module ceill for portability"), \
147      ceill (x))
148 #endif
149
150
151 #if @GNULIB_MATHL@ || !@HAVE_DECL_COSL@
152 extern long double cosl (long double x);
153 #endif
154 #if !@GNULIB_MATHL@ && defined GNULIB_POSIXCHECK
155 # undef cosl
156 # define cosl(x) \
157     (GL_LINK_WARNING ("cosl is unportable - " \
158                       "use gnulib module mathl for portability"), \
159      cosl (x))
160 #endif
161
162
163 #if @GNULIB_MATHL@ || !@HAVE_DECL_EXPL@
164 extern long double expl (long double x);
165 #endif
166 #if !@GNULIB_MATHL@ && defined GNULIB_POSIXCHECK
167 # undef expl
168 # define expl(x) \
169     (GL_LINK_WARNING ("expl is unportable - " \
170                       "use gnulib module mathl for portability"), \
171      expl (x))
172 #endif
173
174
175 #if @GNULIB_FLOORF@
176 # if @REPLACE_FLOORF@
177 #  define floorf rpl_floorf
178 extern float floorf (float x);
179 # endif
180 #elif defined GNULIB_POSIXCHECK
181 # undef floorf
182 # define floorf(x) \
183     (GL_LINK_WARNING ("floorf is unportable - " \
184                       "use gnulib module floorf for portability"), \
185      floorf (x))
186 #endif
187
188 #if @GNULIB_FLOORL@
189 # if @REPLACE_FLOORL@
190 #  define floorl rpl_floorl
191 extern long double floorl (long double x);
192 # endif
193 #elif defined GNULIB_POSIXCHECK
194 # undef floorl
195 # define floorl(x) \
196     (GL_LINK_WARNING ("floorl is unportable - " \
197                       "use gnulib module floorl for portability"), \
198      floorl (x))
199 #endif
200
201
202 /* Write x as
203      x = mantissa * 2^exp
204    where
205      If x finite and nonzero: 0.5 <= |mantissa| < 1.0.
206      If x is zero: mantissa = x, exp = 0.
207      If x is infinite or NaN: mantissa = x, exp unspecified.
208    Store exp in *EXPPTR and return mantissa.  */
209 #if @GNULIB_FREXPL@ && @REPLACE_FREXPL@
210 # define frexpl rpl_frexpl
211 #endif
212 #if (@GNULIB_FREXPL@ && @REPLACE_FREXPL@) || !@HAVE_DECL_FREXPL@
213 extern long double frexpl (long double x, int *expptr);
214 #endif
215 #if !@GNULIB_FREXPL@ && defined GNULIB_POSIXCHECK
216 # undef frexpl
217 # define frexpl(x,e) \
218     (GL_LINK_WARNING ("frexpl is unportable - " \
219                       "use gnulib module frexpl for portability"), \
220      frexpl (x, e))
221 #endif
222
223
224 /* Return x * 2^exp.  */
225 #if @GNULIB_LDEXPL@ && @REPLACE_LDEXPL@
226 # define ldexpl rpl_ldexpl
227 #endif
228 #if (@GNULIB_LDEXPL@ && @REPLACE_LDEXPL@) || !@HAVE_DECL_LDEXPL@
229 extern long double ldexpl (long double x, int exp);
230 #endif
231 #if !@GNULIB_LDEXPL@ && defined GNULIB_POSIXCHECK
232 # undef ldexpl
233 # define ldexpl(x,e) \
234     (GL_LINK_WARNING ("ldexpl is unportable - " \
235                       "use gnulib module ldexpl for portability"), \
236      ldexpl (x, e))
237 #endif
238
239
240 #if @GNULIB_MATHL@ || !@HAVE_DECL_LOGL@
241 extern long double logl (long double x);
242 #endif
243 #if !@GNULIB_MATHL@ && defined GNULIB_POSIXCHECK
244 # undef logl
245 # define logl(x) \
246     (GL_LINK_WARNING ("logl is unportable - " \
247                       "use gnulib module mathl for portability"), \
248      logl (x))
249 #endif
250
251
252 #if @GNULIB_ROUNDF@
253 # if @REPLACE_ROUNDF@
254 #  undef roundf
255 #  define roundf rpl_roundf
256 extern float roundf (float x);
257 # endif
258 #elif defined GNULIB_POSIXCHECK
259 # undef roundf
260 # define roundf(x) \
261     (GL_LINK_WARNING ("roundf is unportable - " \
262                       "use gnulib module roundf for portability"), \
263      roundf (x))
264 #endif
265
266 #if @GNULIB_ROUND@
267 # if @REPLACE_ROUND@
268 #  undef round
269 #  define round rpl_round
270 extern double round (double x);
271 # endif
272 #elif defined GNULIB_POSIXCHECK
273 # undef round
274 # define round(x) \
275     (GL_LINK_WARNING ("round is unportable - " \
276                       "use gnulib module round for portability"), \
277      round (x))
278 #endif
279
280 #if @GNULIB_ROUNDL@
281 # if @REPLACE_ROUNDL@
282 #  undef roundl
283 #  define roundl rpl_roundl
284 extern long double roundl (long double x);
285 # endif
286 #elif defined GNULIB_POSIXCHECK
287 # undef roundl
288 # define roundl(x) \
289     (GL_LINK_WARNING ("roundl is unportable - " \
290                       "use gnulib module roundl for portability"), \
291      roundl (x))
292 #endif
293
294
295 #if @GNULIB_MATHL@ || !@HAVE_DECL_SINL@
296 extern long double sinl (long double x);
297 #endif
298 #if !@GNULIB_MATHL@ && defined GNULIB_POSIXCHECK
299 # undef sinl
300 # define sinl(x) \
301     (GL_LINK_WARNING ("sinl is unportable - " \
302                       "use gnulib module mathl for portability"), \
303      sinl (x))
304 #endif
305
306
307 #if @GNULIB_MATHL@ || !@HAVE_DECL_SQRTL@
308 extern long double sqrtl (long double x);
309 #endif
310 #if !@GNULIB_MATHL@ && defined GNULIB_POSIXCHECK
311 # undef sqrtl
312 # define sqrtl(x) \
313     (GL_LINK_WARNING ("sqrtl is unportable - " \
314                       "use gnulib module mathl for portability"), \
315      sqrtl (x))
316 #endif
317
318
319 #if @GNULIB_MATHL@ || !@HAVE_DECL_TANL@
320 extern long double tanl (long double x);
321 #endif
322 #if !@GNULIB_MATHL@ && defined GNULIB_POSIXCHECK
323 # undef tanl
324 # define tanl(x) \
325     (GL_LINK_WARNING ("tanl is unportable - " \
326                       "use gnulib module mathl for portability"), \
327      tanl (x))
328 #endif
329
330
331 #if @GNULIB_TRUNCF@
332 # if !@HAVE_DECL_TRUNCF@
333 #  define truncf rpl_truncf
334 extern float truncf (float x);
335 # endif
336 #elif defined GNULIB_POSIXCHECK
337 # undef truncf
338 # define truncf(x) \
339     (GL_LINK_WARNING ("truncf is unportable - " \
340                       "use gnulib module truncf for portability"), \
341      truncf (x))
342 #endif
343
344 #if @GNULIB_TRUNC@
345 # if !@HAVE_DECL_TRUNC@
346 #  define trunc rpl_trunc
347 extern double trunc (double x);
348 # endif
349 #elif defined GNULIB_POSIXCHECK
350 # undef trunc
351 # define trunc(x) \
352     (GL_LINK_WARNING ("trunc is unportable - " \
353                       "use gnulib module trunc for portability"), \
354      trunc (x))
355 #endif
356
357 #if @GNULIB_TRUNCL@
358 # if @REPLACE_TRUNCL@
359 #  undef truncl
360 #  define truncl rpl_truncl
361 extern long double truncl (long double x);
362 # endif
363 #elif defined GNULIB_POSIXCHECK
364 # undef truncl
365 # define truncl(x) \
366     (GL_LINK_WARNING ("truncl is unportable - " \
367                       "use gnulib module truncl for portability"), \
368      truncl (x))
369 #endif
370
371
372 #if @GNULIB_ISFINITE@
373 # if @REPLACE_ISFINITE@
374 extern int gl_isfinitef (float x);
375 extern int gl_isfinited (double x);
376 extern int gl_isfinitel (long double x);
377 #  undef isfinite
378 #  define isfinite(x) \
379    (sizeof (x) == sizeof (long double) ? gl_isfinitel (x) : \
380     sizeof (x) == sizeof (double) ? gl_isfinited (x) : \
381     gl_isfinitef (x))
382 # endif
383 #elif defined GNULIB_POSIXCHECK
384   /* How to override a macro?  */
385 #endif
386
387
388 #if @GNULIB_ISINF@
389 # if @REPLACE_ISINF@
390 extern int gl_isinff (float x);
391 extern int gl_isinfd (double x);
392 extern int gl_isinfl (long double x);
393 #  undef isinf
394 #  define isinf(x) \
395    (sizeof (x) == sizeof (long double) ? gl_isinfl (x) : \
396     sizeof (x) == sizeof (double) ? gl_isinfd (x) : \
397     gl_isinff (x))
398 # endif
399 #elif defined GNULIB_POSIXCHECK
400   /* How to override a macro?  */
401 #endif
402
403
404 #if @GNULIB_ISNAN@
405 # if @REPLACE_ISNAN@
406 /* We can't just use the isnanf macro (e.g.) as exposed by
407    isnanf.h (e.g.) here, because those may end up being macros
408    that recursively expand back to isnan.  So use the gnulib
409    replacements for them directly. */
410 #  if HAVE_ISNANF && __GNUC__ >= 4
411 #   define gl_isnan_f(x) __builtin_isnan ((float)(x))
412 #  else
413 extern int rpl_isnanf (float x);
414 #   define gl_isnan_f(x) rpl_isnanf (x)
415 #  endif
416 #  if HAVE_ISNAND && __GNUC__ >= 4
417 #   define gl_isnan_d(x) __builtin_isnan ((double)(x))
418 #  else
419 extern int rpl_isnand (double x);
420 #   define gl_isnan_d(x) rpl_isnand (x)
421 #  endif
422 #  if HAVE_ISNANL && __GNUC__ >= 4
423 #   define gl_isnan_l(x) __builtin_isnan ((long double)(x))
424 #  else
425 extern int rpl_isnanl (long double x);
426 #   define gl_isnan_l(x) rpl_isnanl (x)
427 #  endif
428 #  undef isnan
429 #  define isnan(x) \
430    (sizeof (x) == sizeof (long double) ? gl_isnan_l (x) : \
431     sizeof (x) == sizeof (double) ? gl_isnan_d (x) : \
432     gl_isnan_f (x))
433 # endif
434 #elif defined GNULIB_POSIXCHECK
435   /* How to override a macro?  */
436 #endif
437
438
439 #if @GNULIB_SIGNBIT@
440 # if @REPLACE_SIGNBIT_USING_GCC@
441 #  undef signbit
442    /* GCC 4.0 and newer provides three built-ins for signbit.  */
443 #  define signbit(x) \
444    (sizeof (x) == sizeof (long double) ? __builtin_signbitl (x) : \
445     sizeof (x) == sizeof (double) ? __builtin_signbit (x) : \
446     __builtin_signbitf (x))
447 # endif
448 # if @REPLACE_SIGNBIT@
449 #  undef signbit
450 extern int gl_signbitf (float arg);
451 extern int gl_signbitd (double arg);
452 extern int gl_signbitl (long double arg);
453 #  if __GNUC__ >= 2 && !__STRICT_ANSI__
454 #   if defined FLT_SIGNBIT_WORD && defined FLT_SIGNBIT_BIT
455 #    define gl_signbitf(arg) \
456        ({ union { float _value;                                         \
457                   unsigned int _word[(sizeof (float) + sizeof (unsigned int) - 1) / sizeof (unsigned int)]; \
458                 } _m;                                                   \
459           _m._value = (arg);                                            \
460           (_m._word[FLT_SIGNBIT_WORD] >> FLT_SIGNBIT_BIT) & 1;          \
461         })
462 #   endif
463 #   if defined DBL_SIGNBIT_WORD && defined DBL_SIGNBIT_BIT
464 #    define gl_signbitd(arg) \
465        ({ union { double _value;                                                \
466                   unsigned int _word[(sizeof (double) + sizeof (unsigned int) - 1) / sizeof (unsigned int)]; \
467                 } _m;                                                   \
468           _m._value = (arg);                                            \
469           (_m._word[DBL_SIGNBIT_WORD] >> DBL_SIGNBIT_BIT) & 1;          \
470         })
471 #   endif
472 #   if defined LDBL_SIGNBIT_WORD && defined LDBL_SIGNBIT_BIT
473 #    define gl_signbitl(arg) \
474        ({ union { long double _value;                                   \
475                   unsigned int _word[(sizeof (long double) + sizeof (unsigned int) - 1) / sizeof (unsigned int)]; \
476                 } _m;                                                   \
477           _m._value = (arg);                                            \
478           (_m._word[LDBL_SIGNBIT_WORD] >> LDBL_SIGNBIT_BIT) & 1;                \
479         })
480 #   endif
481 #  endif
482 #  define signbit(x) \
483    (sizeof (x) == sizeof (long double) ? gl_signbitl (x) : \
484     sizeof (x) == sizeof (double) ? gl_signbitd (x) : \
485     gl_signbitf (x))
486 # endif
487 #elif defined GNULIB_POSIXCHECK
488   /* How to override a macro?  */
489 #endif
490
491
492 #ifdef __cplusplus
493 }
494 #endif
495
496 #endif /* _GL_MATH_H */
497 #endif /* _GL_MATH_H */