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 @PRAGMA_SYSTEM_HEADER@
22 /* The include_next requires a split double-inclusion guard. */
23 #@INCLUDE_NEXT@ @NEXT_MATH_H@
29 /* The definition of GL_LINK_WARNING is copied here. */
37 /* POSIX allows platforms that don't support NAN. But all major
38 machines in the past 15 years have supported something close to
39 IEEE NaN, so we define this unconditionally. We also must define
40 it on platforms like Solaris 10, where NAN is present but defined
41 as a function pointer rather than a floating point constant. */
42 #if !defined NAN || @REPLACE_NAN@
44 /* The Compaq (ex-DEC) C 6.4 compiler chokes on the expression 0.0 / 0.0. */
49 static float zero = 0.0f;
54 # define NAN (0.0f / 0.0f)
58 /* Solaris 10 defines HUGE_VAL, but as a function pointer rather
59 than a floating point constant. */
60 #if @REPLACE_HUGE_VAL@
62 # define HUGE_VAL (1.0 / 0.0)
68 If x finite and nonzero: 0.5 <= |mantissa| < 1.0.
69 If x is zero: mantissa = x, exp = 0.
70 If x is infinite or NaN: mantissa = x, exp unspecified.
71 Store exp in *EXPPTR and return mantissa. */
74 # define frexp rpl_frexp
75 extern double frexp (double x, int *expptr);
77 #elif defined GNULIB_POSIXCHECK
80 (GL_LINK_WARNING ("frexp is unportable - " \
81 "use gnulib module frexp for portability"), \
86 #if @GNULIB_MATHL@ || !@HAVE_DECL_ACOSL@
87 extern long double acosl (long double x);
89 #if !@GNULIB_MATHL@ && defined GNULIB_POSIXCHECK
92 (GL_LINK_WARNING ("acosl is unportable - " \
93 "use gnulib module mathl for portability"), \
98 #if @GNULIB_MATHL@ || !@HAVE_DECL_ASINL@
99 extern long double asinl (long double x);
101 #if !@GNULIB_MATHL@ && defined GNULIB_POSIXCHECK
104 (GL_LINK_WARNING ("asinl is unportable - " \
105 "use gnulib module mathl for portability"), \
110 #if @GNULIB_MATHL@ || !@HAVE_DECL_ATANL@
111 extern long double atanl (long double x);
113 #if !@GNULIB_MATHL@ && defined GNULIB_POSIXCHECK
116 (GL_LINK_WARNING ("atanl is unportable - " \
117 "use gnulib module mathl for portability"), \
124 # define ceilf rpl_ceilf
125 extern float ceilf (float x);
127 #elif defined GNULIB_POSIXCHECK
130 (GL_LINK_WARNING ("ceilf is unportable - " \
131 "use gnulib module ceilf for portability"), \
137 # define ceill rpl_ceill
138 extern long double ceill (long double x);
140 #elif defined GNULIB_POSIXCHECK
143 (GL_LINK_WARNING ("ceill is unportable - " \
144 "use gnulib module ceill for portability"), \
149 #if @GNULIB_MATHL@ || !@HAVE_DECL_COSL@
150 extern long double cosl (long double x);
152 #if !@GNULIB_MATHL@ && defined GNULIB_POSIXCHECK
155 (GL_LINK_WARNING ("cosl is unportable - " \
156 "use gnulib module mathl for portability"), \
161 #if @GNULIB_MATHL@ || !@HAVE_DECL_EXPL@
162 extern long double expl (long double x);
164 #if !@GNULIB_MATHL@ && defined GNULIB_POSIXCHECK
167 (GL_LINK_WARNING ("expl is unportable - " \
168 "use gnulib module mathl for portability"), \
174 # if @REPLACE_FLOORF@
175 # define floorf rpl_floorf
176 extern float floorf (float x);
178 #elif defined GNULIB_POSIXCHECK
181 (GL_LINK_WARNING ("floorf is unportable - " \
182 "use gnulib module floorf for portability"), \
187 # if @REPLACE_FLOORL@
188 # define floorl rpl_floorl
189 extern long double floorl (long double x);
191 #elif defined GNULIB_POSIXCHECK
194 (GL_LINK_WARNING ("floorl is unportable - " \
195 "use gnulib module floorl for portability"), \
203 If x finite and nonzero: 0.5 <= |mantissa| < 1.0.
204 If x is zero: mantissa = x, exp = 0.
205 If x is infinite or NaN: mantissa = x, exp unspecified.
206 Store exp in *EXPPTR and return mantissa. */
207 #if @GNULIB_FREXPL@ && @REPLACE_FREXPL@
208 # define frexpl rpl_frexpl
210 #if (@GNULIB_FREXPL@ && @REPLACE_FREXPL@) || !@HAVE_DECL_FREXPL@
211 extern long double frexpl (long double x, int *expptr);
213 #if !@GNULIB_FREXPL@ && defined GNULIB_POSIXCHECK
215 # define frexpl(x,e) \
216 (GL_LINK_WARNING ("frexpl is unportable - " \
217 "use gnulib module frexpl for portability"), \
222 /* Return x * 2^exp. */
223 #if @GNULIB_LDEXPL@ && @REPLACE_LDEXPL@
224 # define ldexpl rpl_ldexpl
226 #if (@GNULIB_LDEXPL@ && @REPLACE_LDEXPL@) || !@HAVE_DECL_LDEXPL@
227 extern long double ldexpl (long double x, int exp);
229 #if !@GNULIB_LDEXPL@ && defined GNULIB_POSIXCHECK
231 # define ldexpl(x,e) \
232 (GL_LINK_WARNING ("ldexpl is unportable - " \
233 "use gnulib module ldexpl for portability"), \
238 #if @GNULIB_MATHL@ || !@HAVE_DECL_LOGL@
239 extern long double logl (long double x);
241 #if !@GNULIB_MATHL@ && defined GNULIB_POSIXCHECK
244 (GL_LINK_WARNING ("logl is unportable - " \
245 "use gnulib module mathl for portability"), \
251 # if @REPLACE_ROUNDF@
253 # define roundf rpl_roundf
254 extern float roundf (float x);
256 #elif defined GNULIB_POSIXCHECK
259 (GL_LINK_WARNING ("roundf is unportable - " \
260 "use gnulib module roundf for portability"), \
267 # define round rpl_round
268 extern double round (double x);
270 #elif defined GNULIB_POSIXCHECK
273 (GL_LINK_WARNING ("round is unportable - " \
274 "use gnulib module round for portability"), \
279 # if @REPLACE_ROUNDL@
281 # define roundl rpl_roundl
282 extern long double roundl (long double x);
284 #elif defined GNULIB_POSIXCHECK
287 (GL_LINK_WARNING ("roundl is unportable - " \
288 "use gnulib module roundl for portability"), \
293 #if @GNULIB_MATHL@ || !@HAVE_DECL_SINL@
294 extern long double sinl (long double x);
296 #if !@GNULIB_MATHL@ && defined GNULIB_POSIXCHECK
299 (GL_LINK_WARNING ("sinl is unportable - " \
300 "use gnulib module mathl for portability"), \
305 #if @GNULIB_MATHL@ || !@HAVE_DECL_SQRTL@
306 extern long double sqrtl (long double x);
308 #if !@GNULIB_MATHL@ && defined GNULIB_POSIXCHECK
311 (GL_LINK_WARNING ("sqrtl is unportable - " \
312 "use gnulib module mathl for portability"), \
317 #if @GNULIB_MATHL@ || !@HAVE_DECL_TANL@
318 extern long double tanl (long double x);
320 #if !@GNULIB_MATHL@ && defined GNULIB_POSIXCHECK
323 (GL_LINK_WARNING ("tanl is unportable - " \
324 "use gnulib module mathl for portability"), \
330 # if !@HAVE_DECL_TRUNCF@
331 # define truncf rpl_truncf
332 extern float truncf (float x);
334 #elif defined GNULIB_POSIXCHECK
337 (GL_LINK_WARNING ("truncf is unportable - " \
338 "use gnulib module truncf for portability"), \
343 # if !@HAVE_DECL_TRUNC@
344 # define trunc rpl_trunc
345 extern double trunc (double x);
347 #elif defined GNULIB_POSIXCHECK
350 (GL_LINK_WARNING ("trunc is unportable - " \
351 "use gnulib module trunc for portability"), \
356 # if @REPLACE_TRUNCL@
358 # define truncl rpl_truncl
359 extern long double truncl (long double x);
361 #elif defined GNULIB_POSIXCHECK
364 (GL_LINK_WARNING ("truncl is unportable - " \
365 "use gnulib module truncl for portability"), \
370 #if @GNULIB_ISFINITE@
371 # if @REPLACE_ISFINITE@
372 extern int gl_isfinitef (float x);
373 extern int gl_isfinited (double x);
374 extern int gl_isfinitel (long double x);
376 # define isfinite(x) \
377 (sizeof (x) == sizeof (long double) ? gl_isfinitel (x) : \
378 sizeof (x) == sizeof (double) ? gl_isfinited (x) : \
381 #elif defined GNULIB_POSIXCHECK
382 /* How to override a macro? */
388 extern int gl_isinff (float x);
389 extern int gl_isinfd (double x);
390 extern int gl_isinfl (long double x);
393 (sizeof (x) == sizeof (long double) ? gl_isinfl (x) : \
394 sizeof (x) == sizeof (double) ? gl_isinfd (x) : \
397 #elif defined GNULIB_POSIXCHECK
398 /* How to override a macro? */
404 /* We can't just use the isnanf macro (e.g.) as exposed by
405 isnanf.h (e.g.) here, because those may end up being macros
406 that recursively expand back to isnan. So use the gnulib
407 replacements for them directly. */
408 # if HAVE_ISNANF && __GNUC__ >= 4
409 # define gl_isnan_f(x) __builtin_isnan ((float)(x))
411 extern int rpl_isnanf (float x);
412 # define gl_isnan_f(x) rpl_isnanf (x)
414 # if HAVE_ISNAND && __GNUC__ >= 4
415 # define gl_isnan_d(x) __builtin_isnan ((double)(x))
417 extern int rpl_isnand (double x);
418 # define gl_isnan_d(x) rpl_isnand (x)
420 # if HAVE_ISNANL && __GNUC__ >= 4
421 # define gl_isnan_l(x) __builtin_isnan ((long double)(x))
423 extern int rpl_isnanl (long double x);
424 # define gl_isnan_l(x) rpl_isnanl (x)
428 (sizeof (x) == sizeof (long double) ? gl_isnan_l (x) : \
429 sizeof (x) == sizeof (double) ? gl_isnan_d (x) : \
432 #elif defined GNULIB_POSIXCHECK
433 /* How to override a macro? */
438 # if @REPLACE_SIGNBIT_USING_GCC@
440 /* GCC 4.0 and newer provides three built-ins for signbit. */
441 # define signbit(x) \
442 (sizeof (x) == sizeof (long double) ? __builtin_signbitl (x) : \
443 sizeof (x) == sizeof (double) ? __builtin_signbit (x) : \
444 __builtin_signbitf (x))
446 # if @REPLACE_SIGNBIT@
448 extern int gl_signbitf (float arg);
449 extern int gl_signbitd (double arg);
450 extern int gl_signbitl (long double arg);
451 # if __GNUC__ >= 2 && !__STRICT_ANSI__
452 # if defined FLT_SIGNBIT_WORD && defined FLT_SIGNBIT_BIT
453 # define gl_signbitf(arg) \
454 ({ union { float _value; \
455 unsigned int _word[(sizeof (float) + sizeof (unsigned int) - 1) / sizeof (unsigned int)]; \
458 (_m._word[FLT_SIGNBIT_WORD] >> FLT_SIGNBIT_BIT) & 1; \
461 # if defined DBL_SIGNBIT_WORD && defined DBL_SIGNBIT_BIT
462 # define gl_signbitd(arg) \
463 ({ union { double _value; \
464 unsigned int _word[(sizeof (double) + sizeof (unsigned int) - 1) / sizeof (unsigned int)]; \
467 (_m._word[DBL_SIGNBIT_WORD] >> DBL_SIGNBIT_BIT) & 1; \
470 # if defined LDBL_SIGNBIT_WORD && defined LDBL_SIGNBIT_BIT
471 # define gl_signbitl(arg) \
472 ({ union { long double _value; \
473 unsigned int _word[(sizeof (long double) + sizeof (unsigned int) - 1) / sizeof (unsigned int)]; \
476 (_m._word[LDBL_SIGNBIT_WORD] >> LDBL_SIGNBIT_BIT) & 1; \
480 # define signbit(x) \
481 (sizeof (x) == sizeof (long double) ? gl_signbitl (x) : \
482 sizeof (x) == sizeof (double) ? gl_signbitd (x) : \
485 #elif defined GNULIB_POSIXCHECK
486 /* How to override a macro? */
494 #endif /* _GL_MATH_H */
495 #endif /* _GL_MATH_H */