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. We also must define
38 it on platforms like Solaris 10, where NAN is present but defined
39 as a function pointer rather than a floating point constant. */
40 #if !defined NAN || @REPLACE_NAN@
42 /* The Compaq (ex-DEC) C 6.4 compiler chokes on the expression 0.0 / 0.0. */
47 static float zero = 0.0f;
52 # define NAN (0.0f / 0.0f)
56 /* Solaris 10 defines HUGE_VAL, but as a function pointer rather
57 than a floating point constant. */
58 #if @REPLACE_HUGE_VAL@
60 # define HUGE_VAL (1.0 / 0.0)
66 If x finite and nonzero: 0.5 <= |mantissa| < 1.0.
67 If x is zero: mantissa = x, exp = 0.
68 If x is infinite or NaN: mantissa = x, exp unspecified.
69 Store exp in *EXPPTR and return mantissa. */
72 # define frexp rpl_frexp
73 extern double frexp (double x, int *expptr);
75 #elif defined GNULIB_POSIXCHECK
78 (GL_LINK_WARNING ("frexp is unportable - " \
79 "use gnulib module frexp for portability"), \
84 #if @GNULIB_MATHL@ || !@HAVE_DECL_ACOSL@
85 extern long double acosl (long double x);
87 #if !@GNULIB_MATHL@ && defined GNULIB_POSIXCHECK
90 (GL_LINK_WARNING ("acosl is unportable - " \
91 "use gnulib module mathl for portability"), \
96 #if @GNULIB_MATHL@ || !@HAVE_DECL_ASINL@
97 extern long double asinl (long double x);
99 #if !@GNULIB_MATHL@ && defined GNULIB_POSIXCHECK
102 (GL_LINK_WARNING ("asinl is unportable - " \
103 "use gnulib module mathl for portability"), \
108 #if @GNULIB_MATHL@ || !@HAVE_DECL_ATANL@
109 extern long double atanl (long double x);
111 #if !@GNULIB_MATHL@ && defined GNULIB_POSIXCHECK
114 (GL_LINK_WARNING ("atanl is unportable - " \
115 "use gnulib module mathl for portability"), \
122 # define ceilf rpl_ceilf
123 extern float ceilf (float x);
125 #elif defined GNULIB_POSIXCHECK
128 (GL_LINK_WARNING ("ceilf is unportable - " \
129 "use gnulib module ceilf for portability"), \
135 # define ceill rpl_ceill
136 extern long double ceill (long double x);
138 #elif defined GNULIB_POSIXCHECK
141 (GL_LINK_WARNING ("ceill is unportable - " \
142 "use gnulib module ceill for portability"), \
147 #if @GNULIB_MATHL@ || !@HAVE_DECL_COSL@
148 extern long double cosl (long double x);
150 #if !@GNULIB_MATHL@ && defined GNULIB_POSIXCHECK
153 (GL_LINK_WARNING ("cosl is unportable - " \
154 "use gnulib module mathl for portability"), \
159 #if @GNULIB_MATHL@ || !@HAVE_DECL_EXPL@
160 extern long double expl (long double x);
162 #if !@GNULIB_MATHL@ && defined GNULIB_POSIXCHECK
165 (GL_LINK_WARNING ("expl is unportable - " \
166 "use gnulib module mathl for portability"), \
172 # if @REPLACE_FLOORF@
173 # define floorf rpl_floorf
174 extern float floorf (float x);
176 #elif defined GNULIB_POSIXCHECK
179 (GL_LINK_WARNING ("floorf is unportable - " \
180 "use gnulib module floorf for portability"), \
185 # if @REPLACE_FLOORL@
186 # define floorl rpl_floorl
187 extern long double floorl (long double x);
189 #elif defined GNULIB_POSIXCHECK
192 (GL_LINK_WARNING ("floorl is unportable - " \
193 "use gnulib module floorl for portability"), \
201 If x finite and nonzero: 0.5 <= |mantissa| < 1.0.
202 If x is zero: mantissa = x, exp = 0.
203 If x is infinite or NaN: mantissa = x, exp unspecified.
204 Store exp in *EXPPTR and return mantissa. */
205 #if @GNULIB_FREXPL@ && @REPLACE_FREXPL@
206 # define frexpl rpl_frexpl
208 #if (@GNULIB_FREXPL@ && @REPLACE_FREXPL@) || !@HAVE_DECL_FREXPL@
209 extern long double frexpl (long double x, int *expptr);
211 #if !@GNULIB_FREXPL@ && defined GNULIB_POSIXCHECK
213 # define frexpl(x,e) \
214 (GL_LINK_WARNING ("frexpl is unportable - " \
215 "use gnulib module frexpl for portability"), \
220 /* Return x * 2^exp. */
221 #if @GNULIB_LDEXPL@ && @REPLACE_LDEXPL@
222 # define ldexpl rpl_ldexpl
224 #if (@GNULIB_LDEXPL@ && @REPLACE_LDEXPL@) || !@HAVE_DECL_LDEXPL@
225 extern long double ldexpl (long double x, int exp);
227 #if !@GNULIB_LDEXPL@ && defined GNULIB_POSIXCHECK
229 # define ldexpl(x,e) \
230 (GL_LINK_WARNING ("ldexpl is unportable - " \
231 "use gnulib module ldexpl for portability"), \
236 #if @GNULIB_MATHL@ || !@HAVE_DECL_LOGL@
237 extern long double logl (long double x);
239 #if !@GNULIB_MATHL@ && defined GNULIB_POSIXCHECK
242 (GL_LINK_WARNING ("logl is unportable - " \
243 "use gnulib module mathl for portability"), \
249 # if @REPLACE_ROUNDF@
251 # define roundf rpl_roundf
252 extern float roundf (float x);
254 #elif defined GNULIB_POSIXCHECK
257 (GL_LINK_WARNING ("roundf is unportable - " \
258 "use gnulib module roundf for portability"), \
265 # define round rpl_round
266 extern double round (double x);
268 #elif defined GNULIB_POSIXCHECK
271 (GL_LINK_WARNING ("round is unportable - " \
272 "use gnulib module round for portability"), \
277 # if @REPLACE_ROUNDL@
279 # define roundl rpl_roundl
280 extern long double roundl (long double x);
282 #elif defined GNULIB_POSIXCHECK
285 (GL_LINK_WARNING ("roundl is unportable - " \
286 "use gnulib module roundl for portability"), \
291 #if @GNULIB_MATHL@ || !@HAVE_DECL_SINL@
292 extern long double sinl (long double x);
294 #if !@GNULIB_MATHL@ && defined GNULIB_POSIXCHECK
297 (GL_LINK_WARNING ("sinl is unportable - " \
298 "use gnulib module mathl for portability"), \
303 #if @GNULIB_MATHL@ || !@HAVE_DECL_SQRTL@
304 extern long double sqrtl (long double x);
306 #if !@GNULIB_MATHL@ && defined GNULIB_POSIXCHECK
309 (GL_LINK_WARNING ("sqrtl is unportable - " \
310 "use gnulib module mathl for portability"), \
315 #if @GNULIB_MATHL@ || !@HAVE_DECL_TANL@
316 extern long double tanl (long double x);
318 #if !@GNULIB_MATHL@ && defined GNULIB_POSIXCHECK
321 (GL_LINK_WARNING ("tanl is unportable - " \
322 "use gnulib module mathl for portability"), \
328 # if !@HAVE_DECL_TRUNCF@
329 # define truncf rpl_truncf
330 extern float truncf (float x);
332 #elif defined GNULIB_POSIXCHECK
335 (GL_LINK_WARNING ("truncf is unportable - " \
336 "use gnulib module truncf for portability"), \
341 # if !@HAVE_DECL_TRUNC@
342 # define trunc rpl_trunc
343 extern double trunc (double x);
345 #elif defined GNULIB_POSIXCHECK
348 (GL_LINK_WARNING ("trunc is unportable - " \
349 "use gnulib module trunc for portability"), \
354 # if @REPLACE_TRUNCL@
356 # define truncl rpl_truncl
357 extern long double truncl (long double x);
359 #elif defined GNULIB_POSIXCHECK
362 (GL_LINK_WARNING ("truncl is unportable - " \
363 "use gnulib module truncl for portability"), \
368 #if @GNULIB_ISFINITE@
369 # if @REPLACE_ISFINITE@
370 extern int gl_isfinitef (float x);
371 extern int gl_isfinited (double x);
372 extern int gl_isfinitel (long double x);
374 # define isfinite(x) \
375 (sizeof (x) == sizeof (long double) ? gl_isfinitel (x) : \
376 sizeof (x) == sizeof (double) ? gl_isfinited (x) : \
379 #elif defined GNULIB_POSIXCHECK
380 /* How to override a macro? */
385 # if @REPLACE_SIGNBIT_USING_GCC@
387 /* GCC 4.0 and newer provides three built-ins for signbit. */
388 # define signbit(x) \
389 (sizeof (x) == sizeof (long double) ? __builtin_signbitl (x) : \
390 sizeof (x) == sizeof (double) ? __builtin_signbit (x) : \
391 __builtin_signbitf (x))
393 # if @REPLACE_SIGNBIT@
395 extern int gl_signbitf (float arg);
396 extern int gl_signbitd (double arg);
397 extern int gl_signbitl (long double arg);
398 # if __GNUC__ >= 2 && !__STRICT_ANSI__
399 # if defined FLT_SIGNBIT_WORD && defined FLT_SIGNBIT_BIT
400 # define gl_signbitf(arg) \
401 ({ union { float _value; \
402 unsigned int _word[(sizeof (float) + sizeof (unsigned int) - 1) / sizeof (unsigned int)]; \
405 (_m._word[FLT_SIGNBIT_WORD] >> FLT_SIGNBIT_BIT) & 1; \
408 # if defined DBL_SIGNBIT_WORD && defined DBL_SIGNBIT_BIT
409 # define gl_signbitd(arg) \
410 ({ union { double _value; \
411 unsigned int _word[(sizeof (double) + sizeof (unsigned int) - 1) / sizeof (unsigned int)]; \
414 (_m._word[DBL_SIGNBIT_WORD] >> DBL_SIGNBIT_BIT) & 1; \
417 # if defined LDBL_SIGNBIT_WORD && defined LDBL_SIGNBIT_BIT
418 # define gl_signbitl(arg) \
419 ({ union { long double _value; \
420 unsigned int _word[(sizeof (long double) + sizeof (unsigned int) - 1) / sizeof (unsigned int)]; \
423 (_m._word[LDBL_SIGNBIT_WORD] >> LDBL_SIGNBIT_BIT) & 1; \
427 # define signbit(x) \
428 (sizeof (x) == sizeof (long double) ? gl_signbitl (x) : \
429 sizeof (x) == sizeof (double) ? gl_signbitd (x) : \
432 #elif defined GNULIB_POSIXCHECK
433 /* How to override a macro? */
441 #endif /* _GL_MATH_H */
442 #endif /* _GL_MATH_H */