1 /* A GNU-like <math.h>.
3 Copyright (C) 2002-2003, 2007, 2008 Free Software Foundation, Inc.
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 3 of the License, or
8 (at your option) any later version.
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.
15 You should have received a copy of the GNU General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>. */
20 /* The include_next requires a split double-inclusion guard. */
21 #@INCLUDE_NEXT@ @NEXT_MATH_H@
27 /* The definition of GL_LINK_WARNING is copied here. */
35 /* POSIX allows platforms that don't support NAN. But all major
36 machines in the past 15 years have supported something close to
37 IEEE NaN, so we define this unconditionally. */
39 /* The Compaq (ex-DEC) C 6.4 compiler chokes on the expression 0.0 / 0.0. */
44 static float zero = 0.0f;
49 # define NAN (0.0f / 0.0f)
56 If x finite and nonzero: 0.5 <= |mantissa| < 1.0.
57 If x is zero: mantissa = x, exp = 0.
58 If x is infinite or NaN: mantissa = x, exp unspecified.
59 Store exp in *EXPPTR and return mantissa. */
62 # define frexp rpl_frexp
63 extern double frexp (double x, int *expptr);
65 #elif defined GNULIB_POSIXCHECK
68 (GL_LINK_WARNING ("frexp is unportable - " \
69 "use gnulib module frexp for portability"), \
74 #if @GNULIB_MATHL@ || !@HAVE_DECL_ACOSL@
75 extern long double acosl (long double x);
77 #if !@GNULIB_MATHL@ && defined GNULIB_POSIXCHECK
80 (GL_LINK_WARNING ("acosl is unportable - " \
81 "use gnulib module mathl for portability"), \
86 #if @GNULIB_MATHL@ || !@HAVE_DECL_ASINL@
87 extern long double asinl (long double x);
89 #if !@GNULIB_MATHL@ && defined GNULIB_POSIXCHECK
92 (GL_LINK_WARNING ("asinl is unportable - " \
93 "use gnulib module mathl for portability"), \
98 #if @GNULIB_MATHL@ || !@HAVE_DECL_ATANL@
99 extern long double atanl (long double x);
101 #if !@GNULIB_MATHL@ && defined GNULIB_POSIXCHECK
104 (GL_LINK_WARNING ("atanl is unportable - " \
105 "use gnulib module mathl for portability"), \
112 # define ceilf rpl_ceilf
113 extern float ceilf (float x);
115 #elif defined GNULIB_POSIXCHECK
118 (GL_LINK_WARNING ("ceilf is unportable - " \
119 "use gnulib module ceilf for portability"), \
125 # define ceill rpl_ceill
126 extern long double ceill (long double x);
128 #elif defined GNULIB_POSIXCHECK
131 (GL_LINK_WARNING ("ceill is unportable - " \
132 "use gnulib module ceill for portability"), \
137 #if @GNULIB_MATHL@ || !@HAVE_DECL_COSL@
138 extern long double cosl (long double x);
140 #if !@GNULIB_MATHL@ && defined GNULIB_POSIXCHECK
143 (GL_LINK_WARNING ("cosl is unportable - " \
144 "use gnulib module mathl for portability"), \
149 #if @GNULIB_MATHL@ || !@HAVE_DECL_EXPL@
150 extern long double expl (long double x);
152 #if !@GNULIB_MATHL@ && defined GNULIB_POSIXCHECK
155 (GL_LINK_WARNING ("expl is unportable - " \
156 "use gnulib module mathl for portability"), \
162 # if @REPLACE_FLOORF@
163 # define floorf rpl_floorf
164 extern float floorf (float x);
166 #elif defined GNULIB_POSIXCHECK
169 (GL_LINK_WARNING ("floorf is unportable - " \
170 "use gnulib module floorf for portability"), \
175 # if @REPLACE_FLOORL@
176 # define floorl rpl_floorl
177 extern long double floorl (long double x);
179 #elif defined GNULIB_POSIXCHECK
182 (GL_LINK_WARNING ("floorl is unportable - " \
183 "use gnulib module floorl for portability"), \
191 If x finite and nonzero: 0.5 <= |mantissa| < 1.0.
192 If x is zero: mantissa = x, exp = 0.
193 If x is infinite or NaN: mantissa = x, exp unspecified.
194 Store exp in *EXPPTR and return mantissa. */
195 #if @GNULIB_FREXPL@ && @REPLACE_FREXPL@
196 # define frexpl rpl_frexpl
198 #if (@GNULIB_FREXPL@ && @REPLACE_FREXPL@) || !@HAVE_DECL_FREXPL@
199 extern long double frexpl (long double x, int *expptr);
201 #if !@GNULIB_FREXPL@ && defined GNULIB_POSIXCHECK
203 # define frexpl(x,e) \
204 (GL_LINK_WARNING ("frexpl is unportable - " \
205 "use gnulib module frexpl for portability"), \
210 /* Return x * 2^exp. */
211 #if @GNULIB_LDEXPL@ && @REPLACE_LDEXPL@
212 # define ldexpl rpl_ldexpl
214 #if (@GNULIB_LDEXPL@ && @REPLACE_LDEXPL@) || !@HAVE_DECL_LDEXPL@
215 extern long double ldexpl (long double x, int exp);
217 #if !@GNULIB_LDEXPL@ && defined GNULIB_POSIXCHECK
219 # define ldexpl(x,e) \
220 (GL_LINK_WARNING ("ldexpl is unportable - " \
221 "use gnulib module ldexpl for portability"), \
226 #if @GNULIB_MATHL@ || !@HAVE_DECL_LOGL@
227 extern long double logl (long double x);
229 #if !@GNULIB_MATHL@ && defined GNULIB_POSIXCHECK
232 (GL_LINK_WARNING ("logl is unportable - " \
233 "use gnulib module mathl for portability"), \
239 # if @REPLACE_ROUNDF@
241 # define roundf rpl_roundf
242 extern float roundf (float x);
244 #elif defined GNULIB_POSIXCHECK
247 (GL_LINK_WARNING ("roundf is unportable - " \
248 "use gnulib module roundf for portability"), \
255 # define round rpl_round
256 extern double round (double x);
258 #elif defined GNULIB_POSIXCHECK
261 (GL_LINK_WARNING ("round is unportable - " \
262 "use gnulib module round for portability"), \
267 # if @REPLACE_ROUNDL@
269 # define roundl rpl_roundl
270 extern long double roundl (long double x);
272 #elif defined GNULIB_POSIXCHECK
275 (GL_LINK_WARNING ("roundl is unportable - " \
276 "use gnulib module roundl for portability"), \
281 #if @GNULIB_MATHL@ || !@HAVE_DECL_SINL@
282 extern long double sinl (long double x);
284 #if !@GNULIB_MATHL@ && defined GNULIB_POSIXCHECK
287 (GL_LINK_WARNING ("sinl is unportable - " \
288 "use gnulib module mathl for portability"), \
293 #if @GNULIB_MATHL@ || !@HAVE_DECL_SQRTL@
294 extern long double sqrtl (long double x);
296 #if !@GNULIB_MATHL@ && defined GNULIB_POSIXCHECK
299 (GL_LINK_WARNING ("sqrtl is unportable - " \
300 "use gnulib module mathl for portability"), \
305 #if @GNULIB_MATHL@ || !@HAVE_DECL_TANL@
306 extern long double tanl (long double x);
308 #if !@GNULIB_MATHL@ && defined GNULIB_POSIXCHECK
311 (GL_LINK_WARNING ("tanl is unportable - " \
312 "use gnulib module mathl for portability"), \
318 # if !@HAVE_DECL_TRUNCF@
319 # define truncf rpl_truncf
320 extern float truncf (float x);
322 #elif defined GNULIB_POSIXCHECK
325 (GL_LINK_WARNING ("truncf is unportable - " \
326 "use gnulib module truncf for portability"), \
331 # if !@HAVE_DECL_TRUNC@
332 # define trunc rpl_trunc
333 extern double trunc (double x);
335 #elif defined GNULIB_POSIXCHECK
338 (GL_LINK_WARNING ("trunc is unportable - " \
339 "use gnulib module trunc for portability"), \
344 # if !@HAVE_DECL_TRUNCL@
345 # define truncl rpl_truncl
346 extern long double truncl (long double x);
348 #elif defined GNULIB_POSIXCHECK
351 (GL_LINK_WARNING ("truncl is unportable - " \
352 "use gnulib module truncl for portability"), \
357 #if @GNULIB_ISFINITE@
358 # if @REPLACE_ISFINITE@
359 extern int gl_isfinitef (float x);
360 extern int gl_isfinited (double x);
361 extern int gl_isfinitel (long double x);
363 # define isfinite(x) \
364 (sizeof (x) == sizeof (long double) ? gl_isfinitel (x) : \
365 sizeof (x) == sizeof (double) ? gl_isfinited (x) : \
368 #elif defined GNULIB_POSIXCHECK
369 /* How to override a macro? */
374 # if @REPLACE_SIGNBIT_USING_GCC@
376 /* GCC 4.0 and newer provides three built-ins for signbit. */
377 # define signbit(x) \
378 (sizeof (x) == sizeof (long double) ? __builtin_signbitl (x) : \
379 sizeof (x) == sizeof (double) ? __builtin_signbit (x) : \
380 __builtin_signbitf (x))
382 # if @REPLACE_SIGNBIT@
384 extern int gl_signbitf (float arg);
385 extern int gl_signbitd (double arg);
386 extern int gl_signbitl (long double arg);
387 # if __GNUC__ >= 2 && !__STRICT_ANSI__
388 # if defined FLT_SIGNBIT_WORD && defined FLT_SIGNBIT_BIT
389 # define gl_signbitf(arg) \
390 ({ union { float _value; \
391 unsigned int _word[(sizeof (float) + sizeof (unsigned int) - 1) / sizeof (unsigned int)]; \
394 (_m._word[FLT_SIGNBIT_WORD] >> FLT_SIGNBIT_BIT) & 1; \
397 # if defined DBL_SIGNBIT_WORD && defined DBL_SIGNBIT_BIT
398 # define gl_signbitd(arg) \
399 ({ union { double _value; \
400 unsigned int _word[(sizeof (double) + sizeof (unsigned int) - 1) / sizeof (unsigned int)]; \
403 (_m._word[DBL_SIGNBIT_WORD] >> DBL_SIGNBIT_BIT) & 1; \
406 # if defined LDBL_SIGNBIT_WORD && defined LDBL_SIGNBIT_BIT
407 # define gl_signbitl(arg) \
408 ({ union { long double _value; \
409 unsigned int _word[(sizeof (long double) + sizeof (unsigned int) - 1) / sizeof (unsigned int)]; \
412 (_m._word[LDBL_SIGNBIT_WORD] >> LDBL_SIGNBIT_BIT) & 1; \
416 # define signbit(x) \
417 (sizeof (x) == sizeof (long double) ? gl_signbitl (x) : \
418 sizeof (x) == sizeof (double) ? gl_signbitd (x) : \
421 #elif defined GNULIB_POSIXCHECK
422 /* How to override a macro? */
430 #endif /* _GL_MATH_H */
431 #endif /* _GL_MATH_H */