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/>. */
21 @PRAGMA_SYSTEM_HEADER@
24 /* The include_next requires a split double-inclusion guard. */
25 #@INCLUDE_NEXT@ @NEXT_MATH_H@
31 /* The definition of GL_LINK_WARNING is copied here. */
39 /* POSIX allows platforms that don't support NAN. But all major
40 machines in the past 15 years have supported something close to
41 IEEE NaN, so we define this unconditionally. We also must define
42 it on platforms like Solaris 10, where NAN is present but defined
43 as a function pointer rather than a floating point constant. */
44 #if !defined NAN || @REPLACE_NAN@
46 /* The Compaq (ex-DEC) C 6.4 compiler chokes on the expression 0.0 / 0.0. */
51 static float zero = 0.0f;
56 # define NAN (0.0f / 0.0f)
60 /* Solaris 10 defines HUGE_VAL, but as a function pointer rather
61 than a floating point constant. */
62 #if @REPLACE_HUGE_VAL@
64 # define HUGE_VAL (1.0 / 0.0)
70 If x finite and nonzero: 0.5 <= |mantissa| < 1.0.
71 If x is zero: mantissa = x, exp = 0.
72 If x is infinite or NaN: mantissa = x, exp unspecified.
73 Store exp in *EXPPTR and return mantissa. */
76 # define frexp rpl_frexp
77 extern double frexp (double x, int *expptr);
79 #elif defined GNULIB_POSIXCHECK
82 (GL_LINK_WARNING ("frexp is unportable - " \
83 "use gnulib module frexp for portability"), \
88 #if @GNULIB_MATHL@ || !@HAVE_DECL_ACOSL@
89 extern long double acosl (long double x);
91 #if !@GNULIB_MATHL@ && defined GNULIB_POSIXCHECK
94 (GL_LINK_WARNING ("acosl is unportable - " \
95 "use gnulib module mathl for portability"), \
100 #if @GNULIB_MATHL@ || !@HAVE_DECL_ASINL@
101 extern long double asinl (long double x);
103 #if !@GNULIB_MATHL@ && defined GNULIB_POSIXCHECK
106 (GL_LINK_WARNING ("asinl is unportable - " \
107 "use gnulib module mathl for portability"), \
112 #if @GNULIB_MATHL@ || !@HAVE_DECL_ATANL@
113 extern long double atanl (long double x);
115 #if !@GNULIB_MATHL@ && defined GNULIB_POSIXCHECK
118 (GL_LINK_WARNING ("atanl is unportable - " \
119 "use gnulib module mathl for portability"), \
126 # define ceilf rpl_ceilf
127 extern float ceilf (float x);
129 #elif defined GNULIB_POSIXCHECK
132 (GL_LINK_WARNING ("ceilf is unportable - " \
133 "use gnulib module ceilf for portability"), \
139 # define ceill rpl_ceill
140 extern long double ceill (long double x);
142 #elif defined GNULIB_POSIXCHECK
145 (GL_LINK_WARNING ("ceill is unportable - " \
146 "use gnulib module ceill for portability"), \
151 #if @GNULIB_MATHL@ || !@HAVE_DECL_COSL@
152 extern long double cosl (long double x);
154 #if !@GNULIB_MATHL@ && defined GNULIB_POSIXCHECK
157 (GL_LINK_WARNING ("cosl is unportable - " \
158 "use gnulib module mathl for portability"), \
163 #if @GNULIB_MATHL@ || !@HAVE_DECL_EXPL@
164 extern long double expl (long double x);
166 #if !@GNULIB_MATHL@ && defined GNULIB_POSIXCHECK
169 (GL_LINK_WARNING ("expl is unportable - " \
170 "use gnulib module mathl for portability"), \
176 # if @REPLACE_FLOORF@
177 # define floorf rpl_floorf
178 extern float floorf (float x);
180 #elif defined GNULIB_POSIXCHECK
183 (GL_LINK_WARNING ("floorf is unportable - " \
184 "use gnulib module floorf for portability"), \
189 # if @REPLACE_FLOORL@
190 # define floorl rpl_floorl
191 extern long double floorl (long double x);
193 #elif defined GNULIB_POSIXCHECK
196 (GL_LINK_WARNING ("floorl is unportable - " \
197 "use gnulib module floorl for portability"), \
205 If x finite and nonzero: 0.5 <= |mantissa| < 1.0.
206 If x is zero: mantissa = x, exp = 0.
207 If x is infinite or NaN: mantissa = x, exp unspecified.
208 Store exp in *EXPPTR and return mantissa. */
209 #if @GNULIB_FREXPL@ && @REPLACE_FREXPL@
210 # define frexpl rpl_frexpl
212 #if (@GNULIB_FREXPL@ && @REPLACE_FREXPL@) || !@HAVE_DECL_FREXPL@
213 extern long double frexpl (long double x, int *expptr);
215 #if !@GNULIB_FREXPL@ && defined GNULIB_POSIXCHECK
217 # define frexpl(x,e) \
218 (GL_LINK_WARNING ("frexpl is unportable - " \
219 "use gnulib module frexpl for portability"), \
224 /* Return x * 2^exp. */
225 #if @GNULIB_LDEXPL@ && @REPLACE_LDEXPL@
226 # define ldexpl rpl_ldexpl
228 #if (@GNULIB_LDEXPL@ && @REPLACE_LDEXPL@) || !@HAVE_DECL_LDEXPL@
229 extern long double ldexpl (long double x, int exp);
231 #if !@GNULIB_LDEXPL@ && defined GNULIB_POSIXCHECK
233 # define ldexpl(x,e) \
234 (GL_LINK_WARNING ("ldexpl is unportable - " \
235 "use gnulib module ldexpl for portability"), \
240 #if @GNULIB_MATHL@ || !@HAVE_DECL_LOGL@
241 extern long double logl (long double x);
243 #if !@GNULIB_MATHL@ && defined GNULIB_POSIXCHECK
246 (GL_LINK_WARNING ("logl is unportable - " \
247 "use gnulib module mathl for portability"), \
253 # if @REPLACE_ROUNDF@
255 # define roundf rpl_roundf
256 extern float roundf (float x);
258 #elif defined GNULIB_POSIXCHECK
261 (GL_LINK_WARNING ("roundf is unportable - " \
262 "use gnulib module roundf for portability"), \
269 # define round rpl_round
270 extern double round (double x);
272 #elif defined GNULIB_POSIXCHECK
275 (GL_LINK_WARNING ("round is unportable - " \
276 "use gnulib module round for portability"), \
281 # if @REPLACE_ROUNDL@
283 # define roundl rpl_roundl
284 extern long double roundl (long double x);
286 #elif defined GNULIB_POSIXCHECK
289 (GL_LINK_WARNING ("roundl is unportable - " \
290 "use gnulib module roundl for portability"), \
295 #if @GNULIB_MATHL@ || !@HAVE_DECL_SINL@
296 extern long double sinl (long double x);
298 #if !@GNULIB_MATHL@ && defined GNULIB_POSIXCHECK
301 (GL_LINK_WARNING ("sinl is unportable - " \
302 "use gnulib module mathl for portability"), \
307 #if @GNULIB_MATHL@ || !@HAVE_DECL_SQRTL@
308 extern long double sqrtl (long double x);
310 #if !@GNULIB_MATHL@ && defined GNULIB_POSIXCHECK
313 (GL_LINK_WARNING ("sqrtl is unportable - " \
314 "use gnulib module mathl for portability"), \
319 #if @GNULIB_MATHL@ || !@HAVE_DECL_TANL@
320 extern long double tanl (long double x);
322 #if !@GNULIB_MATHL@ && defined GNULIB_POSIXCHECK
325 (GL_LINK_WARNING ("tanl is unportable - " \
326 "use gnulib module mathl for portability"), \
332 # if !@HAVE_DECL_TRUNCF@
333 # define truncf rpl_truncf
334 extern float truncf (float x);
336 #elif defined GNULIB_POSIXCHECK
339 (GL_LINK_WARNING ("truncf is unportable - " \
340 "use gnulib module truncf for portability"), \
345 # if !@HAVE_DECL_TRUNC@
346 # define trunc rpl_trunc
347 extern double trunc (double x);
349 #elif defined GNULIB_POSIXCHECK
352 (GL_LINK_WARNING ("trunc is unportable - " \
353 "use gnulib module trunc for portability"), \
358 # if @REPLACE_TRUNCL@
360 # define truncl rpl_truncl
361 extern long double truncl (long double x);
363 #elif defined GNULIB_POSIXCHECK
366 (GL_LINK_WARNING ("truncl is unportable - " \
367 "use gnulib module truncl for portability"), \
372 #if @GNULIB_ISFINITE@
373 # if @REPLACE_ISFINITE@
374 extern int gl_isfinitef (float x);
375 extern int gl_isfinited (double x);
376 extern int gl_isfinitel (long double x);
378 # define isfinite(x) \
379 (sizeof (x) == sizeof (long double) ? gl_isfinitel (x) : \
380 sizeof (x) == sizeof (double) ? gl_isfinited (x) : \
383 #elif defined GNULIB_POSIXCHECK
384 /* How to override a macro? */
390 extern int gl_isinff (float x);
391 extern int gl_isinfd (double x);
392 extern int gl_isinfl (long double x);
395 (sizeof (x) == sizeof (long double) ? gl_isinfl (x) : \
396 sizeof (x) == sizeof (double) ? gl_isinfd (x) : \
399 #elif defined GNULIB_POSIXCHECK
400 /* How to override a macro? */
406 /* We can't just use the isnanf macro (e.g.) as exposed by
407 isnanf.h (e.g.) here, because those may end up being macros
408 that recursively expand back to isnan. So use the gnulib
409 replacements for them directly. */
410 # if HAVE_ISNANF && __GNUC__ >= 4
411 # define gl_isnan_f(x) __builtin_isnan ((float)(x))
413 extern int rpl_isnanf (float x);
414 # define gl_isnan_f(x) rpl_isnanf (x)
416 # if HAVE_ISNAND && __GNUC__ >= 4
417 # define gl_isnan_d(x) __builtin_isnan ((double)(x))
419 extern int rpl_isnand (double x);
420 # define gl_isnan_d(x) rpl_isnand (x)
422 # if HAVE_ISNANL && __GNUC__ >= 4
423 # define gl_isnan_l(x) __builtin_isnan ((long double)(x))
425 extern int rpl_isnanl (long double x);
426 # define gl_isnan_l(x) rpl_isnanl (x)
430 (sizeof (x) == sizeof (long double) ? gl_isnan_l (x) : \
431 sizeof (x) == sizeof (double) ? gl_isnan_d (x) : \
434 #elif defined GNULIB_POSIXCHECK
435 /* How to override a macro? */
440 # if @REPLACE_SIGNBIT_USING_GCC@
442 /* GCC 4.0 and newer provides three built-ins for signbit. */
443 # define signbit(x) \
444 (sizeof (x) == sizeof (long double) ? __builtin_signbitl (x) : \
445 sizeof (x) == sizeof (double) ? __builtin_signbit (x) : \
446 __builtin_signbitf (x))
448 # if @REPLACE_SIGNBIT@
450 extern int gl_signbitf (float arg);
451 extern int gl_signbitd (double arg);
452 extern int gl_signbitl (long double arg);
453 # if __GNUC__ >= 2 && !__STRICT_ANSI__
454 # if defined FLT_SIGNBIT_WORD && defined FLT_SIGNBIT_BIT
455 # define gl_signbitf(arg) \
456 ({ union { float _value; \
457 unsigned int _word[(sizeof (float) + sizeof (unsigned int) - 1) / sizeof (unsigned int)]; \
460 (_m._word[FLT_SIGNBIT_WORD] >> FLT_SIGNBIT_BIT) & 1; \
463 # if defined DBL_SIGNBIT_WORD && defined DBL_SIGNBIT_BIT
464 # define gl_signbitd(arg) \
465 ({ union { double _value; \
466 unsigned int _word[(sizeof (double) + sizeof (unsigned int) - 1) / sizeof (unsigned int)]; \
469 (_m._word[DBL_SIGNBIT_WORD] >> DBL_SIGNBIT_BIT) & 1; \
472 # if defined LDBL_SIGNBIT_WORD && defined LDBL_SIGNBIT_BIT
473 # define gl_signbitl(arg) \
474 ({ union { long double _value; \
475 unsigned int _word[(sizeof (long double) + sizeof (unsigned int) - 1) / sizeof (unsigned int)]; \
478 (_m._word[LDBL_SIGNBIT_WORD] >> LDBL_SIGNBIT_BIT) & 1; \
482 # define signbit(x) \
483 (sizeof (x) == sizeof (long double) ? gl_signbitl (x) : \
484 sizeof (x) == sizeof (double) ? gl_signbitd (x) : \
487 #elif defined GNULIB_POSIXCHECK
488 /* How to override a macro? */
496 #endif /* _GL_MATH_H */
497 #endif /* _GL_MATH_H */