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_FREXPL],
9 AC_REQUIRE([gl_MATH_H_DEFAULTS])
10 AC_REQUIRE([gl_LONG_DOUBLE_VS_DOUBLE])
11 dnl Check whether it's declared.
12 dnl MacOS X 10.3 has frexpl() in libc but doesn't declare it in <math.h>.
13 AC_CHECK_DECL([frexpl], , [HAVE_DECL_FREXPL=0], [[#include <math.h>]])
15 if test $HAVE_DECL_FREXPL = 1; then
16 gl_CHECK_FREXPL_NO_LIBM
17 if test $gl_cv_func_frexpl_no_libm = no; then
18 AC_CACHE_CHECK([whether frexpl() can be used with libm],
19 [gl_cv_func_frexpl_in_libm],
27 [[int e; return frexpl (x, &e) > 0;]])],
28 [gl_cv_func_frexpl_in_libm=yes],
29 [gl_cv_func_frexpl_in_libm=no])
32 if test $gl_cv_func_frexpl_in_libm = yes; then
36 if test $gl_cv_func_frexpl_no_libm = yes \
37 || test $gl_cv_func_frexpl_in_libm = yes; then
39 LIBS="$LIBS $FREXPL_LIBM"
42 case "$gl_cv_func_frexpl_works" in
43 *yes) gl_func_frexpl=yes ;;
44 *) gl_func_frexpl=no; REPLACE_FREXPL=1 ;;
49 if test $gl_func_frexpl = yes; then
50 AC_DEFINE([HAVE_FREXPL], [1],
51 [Define if the frexpl() function is available.])
54 if test $HAVE_DECL_FREXPL = 0 || test $gl_func_frexpl = no; then
55 dnl Find libraries needed to link lib/frexpl.c.
56 if test $HAVE_SAME_LONG_DOUBLE_AS_DOUBLE = 1; then
57 AC_REQUIRE([gl_FUNC_FREXP])
58 FREXPL_LIBM="$FREXP_LIBM"
63 AC_SUBST([FREXPL_LIBM])
66 AC_DEFUN([gl_FUNC_FREXPL_NO_LIBM],
68 AC_REQUIRE([gl_MATH_H_DEFAULTS])
69 AC_REQUIRE([gl_LONG_DOUBLE_VS_DOUBLE])
70 dnl Check whether it's declared.
71 dnl MacOS X 10.3 has frexpl() in libc but doesn't declare it in <math.h>.
72 AC_CHECK_DECL([frexpl], , [HAVE_DECL_FREXPL=0], [[#include <math.h>]])
73 if test $HAVE_DECL_FREXPL = 1; then
74 gl_CHECK_FREXPL_NO_LIBM
75 if test $gl_cv_func_frexpl_no_libm = yes; then
77 case "$gl_cv_func_frexpl_works" in
78 *yes) gl_func_frexpl_no_libm=yes ;;
79 *) gl_func_frexpl_no_libm=no; REPLACE_FREXPL=1 ;;
82 gl_func_frexpl_no_libm=no
83 dnl Set REPLACE_FREXPL here because the system may have frexpl in libm.
86 if test $gl_func_frexpl_no_libm = yes; then
87 AC_DEFINE([HAVE_FREXPL_IN_LIBC], [1],
88 [Define if the frexpl() function is available in libc.])
93 dnl Test whether frexpl() can be used without linking with libm.
94 dnl Set gl_cv_func_frexpl_no_libm to 'yes' or 'no' accordingly.
95 AC_DEFUN([gl_CHECK_FREXPL_NO_LIBM],
97 AC_CACHE_CHECK([whether frexpl() can be used without linking with libm],
98 [gl_cv_func_frexpl_no_libm],
104 [[int e; return frexpl (x, &e) > 0;]])],
105 [gl_cv_func_frexpl_no_libm=yes],
106 [gl_cv_func_frexpl_no_libm=no])
110 dnl Test whether frexpl() works on finite numbers (this fails on
111 dnl MacOS X 10.4/PowerPC, on AIX 5.1, and on BeOS), on denormalized numbers
112 dnl (this fails on MacOS X 10.5/i386), and also on infinite numbers (this
113 dnl fails e.g. on IRIX 6.5 and mingw).
114 AC_DEFUN([gl_FUNC_FREXPL_WORKS],
116 AC_REQUIRE([AC_PROG_CC])
117 AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
118 AC_CACHE_CHECK([whether frexpl works], [gl_cv_func_frexpl_works],
124 /* Override the values of <float.h>, like done in float.in.h. */
125 #if defined __i386__ && (defined __BEOS__ || defined __OpenBSD__)
127 # define LDBL_MIN_EXP (-16381)
129 #if defined __i386__ && defined __FreeBSD__
131 # define LDBL_MIN_EXP (-16381)
133 #if (defined _ARCH_PPC || defined _POWER) && defined _AIX && (LDBL_MANT_DIG == 106) && defined __GNUC__
135 # define LDBL_MIN_EXP DBL_MIN_EXP
137 #if defined __sgi && (LDBL_MANT_DIG >= 106)
138 # if defined __GNUC__
140 # define LDBL_MIN_EXP DBL_MIN_EXP
147 long double frexpl (long double, int *);
151 volatile long double x;
152 /* Test on finite numbers that fails on AIX 5.1. */
160 /* Test on finite numbers that fails on MacOS X 10.4, because its frexpl
161 function returns an invalid (incorrectly normalized) value: it returns
162 y = { 0x3fe028f5, 0xc28f5c28, 0x3c9eb851, 0xeb851eb8 }
163 but the correct result is
164 0.505L = { 0x3fe028f5, 0xc28f5c29, 0xbc547ae1, 0x47ae1480 } */
168 long double y = frexpl (x, &exp);
169 if (!(exp == 1 && y == 0.505L))
172 /* Test on large finite numbers. This fails on BeOS at i = 16322, while
173 LDBL_MAX_EXP = 16384.
174 In the loop end test, we test x against Infinity, rather than comparing
175 i with LDBL_MAX_EXP, because BeOS <float.h> has a wrong LDBL_MAX_EXP. */
178 for (i = 1, x = 1.0L; x != x + x; i++, x *= 2.0L)
189 /* Test on denormalized numbers. */
192 for (i = 1, x = 1.0L; i >= LDBL_MIN_EXP; i--, x *= 0.5L)
197 long double y = frexpl (x, &exp);
198 /* On machines with IEEE854 arithmetic: x = 1.68105e-4932,
199 exp = -16382, y = 0.5. On MacOS X 10.5: exp = -16384, y = 0.5. */
200 if (exp != LDBL_MIN_EXP - 1)
204 /* Test on infinite numbers. */
208 long double y = frexpl (x, &exp);
214 [gl_cv_func_frexpl_works=yes],
215 [gl_cv_func_frexpl_works=no],
219 aix | aix[3-6]* | beos* | darwin* | irix* | mingw* | pw*)
220 gl_cv_func_frexpl_works="guessing no";;
221 *) gl_cv_func_frexpl_works="guessing yes";;