2 dnl Copyright (C) 2007-2011 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 AC_SUBST([FREXPL_LIBM])
56 AC_DEFUN([gl_FUNC_FREXPL_NO_LIBM],
58 AC_REQUIRE([gl_MATH_H_DEFAULTS])
59 dnl Check whether it's declared.
60 dnl MacOS X 10.3 has frexpl() in libc but doesn't declare it in <math.h>.
61 AC_CHECK_DECL([frexpl], , [HAVE_DECL_FREXPL=0], [[#include <math.h>]])
62 if test $HAVE_DECL_FREXPL = 1; then
63 gl_CHECK_FREXPL_NO_LIBM
64 if test $gl_cv_func_frexpl_no_libm = yes; then
66 case "$gl_cv_func_frexpl_works" in
67 *yes) gl_func_frexpl_no_libm=yes ;;
68 *) gl_func_frexpl_no_libm=no; REPLACE_FREXPL=1 ;;
71 gl_func_frexpl_no_libm=no
72 dnl Set REPLACE_FREXPL here because the system may have frexpl in libm.
75 if test $gl_func_frexpl_no_libm = yes; then
76 AC_DEFINE([HAVE_FREXPL_IN_LIBC], [1],
77 [Define if the frexpl() function is available in libc.])
82 dnl Test whether frexpl() can be used without linking with libm.
83 dnl Set gl_cv_func_frexpl_no_libm to 'yes' or 'no' accordingly.
84 AC_DEFUN([gl_CHECK_FREXPL_NO_LIBM],
86 AC_CACHE_CHECK([whether frexpl() can be used without linking with libm],
87 [gl_cv_func_frexpl_no_libm],
93 [[int e; return frexpl (x, &e) > 0;]])],
94 [gl_cv_func_frexpl_no_libm=yes],
95 [gl_cv_func_frexpl_no_libm=no])
99 dnl Test whether frexpl() works on finite numbers (this fails on
100 dnl MacOS X 10.4/PowerPC, on AIX 5.1, and on BeOS), on denormalized numbers
101 dnl (this fails on MacOS X 10.5/i386), and also on infinite numbers (this
102 dnl fails e.g. on IRIX 6.5 and mingw).
103 AC_DEFUN([gl_FUNC_FREXPL_WORKS],
105 AC_REQUIRE([AC_PROG_CC])
106 AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
107 AC_CACHE_CHECK([whether frexpl works], [gl_cv_func_frexpl_works],
113 /* Override the values of <float.h>, like done in float.in.h. */
114 #if defined __i386__ && (defined __BEOS__ || defined __OpenBSD__)
116 # define LDBL_MIN_EXP (-16381)
118 #if defined __i386__ && defined __FreeBSD__
120 # define LDBL_MIN_EXP (-16381)
122 #if (defined _ARCH_PPC || defined _POWER) && defined _AIX && (LDBL_MANT_DIG == 106) && defined __GNUC__
124 # define LDBL_MIN_EXP DBL_MIN_EXP
126 #if defined __sgi && (LDBL_MANT_DIG >= 106)
127 # if defined __GNUC__
129 # define LDBL_MIN_EXP DBL_MIN_EXP
136 long double frexpl (long double, int *);
140 volatile long double x;
141 /* Test on finite numbers that fails on AIX 5.1. */
149 /* Test on finite numbers that fails on MacOS X 10.4, because its frexpl
150 function returns an invalid (incorrectly normalized) value: it returns
151 y = { 0x3fe028f5, 0xc28f5c28, 0x3c9eb851, 0xeb851eb8 }
152 but the correct result is
153 0.505L = { 0x3fe028f5, 0xc28f5c29, 0xbc547ae1, 0x47ae1480 } */
157 long double y = frexpl (x, &exp);
158 if (!(exp == 1 && y == 0.505L))
161 /* Test on large finite numbers. This fails on BeOS at i = 16322, while
162 LDBL_MAX_EXP = 16384.
163 In the loop end test, we test x against Infinity, rather than comparing
164 i with LDBL_MAX_EXP, because BeOS <float.h> has a wrong LDBL_MAX_EXP. */
167 for (i = 1, x = 1.0L; x != x + x; i++, x *= 2.0L)
178 /* Test on denormalized numbers. */
181 for (i = 1, x = 1.0L; i >= LDBL_MIN_EXP; i--, x *= 0.5L)
186 long double y = frexpl (x, &exp);
187 /* On machines with IEEE854 arithmetic: x = 1.68105e-4932,
188 exp = -16382, y = 0.5. On MacOS X 10.5: exp = -16384, y = 0.5. */
189 if (exp != LDBL_MIN_EXP - 1)
193 /* Test on infinite numbers. */
197 long double y = frexpl (x, &exp);
203 [gl_cv_func_frexpl_works=yes],
204 [gl_cv_func_frexpl_works=no],
208 aix | aix[3-6]* | beos* | darwin* | irix* | mingw* | pw*)
209 gl_cv_func_frexpl_works="guessing no";;
210 *) gl_cv_func_frexpl_works="guessing yes";;