* lib/fcntl_.h: Prefer #include_next <foo.h> to #include
[gnulib.git] / lib / math_.h
1 /* A GNU-like <math.h>.
2
3    Copyright (C) 2002-2003, 2007 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 2, or (at your option)
8    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, write to the Free Software Foundation,
17    Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.  */
18
19 #if @HAVE_INCLUDE_NEXT@
20 # include_next <math.h>
21 #endif
22
23 #ifndef _GL_MATH_H
24 #define _GL_MATH_H
25
26 #if ! @HAVE_INCLUDE_NEXT@
27 # include @ABSOLUTE_MATH_H@
28 #endif
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 /* Write x as
40      x = mantissa * 2^exp
41    where
42      If x finite and nonzero: 0.5 <= |mantissa| < 1.0.
43      If x is zero: mantissa = x, exp = 0.
44      If x is infinite or NaN: mantissa = x, exp unspecified.
45    Store exp and return mantissa.  */
46 #if @GNULIB_FREXP@
47 # if @REPLACE_FREXP@
48 #  define frexp rpl_frexp
49 extern double frexp (double x, int *exp);
50 # endif
51 #elif defined GNULIB_POSIXCHECK
52 # undef frexp
53 # define frexp(x,e) \
54     (GL_LINK_WARNING ("frexp is unportable - " \
55                       "use gnulib module frexp for portability"), \
56      frexp (x, e))
57 #endif
58
59
60 #if @GNULIB_MATHL@ || !@HAVE_DECL_ACOSL@
61 extern long double acosl (long double x);
62 #endif
63 #if !@GNULIB_MATHL@ && defined GNULIB_POSIXCHECK
64 # undef acosl
65 # define acosl(x) \
66     (GL_LINK_WARNING ("acosl is unportable - " \
67                       "use gnulib module mathl for portability"), \
68      acosl (x))
69 #endif
70
71 #if @GNULIB_MATHL@ || !@HAVE_DECL_ASINL@
72 extern long double asinl (long double x);
73 #endif
74 #if !@GNULIB_MATHL@ && defined GNULIB_POSIXCHECK
75 # undef asinl
76 # define asinl(x) \
77     (GL_LINK_WARNING ("asinl is unportable - " \
78                       "use gnulib module mathl for portability"), \
79      asinl (x))
80 #endif
81
82 #if @GNULIB_MATHL@ || !@HAVE_DECL_ATANL@
83 extern long double atanl (long double x);
84 #endif
85 #if !@GNULIB_MATHL@ && defined GNULIB_POSIXCHECK
86 # undef atanl
87 # define atanl(x) \
88     (GL_LINK_WARNING ("atanl is unportable - " \
89                       "use gnulib module mathl for portability"), \
90      atanl (x))
91 #endif
92
93 #if @GNULIB_MATHL@ || !@HAVE_DECL_CEILL@
94 extern long double ceill (long double x);
95 #endif
96 #if !@GNULIB_MATHL@ && defined GNULIB_POSIXCHECK
97 # undef ceill
98 # define ceill(x) \
99     (GL_LINK_WARNING ("ceill is unportable - " \
100                       "use gnulib module mathl for portability"), \
101      ceill (x))
102 #endif
103
104 #if @GNULIB_MATHL@ || !@HAVE_DECL_COSL@
105 extern long double cosl (long double x);
106 #endif
107 #if !@GNULIB_MATHL@ && defined GNULIB_POSIXCHECK
108 # undef cosl
109 # define cosl(x) \
110     (GL_LINK_WARNING ("cosl is unportable - " \
111                       "use gnulib module mathl for portability"), \
112      cosl (x))
113 #endif
114
115 #if @GNULIB_MATHL@ || !@HAVE_DECL_EXPL@
116 extern long double expl (long double x);
117 #endif
118 #if !@GNULIB_MATHL@ && defined GNULIB_POSIXCHECK
119 # undef expl
120 # define expl(x) \
121     (GL_LINK_WARNING ("expl is unportable - " \
122                       "use gnulib module mathl for portability"), \
123      expl (x))
124 #endif
125
126 #if @GNULIB_MATHL@ || !@HAVE_DECL_FLOORL@
127 extern long double floorl (long double x);
128 #endif
129 #if !@GNULIB_MATHL@ && defined GNULIB_POSIXCHECK
130 # undef floorl
131 # define floorl(x) \
132     (GL_LINK_WARNING ("floorl is unportable - " \
133                       "use gnulib module mathl for portability"), \
134      floorl (x))
135 #endif
136
137 /* Write x as
138      x = mantissa * 2^exp
139    where
140      If x finite and nonzero: 0.5 <= |mantissa| < 1.0.
141      If x is zero: mantissa = x, exp = 0.
142      If x is infinite or NaN: mantissa = x, exp unspecified.
143    Store exp and return mantissa.  */
144 #if @GNULIB_FREXPL@ && @REPLACE_FREXPL@
145 # define frexpl rpl_frexpl
146 #endif
147 #if (@GNULIB_FREXPL@ && @REPLACE_FREXPL@) || !@HAVE_DECL_FREXPL@
148 extern long double frexpl (long double x, int *exp);
149 #endif
150 #if !@GNULIB_FREXPL@ && defined GNULIB_POSIXCHECK
151 # undef frexpl
152 # define frexpl(x,e) \
153     (GL_LINK_WARNING ("frexpl is unportable - " \
154                       "use gnulib module frexpl for portability"), \
155      frexpl (x, e))
156 #endif
157
158 /* Return x * 2^exp.  */
159 #if @GNULIB_LDEXPL@ && @REPLACE_LDEXPL@
160 # define ldexpl rpl_ldexpl
161 #endif
162 #if (@GNULIB_LDEXPL@ && @REPLACE_LDEXPL@) || !@HAVE_DECL_LDEXPL@
163 extern long double ldexpl (long double x, int exp);
164 #endif
165 #if !@GNULIB_LDEXPL@ && defined GNULIB_POSIXCHECK
166 # undef ldexpl
167 # define ldexpl(x,e) \
168     (GL_LINK_WARNING ("ldexpl is unportable - " \
169                       "use gnulib module ldexpl for portability"), \
170      ldexpl (x, e))
171 #endif
172
173 #if @GNULIB_MATHL@ || !@HAVE_DECL_LOGL@
174 extern long double logl (long double x);
175 #endif
176 #if !@GNULIB_MATHL@ && defined GNULIB_POSIXCHECK
177 # undef logl
178 # define logl(x) \
179     (GL_LINK_WARNING ("logl is unportable - " \
180                       "use gnulib module mathl for portability"), \
181      logl (x))
182 #endif
183
184 #if @GNULIB_MATHL@ || !@HAVE_DECL_SINL@
185 extern long double sinl (long double x);
186 #endif
187 #if !@GNULIB_MATHL@ && defined GNULIB_POSIXCHECK
188 # undef sinl
189 # define sinl(x) \
190     (GL_LINK_WARNING ("sinl is unportable - " \
191                       "use gnulib module mathl for portability"), \
192      sinl (x))
193 #endif
194
195 #if @GNULIB_MATHL@ || !@HAVE_DECL_SQRTL@
196 extern long double sqrtl (long double x);
197 #endif
198 #if !@GNULIB_MATHL@ && defined GNULIB_POSIXCHECK
199 # undef sqrtl
200 # define sqrtl(x) \
201     (GL_LINK_WARNING ("sqrtl is unportable - " \
202                       "use gnulib module mathl for portability"), \
203      sqrtl (x))
204 #endif
205
206 #if @GNULIB_MATHL@ || !@HAVE_DECL_TANL@
207 extern long double tanl (long double x);
208 #endif
209 #if !@GNULIB_MATHL@ && defined GNULIB_POSIXCHECK
210 # undef tanl
211 # define tanl(x) \
212     (GL_LINK_WARNING ("tanl is unportable - " \
213                       "use gnulib module mathl for portability"), \
214      tanl (x))
215 #endif
216
217
218 #if @GNULIB_SIGNBIT@
219 # if @REPLACE_SIGNBIT@
220 #  undef signbit
221 extern int gl_signbitf (float arg);
222 extern int gl_signbitd (double arg);
223 extern int gl_signbitl (long double arg);
224 #  if __GNUC__ >= 2 && !__STRICT_ANSI__
225 #   if defined FLT_SIGNBIT_WORD && defined FLT_SIGNBIT_BIT
226 #    define gl_signbitf(arg) \
227        ({ union { float _value;                                         \
228                   unsigned int _word[(sizeof (float) + sizeof (unsigned int) - 1) / sizeof (unsigned int)]; \
229                 } _m;                                                   \
230           _m._value = (arg);                                            \
231           (_m._word[FLT_SIGNBIT_WORD] >> FLT_SIGNBIT_BIT) & 1;          \
232         })
233 #   endif
234 #   if defined DBL_SIGNBIT_WORD && defined DBL_SIGNBIT_BIT
235 #    define gl_signbitd(arg) \
236        ({ union { double _value;                                                \
237                   unsigned int _word[(sizeof (double) + sizeof (unsigned int) - 1) / sizeof (unsigned int)]; \
238                 } _m;                                                   \
239           _m._value = (arg);                                            \
240           (_m._word[DBL_SIGNBIT_WORD] >> DBL_SIGNBIT_BIT) & 1;          \
241         })
242 #   endif
243 #   if defined LDBL_SIGNBIT_WORD && defined LDBL_SIGNBIT_BIT
244 #    define gl_signbitl(arg) \
245        ({ union { long double _value;                                   \
246                   unsigned int _word[(sizeof (long double) + sizeof (unsigned int) - 1) / sizeof (unsigned int)]; \
247                 } _m;                                                   \
248           _m._value = (arg);                                            \
249           (_m._word[LDBL_SIGNBIT_WORD] >> LDBL_SIGNBIT_BIT) & 1;                \
250         })
251 #   endif
252 #  endif
253 #  define signbit(x) \
254    (sizeof (x) == sizeof (long double) ? gl_signbitl (x) : \
255     sizeof (x) == sizeof (double) ? gl_signbitd (x) : \
256     gl_signbitf (x))
257 # endif
258 #elif defined GNULIB_POSIXCHECK
259   /* How to override a macro?  */
260 #endif
261
262
263 #ifdef __cplusplus
264 }
265 #endif
266
267 #endif