New module 'truncf'.
[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_MATHL@ || !@HAVE_DECL_FLOORL@
130 extern long double floorl (long double x);
131 #endif
132 #if !@GNULIB_MATHL@ && defined GNULIB_POSIXCHECK
133 # undef floorl
134 # define floorl(x) \
135     (GL_LINK_WARNING ("floorl is unportable - " \
136                       "use gnulib module mathl for portability"), \
137      floorl (x))
138 #endif
139
140
141 /* Write x as
142      x = mantissa * 2^exp
143    where
144      If x finite and nonzero: 0.5 <= |mantissa| < 1.0.
145      If x is zero: mantissa = x, exp = 0.
146      If x is infinite or NaN: mantissa = x, exp unspecified.
147    Store exp and return mantissa.  */
148 #if @GNULIB_FREXPL@ && @REPLACE_FREXPL@
149 # define frexpl rpl_frexpl
150 #endif
151 #if (@GNULIB_FREXPL@ && @REPLACE_FREXPL@) || !@HAVE_DECL_FREXPL@
152 extern long double frexpl (long double x, int *exp);
153 #endif
154 #if !@GNULIB_FREXPL@ && defined GNULIB_POSIXCHECK
155 # undef frexpl
156 # define frexpl(x,e) \
157     (GL_LINK_WARNING ("frexpl is unportable - " \
158                       "use gnulib module frexpl for portability"), \
159      frexpl (x, e))
160 #endif
161
162
163 /* Return x * 2^exp.  */
164 #if @GNULIB_LDEXPL@ && @REPLACE_LDEXPL@
165 # define ldexpl rpl_ldexpl
166 #endif
167 #if (@GNULIB_LDEXPL@ && @REPLACE_LDEXPL@) || !@HAVE_DECL_LDEXPL@
168 extern long double ldexpl (long double x, int exp);
169 #endif
170 #if !@GNULIB_LDEXPL@ && defined GNULIB_POSIXCHECK
171 # undef ldexpl
172 # define ldexpl(x,e) \
173     (GL_LINK_WARNING ("ldexpl is unportable - " \
174                       "use gnulib module ldexpl for portability"), \
175      ldexpl (x, e))
176 #endif
177
178
179 #if @GNULIB_MATHL@ || !@HAVE_DECL_LOGL@
180 extern long double logl (long double x);
181 #endif
182 #if !@GNULIB_MATHL@ && defined GNULIB_POSIXCHECK
183 # undef logl
184 # define logl(x) \
185     (GL_LINK_WARNING ("logl is unportable - " \
186                       "use gnulib module mathl for portability"), \
187      logl (x))
188 #endif
189
190
191 #if @GNULIB_MATHL@ || !@HAVE_DECL_SINL@
192 extern long double sinl (long double x);
193 #endif
194 #if !@GNULIB_MATHL@ && defined GNULIB_POSIXCHECK
195 # undef sinl
196 # define sinl(x) \
197     (GL_LINK_WARNING ("sinl is unportable - " \
198                       "use gnulib module mathl for portability"), \
199      sinl (x))
200 #endif
201
202
203 #if @GNULIB_MATHL@ || !@HAVE_DECL_SQRTL@
204 extern long double sqrtl (long double x);
205 #endif
206 #if !@GNULIB_MATHL@ && defined GNULIB_POSIXCHECK
207 # undef sqrtl
208 # define sqrtl(x) \
209     (GL_LINK_WARNING ("sqrtl is unportable - " \
210                       "use gnulib module mathl for portability"), \
211      sqrtl (x))
212 #endif
213
214
215 #if @GNULIB_MATHL@ || !@HAVE_DECL_TANL@
216 extern long double tanl (long double x);
217 #endif
218 #if !@GNULIB_MATHL@ && defined GNULIB_POSIXCHECK
219 # undef tanl
220 # define tanl(x) \
221     (GL_LINK_WARNING ("tanl is unportable - " \
222                       "use gnulib module mathl for portability"), \
223      tanl (x))
224 #endif
225
226
227 #if @GNULIB_TRUNCF@
228 # if !@HAVE_DECL_TRUNCF@
229 #  define truncf rpl_truncf
230 extern float truncf (float x);
231 # endif
232 #elif defined GNULIB_POSIXCHECK
233 # undef truncf
234 # define truncf(x) \
235     (GL_LINK_WARNING ("truncf is unportable - " \
236                       "use gnulib module truncf for portability"), \
237      truncf (x))
238 #endif
239
240 #if @GNULIB_TRUNC@
241 # if !@HAVE_DECL_TRUNC@
242 #  define trunc rpl_trunc
243 extern double trunc (double x);
244 # endif
245 #elif defined GNULIB_POSIXCHECK
246 # undef trunc
247 # define trunc(x) \
248     (GL_LINK_WARNING ("trunc is unportable - " \
249                       "use gnulib module trunc for portability"), \
250      trunc (x))
251 #endif
252
253
254 #if @GNULIB_SIGNBIT@
255 # if @REPLACE_SIGNBIT@
256 #  undef signbit
257 extern int gl_signbitf (float arg);
258 extern int gl_signbitd (double arg);
259 extern int gl_signbitl (long double arg);
260 #  if __GNUC__ >= 2 && !__STRICT_ANSI__
261 #   if defined FLT_SIGNBIT_WORD && defined FLT_SIGNBIT_BIT
262 #    define gl_signbitf(arg) \
263        ({ union { float _value;                                         \
264                   unsigned int _word[(sizeof (float) + sizeof (unsigned int) - 1) / sizeof (unsigned int)]; \
265                 } _m;                                                   \
266           _m._value = (arg);                                            \
267           (_m._word[FLT_SIGNBIT_WORD] >> FLT_SIGNBIT_BIT) & 1;          \
268         })
269 #   endif
270 #   if defined DBL_SIGNBIT_WORD && defined DBL_SIGNBIT_BIT
271 #    define gl_signbitd(arg) \
272        ({ union { double _value;                                                \
273                   unsigned int _word[(sizeof (double) + sizeof (unsigned int) - 1) / sizeof (unsigned int)]; \
274                 } _m;                                                   \
275           _m._value = (arg);                                            \
276           (_m._word[DBL_SIGNBIT_WORD] >> DBL_SIGNBIT_BIT) & 1;          \
277         })
278 #   endif
279 #   if defined LDBL_SIGNBIT_WORD && defined LDBL_SIGNBIT_BIT
280 #    define gl_signbitl(arg) \
281        ({ union { long double _value;                                   \
282                   unsigned int _word[(sizeof (long double) + sizeof (unsigned int) - 1) / sizeof (unsigned int)]; \
283                 } _m;                                                   \
284           _m._value = (arg);                                            \
285           (_m._word[LDBL_SIGNBIT_WORD] >> LDBL_SIGNBIT_BIT) & 1;                \
286         })
287 #   endif
288 #  endif
289 #  define signbit(x) \
290    (sizeof (x) == sizeof (long double) ? gl_signbitl (x) : \
291     sizeof (x) == sizeof (double) ? gl_signbitd (x) : \
292     gl_signbitf (x))
293 # endif
294 #elif defined GNULIB_POSIXCHECK
295   /* How to override a macro?  */
296 #endif
297
298
299 #ifdef __cplusplus
300 }
301 #endif
302
303 #endif /* _GL_MATH_H */
304 #endif /* _GL_MATH_H */