2 dnl Copyright (C) 2007-2010 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_FREXPL],
9 AC_REQUIRE([gl_MATH_H_DEFAULTS])
10 dnl Check whether it's declared.
11 dnl MacOS X 10.3 has frexpl() in libc but doesn't declare it in <math.h>.
12 AC_CHECK_DECL([frexpl], , [HAVE_DECL_FREXPL=0], [#include <math.h>])
14 if test $HAVE_DECL_FREXPL = 1; then
15 gl_CHECK_FREXPL_NO_LIBM
16 if test $gl_cv_func_frexpl_no_libm = no; then
17 AC_CACHE_CHECK([whether frexpl() can be used with libm],
18 [gl_cv_func_frexpl_in_libm],
26 [[int e; return frexpl (x, &e) > 0;]])],
27 [gl_cv_func_frexpl_in_libm=yes],
28 [gl_cv_func_frexpl_in_libm=no])
31 if test $gl_cv_func_frexpl_in_libm = yes; then
35 if test $gl_cv_func_frexpl_no_libm = yes \
36 || test $gl_cv_func_frexpl_in_libm = yes; then
38 LIBS="$LIBS $FREXPL_LIBM"
41 case "$gl_cv_func_frexpl_works" in
42 *yes) gl_func_frexpl=yes ;;
43 *) gl_func_frexpl=no; REPLACE_FREXPL=1; FREXPL_LIBM= ;;
48 if test $gl_func_frexpl = yes; then
49 AC_DEFINE([HAVE_FREXPL], [1],
50 [Define if the frexpl() function is available.])
53 if test $HAVE_DECL_FREXPL = 0 || test $gl_func_frexpl = no; then
56 AC_SUBST([FREXPL_LIBM])
59 AC_DEFUN([gl_FUNC_FREXPL_NO_LIBM],
61 AC_REQUIRE([gl_MATH_H_DEFAULTS])
62 dnl Check whether it's declared.
63 dnl MacOS X 10.3 has frexpl() in libc but doesn't declare it in <math.h>.
64 AC_CHECK_DECL([frexpl], , [HAVE_DECL_FREXPL=0], [#include <math.h>])
65 if test $HAVE_DECL_FREXPL = 1; then
66 gl_CHECK_FREXPL_NO_LIBM
67 if test $gl_cv_func_frexpl_no_libm = yes; then
69 case "$gl_cv_func_frexpl_works" in
70 *yes) gl_func_frexpl_no_libm=yes ;;
71 *) gl_func_frexpl_no_libm=no; REPLACE_FREXPL=1 ;;
74 gl_func_frexpl_no_libm=no
75 dnl Set REPLACE_FREXPL here because the system may have frexpl in libm.
78 if test $gl_func_frexpl_no_libm = yes; then
79 AC_DEFINE([HAVE_FREXPL_IN_LIBC], [1],
80 [Define if the frexpl() function is available in libc.])
83 if test $HAVE_DECL_FREXPL = 0 || test $gl_func_frexpl_no_libm = no; then
88 dnl Test whether frexpl() can be used without linking with libm.
89 dnl Set gl_cv_func_frexpl_no_libm to 'yes' or 'no' accordingly.
90 AC_DEFUN([gl_CHECK_FREXPL_NO_LIBM],
92 AC_CACHE_CHECK([whether frexpl() can be used without linking with libm],
93 [gl_cv_func_frexpl_no_libm],
99 [[int e; return frexpl (x, &e) > 0;]])],
100 [gl_cv_func_frexpl_no_libm=yes],
101 [gl_cv_func_frexpl_no_libm=no])
105 dnl Test whether frexpl() works on finite numbers (this fails on
106 dnl MacOS X 10.4/PowerPC, on AIX 5.1, and on BeOS), on denormalized numbers
107 dnl (this fails on MacOS X 10.5/i386), and also on infinite numbers (this
108 dnl fails e.g. on IRIX 6.5 and mingw).
109 AC_DEFUN([gl_FUNC_FREXPL_WORKS],
111 AC_REQUIRE([AC_PROG_CC])
112 AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
113 AC_CACHE_CHECK([whether frexpl works], [gl_cv_func_frexpl_works],
119 /* Override the values of <float.h>, like done in float.in.h. */
120 #if defined __i386__ && (defined __BEOS__ || defined __OpenBSD__)
122 # define LDBL_MIN_EXP (-16381)
124 extern long double frexpl (long double, int *);
127 volatile long double x;
128 /* Test on finite numbers that fails on AIX 5.1. */
136 /* Test on finite numbers that fails on MacOS X 10.4, because its frexpl
137 function returns an invalid (incorrectly normalized) value: it returns
138 y = { 0x3fe028f5, 0xc28f5c28, 0x3c9eb851, 0xeb851eb8 }
139 but the correct result is
140 0.505L = { 0x3fe028f5, 0xc28f5c29, 0xbc547ae1, 0x47ae1480 } */
144 long double y = frexpl (x, &exp);
145 if (!(exp == 1 && y == 0.505L))
148 /* Test on large finite numbers. This fails on BeOS at i = 16322, while
149 LDBL_MAX_EXP = 16384.
150 In the loop end test, we test x against Infinity, rather than comparing
151 i with LDBL_MAX_EXP, because BeOS <float.h> has a wrong LDBL_MAX_EXP. */
154 for (i = 1, x = 1.0L; x != x + x; i++, x *= 2.0L)
162 /* Test on denormalized numbers. */
165 for (i = 1, x = 1.0L; i >= LDBL_MIN_EXP; i--, x *= 0.5L)
170 long double y = frexpl (x, &exp);
171 /* On machines with IEEE854 arithmetic: x = 1.68105e-4932,
172 exp = -16382, y = 0.5. On MacOS X 10.5: exp = -16384, y = 0.5. */
173 if (exp != LDBL_MIN_EXP - 1)
177 /* Test on infinite numbers. */
181 long double y = frexpl (x, &exp);
187 [gl_cv_func_frexpl_works=yes],
188 [gl_cv_func_frexpl_works=no],
192 aix | aix[3-6]* | beos* | darwin* | irix* | mingw* | pw*)
193 gl_cv_func_frexpl_works="guessing no";;
194 *) gl_cv_func_frexpl_works="guessing yes";;