Imported Upstream version 1.3.14
[debian/gzip] / lib / math.in.h
1 /* A GNU-like <math.h>.
2
3    Copyright (C) 2002-2003, 2007-2009 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 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@ && !defined cosl)
152 # undef cosl
153 extern long double cosl (long double x);
154 #endif
155 #if !@GNULIB_MATHL@ && defined GNULIB_POSIXCHECK
156 # undef cosl
157 # define cosl(x) \
158     (GL_LINK_WARNING ("cosl is unportable - " \
159                       "use gnulib module mathl for portability"), \
160      cosl (x))
161 #endif
162
163
164 #if @GNULIB_MATHL@ || !@HAVE_DECL_EXPL@
165 extern long double expl (long double x);
166 #endif
167 #if !@GNULIB_MATHL@ && defined GNULIB_POSIXCHECK
168 # undef expl
169 # define expl(x) \
170     (GL_LINK_WARNING ("expl is unportable - " \
171                       "use gnulib module mathl for portability"), \
172      expl (x))
173 #endif
174
175
176 #if @GNULIB_FLOORF@
177 # if @REPLACE_FLOORF@
178 #  define floorf rpl_floorf
179 extern float floorf (float x);
180 # endif
181 #elif defined GNULIB_POSIXCHECK
182 # undef floorf
183 # define floorf(x) \
184     (GL_LINK_WARNING ("floorf is unportable - " \
185                       "use gnulib module floorf for portability"), \
186      floorf (x))
187 #endif
188
189 #if @GNULIB_FLOORL@
190 # if @REPLACE_FLOORL@
191 #  define floorl rpl_floorl
192 extern long double floorl (long double x);
193 # endif
194 #elif defined GNULIB_POSIXCHECK
195 # undef floorl
196 # define floorl(x) \
197     (GL_LINK_WARNING ("floorl is unportable - " \
198                       "use gnulib module floorl for portability"), \
199      floorl (x))
200 #endif
201
202
203 /* Write x as
204      x = mantissa * 2^exp
205    where
206      If x finite and nonzero: 0.5 <= |mantissa| < 1.0.
207      If x is zero: mantissa = x, exp = 0.
208      If x is infinite or NaN: mantissa = x, exp unspecified.
209    Store exp in *EXPPTR and return mantissa.  */
210 #if @GNULIB_FREXPL@ && @REPLACE_FREXPL@
211 # define frexpl rpl_frexpl
212 #endif
213 #if (@GNULIB_FREXPL@ && @REPLACE_FREXPL@) || !@HAVE_DECL_FREXPL@
214 extern long double frexpl (long double x, int *expptr);
215 #endif
216 #if !@GNULIB_FREXPL@ && defined GNULIB_POSIXCHECK
217 # undef frexpl
218 # define frexpl(x,e) \
219     (GL_LINK_WARNING ("frexpl is unportable - " \
220                       "use gnulib module frexpl for portability"), \
221      frexpl (x, e))
222 #endif
223
224
225 /* Return x * 2^exp.  */
226 #if @GNULIB_LDEXPL@ && @REPLACE_LDEXPL@
227 # define ldexpl rpl_ldexpl
228 #endif
229 #if (@GNULIB_LDEXPL@ && @REPLACE_LDEXPL@) || !@HAVE_DECL_LDEXPL@
230 extern long double ldexpl (long double x, int exp);
231 #endif
232 #if !@GNULIB_LDEXPL@ && defined GNULIB_POSIXCHECK
233 # undef ldexpl
234 # define ldexpl(x,e) \
235     (GL_LINK_WARNING ("ldexpl is unportable - " \
236                       "use gnulib module ldexpl for portability"), \
237      ldexpl (x, e))
238 #endif
239
240
241 #if @GNULIB_MATHL@ || (!@HAVE_DECL_LOGL@ && !defined logl)
242 # undef logl
243 extern long double logl (long double x);
244 #endif
245 #if !@GNULIB_MATHL@ && defined GNULIB_POSIXCHECK
246 # undef logl
247 # define logl(x) \
248     (GL_LINK_WARNING ("logl is unportable - " \
249                       "use gnulib module mathl for portability"), \
250      logl (x))
251 #endif
252
253
254 #if @GNULIB_ROUNDF@
255 # if @REPLACE_ROUNDF@
256 #  undef roundf
257 #  define roundf rpl_roundf
258 extern float roundf (float x);
259 # endif
260 #elif defined GNULIB_POSIXCHECK
261 # undef roundf
262 # define roundf(x) \
263     (GL_LINK_WARNING ("roundf is unportable - " \
264                       "use gnulib module roundf for portability"), \
265      roundf (x))
266 #endif
267
268 #if @GNULIB_ROUND@
269 # if @REPLACE_ROUND@
270 #  undef round
271 #  define round rpl_round
272 extern double round (double x);
273 # endif
274 #elif defined GNULIB_POSIXCHECK
275 # undef round
276 # define round(x) \
277     (GL_LINK_WARNING ("round is unportable - " \
278                       "use gnulib module round for portability"), \
279      round (x))
280 #endif
281
282 #if @GNULIB_ROUNDL@
283 # if @REPLACE_ROUNDL@
284 #  undef roundl
285 #  define roundl rpl_roundl
286 extern long double roundl (long double x);
287 # endif
288 #elif defined GNULIB_POSIXCHECK
289 # undef roundl
290 # define roundl(x) \
291     (GL_LINK_WARNING ("roundl is unportable - " \
292                       "use gnulib module roundl for portability"), \
293      roundl (x))
294 #endif
295
296
297 #if @GNULIB_MATHL@ || (!@HAVE_DECL_SINL@ && !defined sinl)
298 # undef sinl
299 extern long double sinl (long double x);
300 #endif
301 #if !@GNULIB_MATHL@ && defined GNULIB_POSIXCHECK
302 # undef sinl
303 # define sinl(x) \
304     (GL_LINK_WARNING ("sinl is unportable - " \
305                       "use gnulib module mathl for portability"), \
306      sinl (x))
307 #endif
308
309
310 #if @GNULIB_MATHL@ || !@HAVE_DECL_SQRTL@
311 extern long double sqrtl (long double x);
312 #endif
313 #if !@GNULIB_MATHL@ && defined GNULIB_POSIXCHECK
314 # undef sqrtl
315 # define sqrtl(x) \
316     (GL_LINK_WARNING ("sqrtl is unportable - " \
317                       "use gnulib module mathl for portability"), \
318      sqrtl (x))
319 #endif
320
321
322 #if @GNULIB_MATHL@ || !@HAVE_DECL_TANL@
323 extern long double tanl (long double x);
324 #endif
325 #if !@GNULIB_MATHL@ && defined GNULIB_POSIXCHECK
326 # undef tanl
327 # define tanl(x) \
328     (GL_LINK_WARNING ("tanl is unportable - " \
329                       "use gnulib module mathl for portability"), \
330      tanl (x))
331 #endif
332
333
334 #if @GNULIB_TRUNCF@
335 # if !@HAVE_DECL_TRUNCF@
336 #  define truncf rpl_truncf
337 extern float truncf (float x);
338 # endif
339 #elif defined GNULIB_POSIXCHECK
340 # undef truncf
341 # define truncf(x) \
342     (GL_LINK_WARNING ("truncf is unportable - " \
343                       "use gnulib module truncf for portability"), \
344      truncf (x))
345 #endif
346
347 #if @GNULIB_TRUNC@
348 # if !@HAVE_DECL_TRUNC@
349 #  define trunc rpl_trunc
350 extern double trunc (double x);
351 # endif
352 #elif defined GNULIB_POSIXCHECK
353 # undef trunc
354 # define trunc(x) \
355     (GL_LINK_WARNING ("trunc is unportable - " \
356                       "use gnulib module trunc for portability"), \
357      trunc (x))
358 #endif
359
360 #if @GNULIB_TRUNCL@
361 # if @REPLACE_TRUNCL@
362 #  undef truncl
363 #  define truncl rpl_truncl
364 extern long double truncl (long double x);
365 # endif
366 #elif defined GNULIB_POSIXCHECK
367 # undef truncl
368 # define truncl(x) \
369     (GL_LINK_WARNING ("truncl is unportable - " \
370                       "use gnulib module truncl for portability"), \
371      truncl (x))
372 #endif
373
374
375 #if @GNULIB_ISFINITE@
376 # if @REPLACE_ISFINITE@
377 extern int gl_isfinitef (float x);
378 extern int gl_isfinited (double x);
379 extern int gl_isfinitel (long double x);
380 #  undef isfinite
381 #  define isfinite(x) \
382    (sizeof (x) == sizeof (long double) ? gl_isfinitel (x) : \
383     sizeof (x) == sizeof (double) ? gl_isfinited (x) : \
384     gl_isfinitef (x))
385 # endif
386 #elif defined GNULIB_POSIXCHECK
387   /* How to override a macro?  */
388 #endif
389
390
391 #if @GNULIB_ISINF@
392 # if @REPLACE_ISINF@
393 extern int gl_isinff (float x);
394 extern int gl_isinfd (double x);
395 extern int gl_isinfl (long double x);
396 #  undef isinf
397 #  define isinf(x) \
398    (sizeof (x) == sizeof (long double) ? gl_isinfl (x) : \
399     sizeof (x) == sizeof (double) ? gl_isinfd (x) : \
400     gl_isinff (x))
401 # endif
402 #elif defined GNULIB_POSIXCHECK
403   /* How to override a macro?  */
404 #endif
405
406
407 #if @GNULIB_ISNANF@
408 /* Test for NaN for 'float' numbers.  */
409 # if @HAVE_ISNANF@
410 /* The original <math.h> included above provides a declaration of isnan macro
411    or (older) isnanf function.  */
412 #  include <math.h>
413 #  if __GNUC__ >= 4
414     /* GCC 4.0 and newer provides three built-ins for isnan.  */
415 #   undef isnanf
416 #   define isnanf(x) __builtin_isnanf ((float)(x))
417 #  elif defined isnan
418 #   undef isnanf
419 #   define isnanf(x) isnan ((float)(x))
420 #  endif
421 # else
422 /* Test whether X is a NaN.  */
423 #  undef isnanf
424 #  define isnanf rpl_isnanf
425 extern int isnanf (float x);
426 # endif
427 #endif
428
429 #if @GNULIB_ISNAND@
430 /* Test for NaN for 'double' numbers.
431    This function is a gnulib extension, unlike isnan() which applied only
432    to 'double' numbers earlier but now is a type-generic macro.  */
433 # if @HAVE_ISNAND@
434 /* The original <math.h> included above provides a declaration of isnan macro.  */
435 #  include <math.h>
436 #  if __GNUC__ >= 4
437     /* GCC 4.0 and newer provides three built-ins for isnan.  */
438 #   undef isnand
439 #   define isnand(x) __builtin_isnan ((double)(x))
440 #  else
441 #   undef isnand
442 #   define isnand(x) isnan ((double)(x))
443 #  endif
444 # else
445 /* Test whether X is a NaN.  */
446 #  undef isnand
447 #  define isnand rpl_isnand
448 extern int isnand (double x);
449 # endif
450 #endif
451
452 #if @GNULIB_ISNANL@
453 /* Test for NaN for 'long double' numbers.  */
454 # if @HAVE_ISNANL@
455 /* The original <math.h> included above provides a declaration of isnan macro or (older) isnanl function.  */
456 #  include <math.h>
457 #  if __GNUC__ >= 4
458     /* GCC 4.0 and newer provides three built-ins for isnan.  */
459 #   undef isnanl
460 #   define isnanl(x) __builtin_isnanl ((long double)(x))
461 #  elif defined isnan
462 #   undef isnanl
463 #   define isnanl(x) isnan ((long double)(x))
464 #  endif
465 # else
466 /* Test whether X is a NaN.  */
467 #  undef isnanl
468 #  define isnanl rpl_isnanl
469 extern int isnanl (long double x);
470 # endif
471 #endif
472
473 /* This must come *after* the snippets for GNULIB_ISNANF and GNULIB_ISNANL!  */
474 #if @GNULIB_ISNAN@
475 # if @REPLACE_ISNAN@
476 /* We can't just use the isnanf macro (e.g.) as exposed by
477    isnanf.h (e.g.) here, because those may end up being macros
478    that recursively expand back to isnan.  So use the gnulib
479    replacements for them directly. */
480 #  if @HAVE_ISNANF@ && __GNUC__ >= 4
481 #   define gl_isnan_f(x) __builtin_isnan ((float)(x))
482 #  else
483 extern int rpl_isnanf (float x);
484 #   define gl_isnan_f(x) rpl_isnanf (x)
485 #  endif
486 #  if @HAVE_ISNAND@ && __GNUC__ >= 4
487 #   define gl_isnan_d(x) __builtin_isnan ((double)(x))
488 #  else
489 extern int rpl_isnand (double x);
490 #   define gl_isnan_d(x) rpl_isnand (x)
491 #  endif
492 #  if @HAVE_ISNANL@ && __GNUC__ >= 4
493 #   define gl_isnan_l(x) __builtin_isnan ((long double)(x))
494 #  else
495 extern int rpl_isnanl (long double x);
496 #   define gl_isnan_l(x) rpl_isnanl (x)
497 #  endif
498 #  undef isnan
499 #  define isnan(x) \
500    (sizeof (x) == sizeof (long double) ? gl_isnan_l (x) : \
501     sizeof (x) == sizeof (double) ? gl_isnan_d (x) : \
502     gl_isnan_f (x))
503 # endif
504 #elif defined GNULIB_POSIXCHECK
505   /* How to override a macro?  */
506 #endif
507
508
509 #if @GNULIB_SIGNBIT@
510 # if @REPLACE_SIGNBIT_USING_GCC@
511 #  undef signbit
512    /* GCC 4.0 and newer provides three built-ins for signbit.  */
513 #  define signbit(x) \
514    (sizeof (x) == sizeof (long double) ? __builtin_signbitl (x) : \
515     sizeof (x) == sizeof (double) ? __builtin_signbit (x) : \
516     __builtin_signbitf (x))
517 # endif
518 # if @REPLACE_SIGNBIT@
519 #  undef signbit
520 extern int gl_signbitf (float arg);
521 extern int gl_signbitd (double arg);
522 extern int gl_signbitl (long double arg);
523 #  if __GNUC__ >= 2 && !__STRICT_ANSI__
524 #   if defined FLT_SIGNBIT_WORD && defined FLT_SIGNBIT_BIT && !defined gl_signbitf
525 #    define gl_signbitf_OPTIMIZED_MACRO
526 #    define gl_signbitf(arg) \
527        ({ union { float _value;                                         \
528                   unsigned int _word[(sizeof (float) + sizeof (unsigned int) - 1) / sizeof (unsigned int)]; \
529                 } _m;                                                   \
530           _m._value = (arg);                                            \
531           (_m._word[FLT_SIGNBIT_WORD] >> FLT_SIGNBIT_BIT) & 1;          \
532         })
533 #   endif
534 #   if defined DBL_SIGNBIT_WORD && defined DBL_SIGNBIT_BIT && !defined gl_signbitd
535 #    define gl_signbitd_OPTIMIZED_MACRO
536 #    define gl_signbitd(arg) \
537        ({ union { double _value;                                                \
538                   unsigned int _word[(sizeof (double) + sizeof (unsigned int) - 1) / sizeof (unsigned int)]; \
539                 } _m;                                                   \
540           _m._value = (arg);                                            \
541           (_m._word[DBL_SIGNBIT_WORD] >> DBL_SIGNBIT_BIT) & 1;          \
542         })
543 #   endif
544 #   if defined LDBL_SIGNBIT_WORD && defined LDBL_SIGNBIT_BIT && !defined gl_signbitl
545 #    define gl_signbitl_OPTIMIZED_MACRO
546 #    define gl_signbitl(arg) \
547        ({ union { long double _value;                                   \
548                   unsigned int _word[(sizeof (long double) + sizeof (unsigned int) - 1) / sizeof (unsigned int)]; \
549                 } _m;                                                   \
550           _m._value = (arg);                                            \
551           (_m._word[LDBL_SIGNBIT_WORD] >> LDBL_SIGNBIT_BIT) & 1;                \
552         })
553 #   endif
554 #  endif
555 #  define signbit(x) \
556    (sizeof (x) == sizeof (long double) ? gl_signbitl (x) : \
557     sizeof (x) == sizeof (double) ? gl_signbitd (x) : \
558     gl_signbitf (x))
559 # endif
560 #elif defined GNULIB_POSIXCHECK
561   /* How to override a macro?  */
562 #endif
563
564
565 #ifdef __cplusplus
566 }
567 #endif
568
569 #endif /* _GL_MATH_H */
570 #endif /* _GL_MATH_H */