3 dnl Copyright (C) 2007-2024 Free Software Foundation, Inc.
4 dnl This file is free software; the Free Software Foundation
5 dnl gives unlimited permission to copy and/or distribute it,
6 dnl with or without modifications, as long as this notice is preserved.
8 AC_DEFUN([gl_FUNC_FREXPL],
10 AC_REQUIRE([gl_MATH_H_DEFAULTS])
11 AC_REQUIRE([gl_LONG_DOUBLE_VS_DOUBLE])
13 dnl Persuade glibc <math.h> to declare frexpl().
14 AC_REQUIRE([gl_USE_SYSTEM_EXTENSIONS])
16 dnl Check whether it's declared.
17 dnl Mac OS X 10.3 has frexpl() in libc but doesn't declare it in <math.h>.
18 AC_CHECK_DECL([frexpl], , [HAVE_DECL_FREXPL=0], [[#include <math.h>]])
21 if test $HAVE_DECL_FREXPL = 1; then
22 gl_CHECK_FREXPL_NO_LIBM
23 if test $gl_cv_func_frexpl_no_libm = no; then
24 AC_CACHE_CHECK([whether frexpl() can be used with libm],
25 [gl_cv_func_frexpl_in_libm],
33 [[int e; return frexpl (x, &e) > 0;]])],
34 [gl_cv_func_frexpl_in_libm=yes],
35 [gl_cv_func_frexpl_in_libm=no])
38 if test $gl_cv_func_frexpl_in_libm = yes; then
42 if test $gl_cv_func_frexpl_no_libm = yes \
43 || test $gl_cv_func_frexpl_in_libm = yes; then
45 LIBS="$LIBS $FREXPL_LIBM"
48 case "$gl_cv_func_frexpl_works" in
49 *yes) gl_func_frexpl=yes ;;
50 *) gl_func_frexpl=no; REPLACE_FREXPL=1 ;;
55 if test $gl_func_frexpl = yes; then
56 AC_DEFINE([HAVE_FREXPL], [1],
57 [Define if the frexpl() function is available.])
60 if test $HAVE_DECL_FREXPL = 0 || test $gl_func_frexpl = no; then
61 dnl Find libraries needed to link lib/frexpl.c.
62 if test $HAVE_SAME_LONG_DOUBLE_AS_DOUBLE = 1; then
63 AC_REQUIRE([gl_FUNC_FREXP])
64 FREXPL_LIBM="$FREXP_LIBM"
69 AC_SUBST([FREXPL_LIBM])
72 AC_DEFUN([gl_FUNC_FREXPL_NO_LIBM],
74 AC_REQUIRE([gl_MATH_H_DEFAULTS])
75 AC_REQUIRE([gl_LONG_DOUBLE_VS_DOUBLE])
76 dnl Check whether it's declared.
77 dnl Mac OS X 10.3 has frexpl() in libc but doesn't declare it in <math.h>.
78 AC_CHECK_DECL([frexpl], , [HAVE_DECL_FREXPL=0], [[#include <math.h>]])
79 if test $HAVE_DECL_FREXPL = 1; then
80 gl_CHECK_FREXPL_NO_LIBM
81 if test $gl_cv_func_frexpl_no_libm = yes; then
83 case "$gl_cv_func_frexpl_works" in
84 *yes) gl_func_frexpl_no_libm=yes ;;
85 *) gl_func_frexpl_no_libm=no; REPLACE_FREXPL=1 ;;
88 gl_func_frexpl_no_libm=no
89 dnl Set REPLACE_FREXPL here because the system may have frexpl in libm.
92 if test $gl_func_frexpl_no_libm = yes; then
93 AC_DEFINE([HAVE_FREXPL_IN_LIBC], [1],
94 [Define if the frexpl() function is available in libc.])
99 dnl Test whether frexpl() can be used without linking with libm.
100 dnl Set gl_cv_func_frexpl_no_libm to 'yes' or 'no' accordingly.
101 AC_DEFUN([gl_CHECK_FREXPL_NO_LIBM],
103 AC_CACHE_CHECK([whether frexpl() can be used without linking with libm],
104 [gl_cv_func_frexpl_no_libm],
110 [[int e; return frexpl (x, &e) > 0;]])],
111 [gl_cv_func_frexpl_no_libm=yes],
112 [gl_cv_func_frexpl_no_libm=no])
116 dnl Test whether frexpl() works on finite numbers (this fails on
117 dnl Mac OS X 10.4/PowerPC, on AIX 5.1, and on BeOS), on denormalized numbers
118 dnl (this fails on Mac OS X 10.5/i386), and also on infinite numbers (this
119 dnl fails e.g. on IRIX 6.5 and mingw).
120 AC_DEFUN([gl_FUNC_FREXPL_WORKS],
122 AC_REQUIRE([AC_PROG_CC])
123 AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
124 AC_CACHE_CHECK([whether frexpl works], [gl_cv_func_frexpl_works],
130 /* Override the values of <float.h>, like done in float.in.h. */
131 #if defined __i386__ && (defined __BEOS__ || defined __OpenBSD__)
133 # define LDBL_MIN_EXP (-16381)
135 #if defined __i386__ && (defined __FreeBSD__ || defined __DragonFly__)
137 # define LDBL_MIN_EXP (-16381)
139 #if (defined _ARCH_PPC || defined _POWER) && defined _AIX && (LDBL_MANT_DIG == 106) && defined __GNUC__
141 # define LDBL_MIN_EXP DBL_MIN_EXP
143 #if defined __sgi && (LDBL_MANT_DIG >= 106)
144 # if defined __GNUC__
146 # define LDBL_MIN_EXP DBL_MIN_EXP
153 long double frexpl (long double, int *);
154 long double zero = 0.0L;
158 volatile long double x;
159 /* Test on finite numbers that fails on AIX 5.1. */
167 /* Test on finite numbers that fails on Mac OS X 10.4, because its frexpl
168 function returns an invalid (incorrectly normalized) value: it returns
169 y = { 0x3fe028f5, 0xc28f5c28, 0x3c9eb851, 0xeb851eb8 }
170 but the correct result is
171 0.505L = { 0x3fe028f5, 0xc28f5c29, 0xbc547ae1, 0x47ae1480 } */
175 long double y = frexpl (x, &exp);
176 if (!(exp == 1 && y == 0.505L))
179 /* Test on large finite numbers. This fails on BeOS at i = 16322, while
180 LDBL_MAX_EXP = 16384.
181 In the loop end test, we test x against Infinity, rather than comparing
182 i with LDBL_MAX_EXP, because BeOS <float.h> has a wrong LDBL_MAX_EXP. */
185 for (i = 1, x = 1.0L; x != x + x; i++, x *= 2.0L)
196 /* Test on denormalized numbers. */
199 for (i = 1, x = 1.0L; i >= LDBL_MIN_EXP; i--, x *= 0.5L)
204 long double y = frexpl (x, &exp);
205 /* On machines with IEEE854 arithmetic: x = 1.68105e-4932,
206 exp = -16382, y = 0.5. On Mac OS X 10.5: exp = -16384, y = 0.5. */
207 if (exp != LDBL_MIN_EXP - 1)
211 /* Test on infinite numbers. */
212 /* The Microsoft MSVC 14 compiler chokes on the expression 1.0 / 0.0. */
216 long double y = frexpl (x, &exp);
222 [gl_cv_func_frexpl_works=yes],
223 [gl_cv_func_frexpl_works=no],
227 aix | aix[3-6]* | beos* | darwin* | irix* | mingw* | windows* | pw*)
228 gl_cv_func_frexpl_works="guessing no";;
229 *) gl_cv_func_frexpl_works="guessing yes";;