New module 'floorf'.
[gnulib.git] / lib / math.in.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 #ifndef _GL_MATH_H
20
21 /* The include_next requires a split double-inclusion guard.  */
22 #@INCLUDE_NEXT@ @NEXT_MATH_H@
23
24 #ifndef _GL_MATH_H
25 #define _GL_MATH_H
26
27
28 /* The definition of GL_LINK_WARNING is copied here.  */
29
30
31 #ifdef __cplusplus
32 extern "C" {
33 #endif
34
35
36 /* Write x as
37      x = mantissa * 2^exp
38    where
39      If x finite and nonzero: 0.5 <= |mantissa| < 1.0.
40      If x is zero: mantissa = x, exp = 0.
41      If x is infinite or NaN: mantissa = x, exp unspecified.
42    Store exp and return mantissa.  */
43 #if @GNULIB_FREXP@
44 # if @REPLACE_FREXP@
45 #  define frexp rpl_frexp
46 extern double frexp (double x, int *exp);
47 # endif
48 #elif defined GNULIB_POSIXCHECK
49 # undef frexp
50 # define frexp(x,e) \
51     (GL_LINK_WARNING ("frexp is unportable - " \
52                       "use gnulib module frexp for portability"), \
53      frexp (x, e))
54 #endif
55
56
57 #if @GNULIB_MATHL@ || !@HAVE_DECL_ACOSL@
58 extern long double acosl (long double x);
59 #endif
60 #if !@GNULIB_MATHL@ && defined GNULIB_POSIXCHECK
61 # undef acosl
62 # define acosl(x) \
63     (GL_LINK_WARNING ("acosl is unportable - " \
64                       "use gnulib module mathl for portability"), \
65      acosl (x))
66 #endif
67
68
69 #if @GNULIB_MATHL@ || !@HAVE_DECL_ASINL@
70 extern long double asinl (long double x);
71 #endif
72 #if !@GNULIB_MATHL@ && defined GNULIB_POSIXCHECK
73 # undef asinl
74 # define asinl(x) \
75     (GL_LINK_WARNING ("asinl is unportable - " \
76                       "use gnulib module mathl for portability"), \
77      asinl (x))
78 #endif
79
80
81 #if @GNULIB_MATHL@ || !@HAVE_DECL_ATANL@
82 extern long double atanl (long double x);
83 #endif
84 #if !@GNULIB_MATHL@ && defined GNULIB_POSIXCHECK
85 # undef atanl
86 # define atanl(x) \
87     (GL_LINK_WARNING ("atanl is unportable - " \
88                       "use gnulib module mathl for portability"), \
89      atanl (x))
90 #endif
91
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
105 #if @GNULIB_MATHL@ || !@HAVE_DECL_COSL@
106 extern long double cosl (long double x);
107 #endif
108 #if !@GNULIB_MATHL@ && defined GNULIB_POSIXCHECK
109 # undef cosl
110 # define cosl(x) \
111     (GL_LINK_WARNING ("cosl is unportable - " \
112                       "use gnulib module mathl for portability"), \
113      cosl (x))
114 #endif
115
116
117 #if @GNULIB_MATHL@ || !@HAVE_DECL_EXPL@
118 extern long double expl (long double x);
119 #endif
120 #if !@GNULIB_MATHL@ && defined GNULIB_POSIXCHECK
121 # undef expl
122 # define expl(x) \
123     (GL_LINK_WARNING ("expl is unportable - " \
124                       "use gnulib module mathl for portability"), \
125      expl (x))
126 #endif
127
128
129 #if @GNULIB_FLOORF@
130 # if !@HAVE_DECL_FLOORF@
131 #  define floorf rpl_floorf
132 extern float floorf (float x);
133 # endif
134 #elif defined GNULIB_POSIXCHECK
135 # undef floorf
136 # define floorf(x) \
137     (GL_LINK_WARNING ("floorf is unportable - " \
138                       "use gnulib module floorf for portability"), \
139      floorf (x))
140 #endif
141
142 #if @GNULIB_MATHL@ || !@HAVE_DECL_FLOORL@
143 extern long double floorl (long double x);
144 #endif
145 #if !@GNULIB_MATHL@ && defined GNULIB_POSIXCHECK
146 # undef floorl
147 # define floorl(x) \
148     (GL_LINK_WARNING ("floorl is unportable - " \
149                       "use gnulib module mathl for portability"), \
150      floorl (x))
151 #endif
152
153
154 /* Write x as
155      x = mantissa * 2^exp
156    where
157      If x finite and nonzero: 0.5 <= |mantissa| < 1.0.
158      If x is zero: mantissa = x, exp = 0.
159      If x is infinite or NaN: mantissa = x, exp unspecified.
160    Store exp and return mantissa.  */
161 #if @GNULIB_FREXPL@ && @REPLACE_FREXPL@
162 # define frexpl rpl_frexpl
163 #endif
164 #if (@GNULIB_FREXPL@ && @REPLACE_FREXPL@) || !@HAVE_DECL_FREXPL@
165 extern long double frexpl (long double x, int *exp);
166 #endif
167 #if !@GNULIB_FREXPL@ && defined GNULIB_POSIXCHECK
168 # undef frexpl
169 # define frexpl(x,e) \
170     (GL_LINK_WARNING ("frexpl is unportable - " \
171                       "use gnulib module frexpl for portability"), \
172      frexpl (x, e))
173 #endif
174
175
176 /* Return x * 2^exp.  */
177 #if @GNULIB_LDEXPL@ && @REPLACE_LDEXPL@
178 # define ldexpl rpl_ldexpl
179 #endif
180 #if (@GNULIB_LDEXPL@ && @REPLACE_LDEXPL@) || !@HAVE_DECL_LDEXPL@
181 extern long double ldexpl (long double x, int exp);
182 #endif
183 #if !@GNULIB_LDEXPL@ && defined GNULIB_POSIXCHECK
184 # undef ldexpl
185 # define ldexpl(x,e) \
186     (GL_LINK_WARNING ("ldexpl is unportable - " \
187                       "use gnulib module ldexpl for portability"), \
188      ldexpl (x, e))
189 #endif
190
191
192 #if @GNULIB_MATHL@ || !@HAVE_DECL_LOGL@
193 extern long double logl (long double x);
194 #endif
195 #if !@GNULIB_MATHL@ && defined GNULIB_POSIXCHECK
196 # undef logl
197 # define logl(x) \
198     (GL_LINK_WARNING ("logl is unportable - " \
199                       "use gnulib module mathl for portability"), \
200      logl (x))
201 #endif
202
203
204 #if @GNULIB_MATHL@ || !@HAVE_DECL_SINL@
205 extern long double sinl (long double x);
206 #endif
207 #if !@GNULIB_MATHL@ && defined GNULIB_POSIXCHECK
208 # undef sinl
209 # define sinl(x) \
210     (GL_LINK_WARNING ("sinl is unportable - " \
211                       "use gnulib module mathl for portability"), \
212      sinl (x))
213 #endif
214
215
216 #if @GNULIB_MATHL@ || !@HAVE_DECL_SQRTL@
217 extern long double sqrtl (long double x);
218 #endif
219 #if !@GNULIB_MATHL@ && defined GNULIB_POSIXCHECK
220 # undef sqrtl
221 # define sqrtl(x) \
222     (GL_LINK_WARNING ("sqrtl is unportable - " \
223                       "use gnulib module mathl for portability"), \
224      sqrtl (x))
225 #endif
226
227
228 #if @GNULIB_MATHL@ || !@HAVE_DECL_TANL@
229 extern long double tanl (long double x);
230 #endif
231 #if !@GNULIB_MATHL@ && defined GNULIB_POSIXCHECK
232 # undef tanl
233 # define tanl(x) \
234     (GL_LINK_WARNING ("tanl is unportable - " \
235                       "use gnulib module mathl for portability"), \
236      tanl (x))
237 #endif
238
239
240 #if @GNULIB_TRUNCF@
241 # if !@HAVE_DECL_TRUNCF@
242 #  define truncf rpl_truncf
243 extern float truncf (float x);
244 # endif
245 #elif defined GNULIB_POSIXCHECK
246 # undef truncf
247 # define truncf(x) \
248     (GL_LINK_WARNING ("truncf is unportable - " \
249                       "use gnulib module truncf for portability"), \
250      truncf (x))
251 #endif
252
253 #if @GNULIB_TRUNC@
254 # if !@HAVE_DECL_TRUNC@
255 #  define trunc rpl_trunc
256 extern double trunc (double x);
257 # endif
258 #elif defined GNULIB_POSIXCHECK
259 # undef trunc
260 # define trunc(x) \
261     (GL_LINK_WARNING ("trunc is unportable - " \
262                       "use gnulib module trunc for portability"), \
263      trunc (x))
264 #endif
265
266 #if @GNULIB_TRUNCL@
267 # if !@HAVE_DECL_TRUNCL@
268 #  define truncl rpl_truncl
269 extern long double truncl (long double x);
270 # endif
271 #elif defined GNULIB_POSIXCHECK
272 # undef truncl
273 # define truncl(x) \
274     (GL_LINK_WARNING ("truncl is unportable - " \
275                       "use gnulib module truncl for portability"), \
276      truncl (x))
277 #endif
278
279
280 #if @GNULIB_SIGNBIT@
281 # if @REPLACE_SIGNBIT@
282 #  undef signbit
283 extern int gl_signbitf (float arg);
284 extern int gl_signbitd (double arg);
285 extern int gl_signbitl (long double arg);
286 #  if __GNUC__ >= 2 && !__STRICT_ANSI__
287 #   if defined FLT_SIGNBIT_WORD && defined FLT_SIGNBIT_BIT
288 #    define gl_signbitf(arg) \
289        ({ union { float _value;                                         \
290                   unsigned int _word[(sizeof (float) + sizeof (unsigned int) - 1) / sizeof (unsigned int)]; \
291                 } _m;                                                   \
292           _m._value = (arg);                                            \
293           (_m._word[FLT_SIGNBIT_WORD] >> FLT_SIGNBIT_BIT) & 1;          \
294         })
295 #   endif
296 #   if defined DBL_SIGNBIT_WORD && defined DBL_SIGNBIT_BIT
297 #    define gl_signbitd(arg) \
298        ({ union { double _value;                                                \
299                   unsigned int _word[(sizeof (double) + sizeof (unsigned int) - 1) / sizeof (unsigned int)]; \
300                 } _m;                                                   \
301           _m._value = (arg);                                            \
302           (_m._word[DBL_SIGNBIT_WORD] >> DBL_SIGNBIT_BIT) & 1;          \
303         })
304 #   endif
305 #   if defined LDBL_SIGNBIT_WORD && defined LDBL_SIGNBIT_BIT
306 #    define gl_signbitl(arg) \
307        ({ union { long double _value;                                   \
308                   unsigned int _word[(sizeof (long double) + sizeof (unsigned int) - 1) / sizeof (unsigned int)]; \
309                 } _m;                                                   \
310           _m._value = (arg);                                            \
311           (_m._word[LDBL_SIGNBIT_WORD] >> LDBL_SIGNBIT_BIT) & 1;                \
312         })
313 #   endif
314 #  endif
315 #  define signbit(x) \
316    (sizeof (x) == sizeof (long double) ? gl_signbitl (x) : \
317     sizeof (x) == sizeof (double) ? gl_signbitd (x) : \
318     gl_signbitf (x))
319 # endif
320 #elif defined GNULIB_POSIXCHECK
321   /* How to override a macro?  */
322 #endif
323
324
325 #ifdef __cplusplus
326 }
327 #endif
328
329 #endif /* _GL_MATH_H */
330 #endif /* _GL_MATH_H */