2 dnl Copyright (C) 2007-2017 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])
12 dnl Persuade glibc <math.h> to declare frexpl().
13 AC_REQUIRE([gl_USE_SYSTEM_EXTENSIONS])
15 dnl Check whether it's declared.
16 dnl Mac OS X 10.3 has frexpl() in libc but doesn't declare it in <math.h>.
17 AC_CHECK_DECL([frexpl], , [HAVE_DECL_FREXPL=0], [[#include <math.h>]])
20 if test $HAVE_DECL_FREXPL = 1; then
21 gl_CHECK_FREXPL_NO_LIBM
22 if test $gl_cv_func_frexpl_no_libm = no; then
23 AC_CACHE_CHECK([whether frexpl() can be used with libm],
24 [gl_cv_func_frexpl_in_libm],
32 [[int e; return frexpl (x, &e) > 0;]])],
33 [gl_cv_func_frexpl_in_libm=yes],
34 [gl_cv_func_frexpl_in_libm=no])
37 if test $gl_cv_func_frexpl_in_libm = yes; then
41 if test $gl_cv_func_frexpl_no_libm = yes \
42 || test $gl_cv_func_frexpl_in_libm = yes; then
44 LIBS="$LIBS $FREXPL_LIBM"
47 case "$gl_cv_func_frexpl_works" in
48 *yes) gl_func_frexpl=yes ;;
49 *) gl_func_frexpl=no; REPLACE_FREXPL=1 ;;
54 if test $gl_func_frexpl = yes; then
55 AC_DEFINE([HAVE_FREXPL], [1],
56 [Define if the frexpl() function is available.])
59 if test $HAVE_DECL_FREXPL = 0 || test $gl_func_frexpl = no; then
60 dnl Find libraries needed to link lib/frexpl.c.
61 if test $HAVE_SAME_LONG_DOUBLE_AS_DOUBLE = 1; then
62 AC_REQUIRE([gl_FUNC_FREXP])
63 FREXPL_LIBM="$FREXP_LIBM"
68 AC_SUBST([FREXPL_LIBM])
71 AC_DEFUN([gl_FUNC_FREXPL_NO_LIBM],
73 AC_REQUIRE([gl_MATH_H_DEFAULTS])
74 AC_REQUIRE([gl_LONG_DOUBLE_VS_DOUBLE])
75 dnl Check whether it's declared.
76 dnl Mac OS X 10.3 has frexpl() in libc but doesn't declare it in <math.h>.
77 AC_CHECK_DECL([frexpl], , [HAVE_DECL_FREXPL=0], [[#include <math.h>]])
78 if test $HAVE_DECL_FREXPL = 1; then
79 gl_CHECK_FREXPL_NO_LIBM
80 if test $gl_cv_func_frexpl_no_libm = yes; then
82 case "$gl_cv_func_frexpl_works" in
83 *yes) gl_func_frexpl_no_libm=yes ;;
84 *) gl_func_frexpl_no_libm=no; REPLACE_FREXPL=1 ;;
87 gl_func_frexpl_no_libm=no
88 dnl Set REPLACE_FREXPL here because the system may have frexpl in libm.
91 if test $gl_func_frexpl_no_libm = yes; then
92 AC_DEFINE([HAVE_FREXPL_IN_LIBC], [1],
93 [Define if the frexpl() function is available in libc.])
98 dnl Test whether frexpl() can be used without linking with libm.
99 dnl Set gl_cv_func_frexpl_no_libm to 'yes' or 'no' accordingly.
100 AC_DEFUN([gl_CHECK_FREXPL_NO_LIBM],
102 AC_CACHE_CHECK([whether frexpl() can be used without linking with libm],
103 [gl_cv_func_frexpl_no_libm],
109 [[int e; return frexpl (x, &e) > 0;]])],
110 [gl_cv_func_frexpl_no_libm=yes],
111 [gl_cv_func_frexpl_no_libm=no])
115 dnl Test whether frexpl() works on finite numbers (this fails on
116 dnl Mac OS X 10.4/PowerPC, on AIX 5.1, and on BeOS), on denormalized numbers
117 dnl (this fails on Mac OS X 10.5/i386), and also on infinite numbers (this
118 dnl fails e.g. on IRIX 6.5 and mingw).
119 AC_DEFUN([gl_FUNC_FREXPL_WORKS],
121 AC_REQUIRE([AC_PROG_CC])
122 AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
123 AC_CACHE_CHECK([whether frexpl works], [gl_cv_func_frexpl_works],
129 /* Override the values of <float.h>, like done in float.in.h. */
130 #if defined __i386__ && (defined __BEOS__ || defined __OpenBSD__)
132 # define LDBL_MIN_EXP (-16381)
134 #if defined __i386__ && (defined __FreeBSD__ || defined __DragonFly__)
136 # define LDBL_MIN_EXP (-16381)
138 #if (defined _ARCH_PPC || defined _POWER) && defined _AIX && (LDBL_MANT_DIG == 106) && defined __GNUC__
140 # define LDBL_MIN_EXP DBL_MIN_EXP
142 #if defined __sgi && (LDBL_MANT_DIG >= 106)
143 # if defined __GNUC__
145 # define LDBL_MIN_EXP DBL_MIN_EXP
152 long double frexpl (long double, int *);
156 volatile long double x;
157 /* Test on finite numbers that fails on AIX 5.1. */
165 /* Test on finite numbers that fails on Mac OS X 10.4, because its frexpl
166 function returns an invalid (incorrectly normalized) value: it returns
167 y = { 0x3fe028f5, 0xc28f5c28, 0x3c9eb851, 0xeb851eb8 }
168 but the correct result is
169 0.505L = { 0x3fe028f5, 0xc28f5c29, 0xbc547ae1, 0x47ae1480 } */
173 long double y = frexpl (x, &exp);
174 if (!(exp == 1 && y == 0.505L))
177 /* Test on large finite numbers. This fails on BeOS at i = 16322, while
178 LDBL_MAX_EXP = 16384.
179 In the loop end test, we test x against Infinity, rather than comparing
180 i with LDBL_MAX_EXP, because BeOS <float.h> has a wrong LDBL_MAX_EXP. */
183 for (i = 1, x = 1.0L; x != x + x; i++, x *= 2.0L)
194 /* Test on denormalized numbers. */
197 for (i = 1, x = 1.0L; i >= LDBL_MIN_EXP; i--, x *= 0.5L)
202 long double y = frexpl (x, &exp);
203 /* On machines with IEEE854 arithmetic: x = 1.68105e-4932,
204 exp = -16382, y = 0.5. On Mac OS X 10.5: exp = -16384, y = 0.5. */
205 if (exp != LDBL_MIN_EXP - 1)
209 /* Test on infinite numbers. */
213 long double y = frexpl (x, &exp);
219 [gl_cv_func_frexpl_works=yes],
220 [gl_cv_func_frexpl_works=no],
224 aix | aix[3-6]* | beos* | darwin* | irix* | mingw* | pw*)
225 gl_cv_func_frexpl_works="guessing no";;
226 *) gl_cv_func_frexpl_works="guessing yes";;