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