2 dnl Copyright (C) 2007-2012 Free Software Foundation, Inc.
3 dnl This file is free software; the Free Software Foundation
4 dnl gives unlimited permission to copy and/or distribute it,
5 dnl with or without modifications, as long as this notice is preserved.
7 AC_DEFUN([gl_FUNC_FREXP],
9 AC_REQUIRE([gl_MATH_H_DEFAULTS])
10 AC_REQUIRE([gl_CHECK_FREXP_NO_LIBM])
12 if test $gl_cv_func_frexp_no_libm = no; then
13 AC_CACHE_CHECK([whether frexp() can be used with libm],
14 [gl_cv_func_frexp_in_libm],
22 [[int e; return frexp (x, &e) > 0;]])],
23 [gl_cv_func_frexp_in_libm=yes],
24 [gl_cv_func_frexp_in_libm=no])
27 if test $gl_cv_func_frexp_in_libm = yes; then
31 if test $gl_cv_func_frexp_no_libm = yes \
32 || test $gl_cv_func_frexp_in_libm = yes; then
34 LIBS="$LIBS $FREXP_LIBM"
37 case "$gl_cv_func_frexp_works" in
38 *yes) gl_func_frexp=yes ;;
39 *) gl_func_frexp=no; REPLACE_FREXP=1; FREXP_LIBM= ;;
44 if test $gl_func_frexp = yes; then
45 AC_DEFINE([HAVE_FREXP], [1],
46 [Define if the frexp() function is available and works.])
48 AC_SUBST([FREXP_LIBM])
51 AC_DEFUN([gl_FUNC_FREXP_NO_LIBM],
53 AC_REQUIRE([gl_MATH_H_DEFAULTS])
54 AC_REQUIRE([gl_CHECK_FREXP_NO_LIBM])
55 if test $gl_cv_func_frexp_no_libm = yes; then
57 case "$gl_cv_func_frexp_works" in
58 *yes) gl_func_frexp_no_libm=yes ;;
59 *) gl_func_frexp_no_libm=no; REPLACE_FREXP=1 ;;
62 gl_func_frexp_no_libm=no
63 dnl Set REPLACE_FREXP here because the system may have frexp in libm.
66 if test $gl_func_frexp_no_libm = yes; then
67 AC_DEFINE([HAVE_FREXP_IN_LIBC], [1],
68 [Define if the frexp() function is available in libc.])
72 dnl Test whether frexp() can be used without linking with libm.
73 dnl Set gl_cv_func_frexp_no_libm to 'yes' or 'no' accordingly.
74 AC_DEFUN([gl_CHECK_FREXP_NO_LIBM],
76 AC_CACHE_CHECK([whether frexp() can be used without linking with libm],
77 [gl_cv_func_frexp_no_libm],
83 [[int e; return frexp (x, &e) > 0;]])],
84 [gl_cv_func_frexp_no_libm=yes],
85 [gl_cv_func_frexp_no_libm=no])
89 dnl Test whether frexp() works also on denormalized numbers (this fails e.g. on
90 dnl NetBSD 3.0), on infinite numbers (this fails e.g. on IRIX 6.5 and mingw),
91 dnl and on negative zero (this fails e.g. on NetBSD 4.99 and mingw).
92 AC_DEFUN([gl_FUNC_FREXP_WORKS],
94 AC_REQUIRE([AC_PROG_CC])
95 AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
96 AC_CHECK_FUNCS_ONCE([alarm])
97 AC_CACHE_CHECK([whether frexp works], [gl_cv_func_frexp_works],
107 /* HP cc on HP-UX 10.20 has a bug with the constant expression -0.0.
108 ICC 10.0 has a bug when optimizing the expression -zero.
109 The expression -DBL_MIN * DBL_MIN does not work when cross-compiling
110 to PowerPC on Mac OS X 10.5. */
111 #if defined __hpux || defined __sgi || defined __ICC
113 compute_minus_zero (void)
115 return -DBL_MIN * DBL_MIN;
117 # define minus_zero compute_minus_zero ()
119 double minus_zero = -0.0;
128 /* NeXTstep 3.3 frexp() runs into an endless loop when called on an infinite
129 number. Let the test fail in this case. */
132 /* Test on denormalized numbers. */
133 for (i = 1, x = 1.0; i >= DBL_MIN_EXP; i--, x *= 0.5)
138 double y = frexp (x, &exp);
139 /* On machines with IEEE754 arithmetic: x = 1.11254e-308, exp = -1022.
140 On NetBSD: y = 0.75. Correct: y = 0.5. */
144 /* Test on infinite numbers. */
148 double y = frexp (x, &exp);
152 /* Test on negative zero. */
156 double y = frexp (x, &exp);
157 if (memcmp (&y, &x, sizeof x))
162 [gl_cv_func_frexp_works=yes],
163 [gl_cv_func_frexp_works=no],
165 netbsd* | irix* | mingw*) gl_cv_func_frexp_works="guessing no";;
166 *) gl_cv_func_frexp_works="guessing yes";;