| 1 |
# frexpl.m4 |
| 2 |
# serial 25 |
| 3 |
dnl Copyright (C) 2007-2026 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. |
| 7 |
dnl This file is offered as-is, without any warranty. |
| 8 |
|
| 9 |
AC_DEFUN([gl_FUNC_FREXPL], |
| 10 |
[ |
| 11 |
AC_REQUIRE([gl_MATH_H_DEFAULTS]) |
| 12 |
AC_REQUIRE([gl_LONG_DOUBLE_VS_DOUBLE]) |
| 13 |
|
| 14 |
dnl Persuade glibc <math.h> to declare frexpl(). |
| 15 |
AC_REQUIRE([gl_USE_SYSTEM_EXTENSIONS]) |
| 16 |
|
| 17 |
dnl Check whether it's declared. |
| 18 |
dnl Mac OS X 10.3 has frexpl() in libc but doesn't declare it in <math.h>. |
| 19 |
AC_CHECK_DECL([frexpl], , [HAVE_DECL_FREXPL=0], [[#include <math.h>]]) |
| 20 |
|
| 21 |
FREXPL_LIBM= |
| 22 |
if test $HAVE_DECL_FREXPL = 1; then |
| 23 |
gl_CHECK_FREXPL_NO_LIBM |
| 24 |
if test $gl_cv_func_frexpl_no_libm = no; then |
| 25 |
AC_CACHE_CHECK([whether frexpl() can be used with libm], |
| 26 |
[gl_cv_func_frexpl_in_libm], |
| 27 |
[ |
| 28 |
saved_LIBS="$LIBS" |
| 29 |
LIBS="$LIBS -lm" |
| 30 |
AC_LINK_IFELSE( |
| 31 |
[AC_LANG_PROGRAM( |
| 32 |
[[#include <math.h> |
| 33 |
long double x;]], |
| 34 |
[[int e; return frexpl (x, &e) > 0;]])], |
| 35 |
[gl_cv_func_frexpl_in_libm=yes], |
| 36 |
[gl_cv_func_frexpl_in_libm=no]) |
| 37 |
LIBS="$saved_LIBS" |
| 38 |
]) |
| 39 |
if test $gl_cv_func_frexpl_in_libm = yes; then |
| 40 |
FREXPL_LIBM=-lm |
| 41 |
fi |
| 42 |
fi |
| 43 |
if test $gl_cv_func_frexpl_no_libm = yes \ |
| 44 |
|| test $gl_cv_func_frexpl_in_libm = yes; then |
| 45 |
saved_LIBS="$LIBS" |
| 46 |
LIBS="$LIBS $FREXPL_LIBM" |
| 47 |
gl_FUNC_FREXPL_WORKS |
| 48 |
LIBS="$saved_LIBS" |
| 49 |
case "$gl_cv_func_frexpl_works" in |
| 50 |
*yes) gl_func_frexpl=yes ;; |
| 51 |
*) gl_func_frexpl=no; REPLACE_FREXPL=1 ;; |
| 52 |
esac |
| 53 |
else |
| 54 |
gl_func_frexpl=no |
| 55 |
fi |
| 56 |
if test $gl_func_frexpl = yes; then |
| 57 |
AC_DEFINE([HAVE_FREXPL], [1], |
| 58 |
[Define if the frexpl() function is available.]) |
| 59 |
fi |
| 60 |
fi |
| 61 |
if test $HAVE_DECL_FREXPL = 0 || test $gl_func_frexpl = no; then |
| 62 |
dnl Find libraries needed to link lib/frexpl.c. |
| 63 |
if test $HAVE_SAME_LONG_DOUBLE_AS_DOUBLE = 1; then |
| 64 |
AC_REQUIRE([gl_FUNC_FREXP]) |
| 65 |
FREXPL_LIBM="$FREXP_LIBM" |
| 66 |
else |
| 67 |
FREXPL_LIBM= |
| 68 |
fi |
| 69 |
fi |
| 70 |
AC_SUBST([FREXPL_LIBM]) |
| 71 |
]) |
| 72 |
|
| 73 |
AC_DEFUN([gl_FUNC_FREXPL_NO_LIBM], |
| 74 |
[ |
| 75 |
AC_REQUIRE([gl_MATH_H_DEFAULTS]) |
| 76 |
AC_REQUIRE([gl_LONG_DOUBLE_VS_DOUBLE]) |
| 77 |
dnl Check whether it's declared. |
| 78 |
dnl Mac OS X 10.3 has frexpl() in libc but doesn't declare it in <math.h>. |
| 79 |
AC_CHECK_DECL([frexpl], , [HAVE_DECL_FREXPL=0], [[#include <math.h>]]) |
| 80 |
if test $HAVE_DECL_FREXPL = 1; then |
| 81 |
gl_CHECK_FREXPL_NO_LIBM |
| 82 |
if test $gl_cv_func_frexpl_no_libm = yes; then |
| 83 |
gl_FUNC_FREXPL_WORKS |
| 84 |
case "$gl_cv_func_frexpl_works" in |
| 85 |
*yes) gl_func_frexpl_no_libm=yes ;; |
| 86 |
*) gl_func_frexpl_no_libm=no; REPLACE_FREXPL=1 ;; |
| 87 |
esac |
| 88 |
else |
| 89 |
gl_func_frexpl_no_libm=no |
| 90 |
dnl Set REPLACE_FREXPL here because the system may have frexpl in libm. |
| 91 |
REPLACE_FREXPL=1 |
| 92 |
fi |
| 93 |
if test $gl_func_frexpl_no_libm = yes; then |
| 94 |
AC_DEFINE([HAVE_FREXPL_IN_LIBC], [1], |
| 95 |
[Define if the frexpl() function is available in libc.]) |
| 96 |
fi |
| 97 |
fi |
| 98 |
]) |
| 99 |
|
| 100 |
dnl Test whether frexpl() can be used without linking with libm. |
| 101 |
dnl Set gl_cv_func_frexpl_no_libm to 'yes' or 'no' accordingly. |
| 102 |
AC_DEFUN([gl_CHECK_FREXPL_NO_LIBM], |
| 103 |
[ |
| 104 |
AC_CACHE_CHECK([whether frexpl() can be used without linking with libm], |
| 105 |
[gl_cv_func_frexpl_no_libm], |
| 106 |
[ |
| 107 |
AC_LINK_IFELSE( |
| 108 |
[AC_LANG_PROGRAM( |
| 109 |
[[#include <math.h> |
| 110 |
long double x;]], |
| 111 |
[[int e; return frexpl (x, &e) > 0;]])], |
| 112 |
[gl_cv_func_frexpl_no_libm=yes], |
| 113 |
[gl_cv_func_frexpl_no_libm=no]) |
| 114 |
]) |
| 115 |
]) |
| 116 |
|
| 117 |
dnl Test whether frexpl() works on finite numbers (this fails on |
| 118 |
dnl Mac OS X 10.4/PowerPC, on AIX 5.1, and on BeOS), on denormalized numbers |
| 119 |
dnl (this fails on Mac OS X 10.5/i386), and also on infinite numbers (this |
| 120 |
dnl fails e.g. on mingw). |
| 121 |
AC_DEFUN([gl_FUNC_FREXPL_WORKS], |
| 122 |
[ |
| 123 |
AC_REQUIRE([AC_PROG_CC]) |
| 124 |
AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles |
| 125 |
AC_CACHE_CHECK([whether frexpl works], [gl_cv_func_frexpl_works], |
| 126 |
[ |
| 127 |
AC_RUN_IFELSE( |
| 128 |
[AC_LANG_SOURCE([[ |
| 129 |
#include <float.h> |
| 130 |
#include <math.h> |
| 131 |
/* Override the values of <float.h>, like done in float.in.h. */ |
| 132 |
#if defined __i386__ && (defined __BEOS__ || defined __OpenBSD__) |
| 133 |
# undef LDBL_MIN_EXP |
| 134 |
# define LDBL_MIN_EXP (-16381) |
| 135 |
#endif |
| 136 |
#if defined __i386__ && (defined __FreeBSD__ || defined __DragonFly__) |
| 137 |
# undef LDBL_MIN_EXP |
| 138 |
# define LDBL_MIN_EXP (-16381) |
| 139 |
#endif |
| 140 |
#if (defined _ARCH_PPC || defined _POWER) && defined _AIX && (LDBL_MANT_DIG == 106) && defined __GNUC__ |
| 141 |
# undef LDBL_MIN_EXP |
| 142 |
# define LDBL_MIN_EXP DBL_MIN_EXP |
| 143 |
#endif |
| 144 |
extern |
| 145 |
#ifdef __cplusplus |
| 146 |
"C" |
| 147 |
#endif |
| 148 |
long double frexpl (long double, int *); |
| 149 |
long double zero = 0.0L; |
| 150 |
int main() |
| 151 |
{ |
| 152 |
int result = 0; |
| 153 |
volatile long double x; |
| 154 |
/* Test on finite numbers that fails on AIX 5.1. */ |
| 155 |
x = 16.0L; |
| 156 |
{ |
| 157 |
int exp = -9999; |
| 158 |
frexpl (x, &exp); |
| 159 |
if (exp != 5) |
| 160 |
result |= 1; |
| 161 |
} |
| 162 |
/* Test on finite numbers that fails on Mac OS X 10.4, because its frexpl |
| 163 |
function returns an invalid (incorrectly normalized) value: it returns |
| 164 |
y = { 0x3fe028f5, 0xc28f5c28, 0x3c9eb851, 0xeb851eb8 } |
| 165 |
but the correct result is |
| 166 |
0.505L = { 0x3fe028f5, 0xc28f5c29, 0xbc547ae1, 0x47ae1480 } */ |
| 167 |
x = 1.01L; |
| 168 |
{ |
| 169 |
int exp = -9999; |
| 170 |
long double y = frexpl (x, &exp); |
| 171 |
if (!(exp == 1 && y == 0.505L)) |
| 172 |
result |= 2; |
| 173 |
} |
| 174 |
/* Test on large finite numbers. This fails on BeOS at i = 16322, while |
| 175 |
LDBL_MAX_EXP = 16384. |
| 176 |
In the loop end test, we test x against Infinity, rather than comparing |
| 177 |
i with LDBL_MAX_EXP, because BeOS <float.h> has a wrong LDBL_MAX_EXP. */ |
| 178 |
{ |
| 179 |
int i; |
| 180 |
for (i = 1, x = 1.0L; x != x + x; i++, x *= 2.0L) |
| 181 |
{ |
| 182 |
int exp = -9999; |
| 183 |
frexpl (x, &exp); |
| 184 |
if (exp != i) |
| 185 |
{ |
| 186 |
result |= 4; |
| 187 |
break; |
| 188 |
} |
| 189 |
} |
| 190 |
} |
| 191 |
/* Test on denormalized numbers. */ |
| 192 |
{ |
| 193 |
int i; |
| 194 |
for (i = 1, x = 1.0L; i >= LDBL_MIN_EXP; i--, x *= 0.5L) |
| 195 |
; |
| 196 |
if (x > 0.0L) |
| 197 |
{ |
| 198 |
int exp; |
| 199 |
long double y = frexpl (x, &exp); |
| 200 |
/* On machines with IEEE854 arithmetic: x = 1.68105e-4932, |
| 201 |
exp = -16382, y = 0.5. On Mac OS X 10.5: exp = -16384, y = 0.5. */ |
| 202 |
if (exp != LDBL_MIN_EXP - 1) |
| 203 |
result |= 8; |
| 204 |
} |
| 205 |
} |
| 206 |
/* Test on infinite numbers. */ |
| 207 |
/* The Microsoft MSVC 14 compiler chokes on the expression 1.0 / 0.0. */ |
| 208 |
x = 1.0L / zero; |
| 209 |
{ |
| 210 |
int exp; |
| 211 |
long double y = frexpl (x, &exp); |
| 212 |
if (y != x) |
| 213 |
result |= 16; |
| 214 |
} |
| 215 |
return result; |
| 216 |
}]])], |
| 217 |
[gl_cv_func_frexpl_works=yes], |
| 218 |
[gl_cv_func_frexpl_works=no], |
| 219 |
[ |
| 220 |
changequote(,)dnl |
| 221 |
case "$host_os" in |
| 222 |
aix | aix[3-6]* | beos* | darwin* | mingw* | windows* | pw*) |
| 223 |
gl_cv_func_frexpl_works="guessing no";; |
| 224 |
*) gl_cv_func_frexpl_works="guessing yes";; |
| 225 |
esac |
| 226 |
changequote([,])dnl |
| 227 |
]) |
| 228 |
]) |
| 229 |
]) |