2 dnl Copyright (C) 2007 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])
11 AC_CACHE_CHECK([whether frexp() can be used without linking with libm],
12 [gl_cv_func_frexp_no_libm],
14 AC_TRY_LINK([#include <math.h>
16 [int e; return frexp (x, &e) > 0;],
17 [gl_cv_func_frexp_no_libm=yes],
18 [gl_cv_func_frexp_no_libm=no])
20 if test $gl_cv_func_frexp_no_libm = no; then
21 AC_CACHE_CHECK([whether frexp() can be used with libm],
22 [gl_cv_func_frexp_in_libm],
26 AC_TRY_LINK([#include <math.h>
28 [int e; return frexp (x, &e) > 0;],
29 [gl_cv_func_frexp_in_libm=yes],
30 [gl_cv_func_frexp_in_libm=no])
33 if test $gl_cv_func_frexp_in_libm = yes; then
37 if test $gl_cv_func_frexp_no_libm = yes \
38 || test $gl_cv_func_frexp_in_libm = yes; then
40 LIBS="$LIBS $FREXP_LIBM"
43 case "$gl_cv_func_frexp_works" in
44 *yes) gl_func_frexp=yes ;;
45 *) gl_func_frexp=no; REPLACE_FREXP=1; FREXP_LIBM= ;;
50 if test $gl_func_frexp = yes; then
51 AC_DEFINE([HAVE_FREXP], 1,
52 [Define if the frexp() function is available and works.])
56 AC_SUBST([FREXP_LIBM])
59 AC_DEFUN([gl_FUNC_FREXP_NO_LIBM],
61 AC_REQUIRE([gl_MATH_H_DEFAULTS])
62 AC_CACHE_CHECK([whether frexp() can be used without linking with libm],
63 [gl_cv_func_frexp_no_libm],
65 AC_TRY_LINK([#include <math.h>
67 [int e; return frexp (x, &e) > 0;],
68 [gl_cv_func_frexp_no_libm=yes],
69 [gl_cv_func_frexp_no_libm=no])
71 if test $gl_cv_func_frexp_no_libm = yes; then
73 case "$gl_cv_func_frexp_works" in
74 *yes) gl_func_frexp_no_libm=yes ;;
75 *) gl_func_frexp_no_libm=no; REPLACE_FREXP=1 ;;
78 gl_func_frexp_no_libm=no
79 dnl Set REPLACE_FREXP here because the system may have frexp in libm.
82 if test $gl_func_frexp_no_libm = yes; then
83 AC_DEFINE([HAVE_FREXP_IN_LIBC], 1,
84 [Define if the frexp() function is available in libc.])
90 dnl Test whether frexp() works also on denormalized numbers (this fails e.g. on
91 dnl NetBSD 3.0) and on infinite numbers (this fails e.g. on IRIX 6.5 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_CACHE_CHECK([whether frexp works], [gl_cv_func_frexp_works],
105 /* Test on denormalized numbers. */
106 for (i = 1, x = 1.0; i >= DBL_MIN_EXP; i--, x *= 0.5)
111 double y = frexp (x, &exp);
112 /* On machines with IEEE754 arithmetic: x = 1.11254e-308, exp = -1022.
113 On NetBSD: y = 0.75. Correct: y = 0.5. */
117 /* Test on infinite numbers. */
121 double y = frexp (x, &exp);
126 }], [gl_cv_func_frexp_works=yes], [gl_cv_func_frexp_works=no],
128 netbsd* | irix* | mingw*) gl_cv_func_frexp_works="guessing no";;
129 *) gl_cv_func_frexp_works="guessing yes";;