3 dnl Copyright (C) 2007-2024 Free Software Foundation, Inc.
4 dnl This file is free software; the Free Software Foundation
5 dnl gives unlimited permission to copy and/or distribute it,
6 dnl with or without modifications, as long as this notice is preserved.
8 AC_DEFUN([gl_FUNC_FREXP],
10 AC_REQUIRE([gl_MATH_H_DEFAULTS])
11 AC_REQUIRE([gl_CHECK_FREXP_NO_LIBM])
13 if test $gl_cv_func_frexp_no_libm = no; then
14 AC_CACHE_CHECK([whether frexp() can be used with libm],
15 [gl_cv_func_frexp_in_libm],
23 [[int e; return frexp (x, &e) > 0;]])],
24 [gl_cv_func_frexp_in_libm=yes],
25 [gl_cv_func_frexp_in_libm=no])
28 if test $gl_cv_func_frexp_in_libm = yes; then
32 if test $gl_cv_func_frexp_no_libm = yes \
33 || test $gl_cv_func_frexp_in_libm = yes; then
35 LIBS="$LIBS $FREXP_LIBM"
38 case "$gl_cv_func_frexp_works" in
39 *yes) gl_func_frexp=yes ;;
40 *) gl_func_frexp=no; REPLACE_FREXP=1; FREXP_LIBM= ;;
45 if test $gl_func_frexp = yes; then
46 AC_DEFINE([HAVE_FREXP], [1],
47 [Define if the frexp() function is available and works.])
49 AC_SUBST([FREXP_LIBM])
52 AC_DEFUN([gl_FUNC_FREXP_NO_LIBM],
54 AC_REQUIRE([gl_MATH_H_DEFAULTS])
55 AC_REQUIRE([gl_CHECK_FREXP_NO_LIBM])
56 if test $gl_cv_func_frexp_no_libm = yes; then
58 case "$gl_cv_func_frexp_works" in
59 *yes) gl_func_frexp_no_libm=yes ;;
60 *) gl_func_frexp_no_libm=no; REPLACE_FREXP=1 ;;
63 gl_func_frexp_no_libm=no
64 dnl Set REPLACE_FREXP here because the system may have frexp in libm.
67 if test $gl_func_frexp_no_libm = yes; then
68 AC_DEFINE([HAVE_FREXP_IN_LIBC], [1],
69 [Define if the frexp() function is available in libc.])
73 dnl Test whether frexp() can be used without linking with libm.
74 dnl Set gl_cv_func_frexp_no_libm to 'yes' or 'no' accordingly.
75 AC_DEFUN([gl_CHECK_FREXP_NO_LIBM],
77 AC_CACHE_CHECK([whether frexp() can be used without linking with libm],
78 [gl_cv_func_frexp_no_libm],
84 [[int e; return frexp (x, &e) > 0;]])],
85 [gl_cv_func_frexp_no_libm=yes],
86 [gl_cv_func_frexp_no_libm=no])
90 dnl Test whether frexp() works also on denormalized numbers (this fails e.g. on
91 dnl NetBSD 3.0), on infinite numbers (this fails e.g. on IRIX 6.5 and mingw),
92 dnl and on negative zero (this fails e.g. on NetBSD 4.99 and mingw).
93 AC_DEFUN([gl_FUNC_FREXP_WORKS],
95 AC_REQUIRE([AC_PROG_CC])
96 AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
97 AC_CHECK_DECLS_ONCE([alarm])
98 AC_CACHE_CHECK([whether frexp works], [gl_cv_func_frexp_works],
109 /* HP cc on HP-UX 10.20 has a bug with the constant expression -0.0.
110 ICC 10.0 has a bug when optimizing the expression -zero.
111 The expression -DBL_MIN * DBL_MIN does not work when cross-compiling
112 to PowerPC on Mac OS X 10.5. */
113 #if defined __hpux || defined __sgi || defined __ICC
115 compute_minus_zero (void)
117 return -DBL_MIN * DBL_MIN;
119 # define minus_zero compute_minus_zero ()
121 double minus_zero = -0.0;
130 /* NeXTstep 3.3 frexp() runs into an endless loop when called on an infinite
131 number. Let the test fail in this case. */
132 signal (SIGALRM, SIG_DFL);
135 /* Test on denormalized numbers. */
136 for (i = 1, x = 1.0; i >= DBL_MIN_EXP; i--, x *= 0.5)
141 double y = frexp (x, &exp);
142 /* On machines with IEEE754 arithmetic: x = 1.11254e-308, exp = -1022.
143 On NetBSD: y = 0.75. Correct: y = 0.5. */
147 /* Test on infinite numbers. */
151 double y = frexp (x, &exp);
155 /* Test on negative zero. */
159 double y = frexp (x, &exp);
161 if (memcmp (&y, &x1, sizeof x1))
166 [gl_cv_func_frexp_works=yes],
167 [gl_cv_func_frexp_works=no],
169 netbsd* | irix*) gl_cv_func_frexp_works="guessing no" ;;
170 # Guess yes with MSVC, no with mingw.
172 gl_cv_func_frexp_works="guessing yes"
175 AC_EGREP_CPP([Good], [
180 [gl_cv_func_frexp_works="guessing yes"],
181 [gl_cv_func_frexp_works="guessing no"])
183 *) gl_cv_func_frexp_works="guessing yes" ;;