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