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