| 1 |
# frexp.m4 |
| 2 |
# serial 21 |
| 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_FREXP], |
| 10 |
[ |
| 11 |
AC_REQUIRE([gl_MATH_H_DEFAULTS]) |
| 12 |
AC_REQUIRE([gl_CHECK_FREXP_NO_LIBM]) |
| 13 |
FREXP_LIBM= |
| 14 |
if test $gl_cv_func_frexp_no_libm = no; then |
| 15 |
AC_CACHE_CHECK([whether frexp() can be used with libm], |
| 16 |
[gl_cv_func_frexp_in_libm], |
| 17 |
[ |
| 18 |
saved_LIBS="$LIBS" |
| 19 |
LIBS="$LIBS -lm" |
| 20 |
AC_LINK_IFELSE( |
| 21 |
[AC_LANG_PROGRAM( |
| 22 |
[[#include <math.h> |
| 23 |
double x;]], |
| 24 |
[[int e; return frexp (x, &e) > 0;]])], |
| 25 |
[gl_cv_func_frexp_in_libm=yes], |
| 26 |
[gl_cv_func_frexp_in_libm=no]) |
| 27 |
LIBS="$saved_LIBS" |
| 28 |
]) |
| 29 |
if test $gl_cv_func_frexp_in_libm = yes; then |
| 30 |
FREXP_LIBM=-lm |
| 31 |
fi |
| 32 |
fi |
| 33 |
if test $gl_cv_func_frexp_no_libm = yes \ |
| 34 |
|| test $gl_cv_func_frexp_in_libm = yes; then |
| 35 |
saved_LIBS="$LIBS" |
| 36 |
LIBS="$LIBS $FREXP_LIBM" |
| 37 |
gl_FUNC_FREXP_WORKS |
| 38 |
LIBS="$saved_LIBS" |
| 39 |
case "$gl_cv_func_frexp_works" in |
| 40 |
*yes) gl_func_frexp=yes ;; |
| 41 |
*) gl_func_frexp=no; REPLACE_FREXP=1; FREXP_LIBM= ;; |
| 42 |
esac |
| 43 |
else |
| 44 |
gl_func_frexp=no |
| 45 |
fi |
| 46 |
if test $gl_func_frexp = yes; then |
| 47 |
AC_DEFINE([HAVE_FREXP], [1], |
| 48 |
[Define if the frexp() function is available and works.]) |
| 49 |
fi |
| 50 |
AC_SUBST([FREXP_LIBM]) |
| 51 |
]) |
| 52 |
|
| 53 |
AC_DEFUN([gl_FUNC_FREXP_NO_LIBM], |
| 54 |
[ |
| 55 |
AC_REQUIRE([gl_MATH_H_DEFAULTS]) |
| 56 |
AC_REQUIRE([gl_CHECK_FREXP_NO_LIBM]) |
| 57 |
if test $gl_cv_func_frexp_no_libm = yes; then |
| 58 |
gl_FUNC_FREXP_WORKS |
| 59 |
case "$gl_cv_func_frexp_works" in |
| 60 |
*yes) gl_func_frexp_no_libm=yes ;; |
| 61 |
*) gl_func_frexp_no_libm=no; REPLACE_FREXP=1 ;; |
| 62 |
esac |
| 63 |
else |
| 64 |
gl_func_frexp_no_libm=no |
| 65 |
dnl Set REPLACE_FREXP here because the system may have frexp in libm. |
| 66 |
REPLACE_FREXP=1 |
| 67 |
fi |
| 68 |
if test $gl_func_frexp_no_libm = yes; then |
| 69 |
AC_DEFINE([HAVE_FREXP_IN_LIBC], [1], |
| 70 |
[Define if the frexp() function is available in libc.]) |
| 71 |
fi |
| 72 |
]) |
| 73 |
|
| 74 |
dnl Test whether frexp() can be used without linking with libm. |
| 75 |
dnl Set gl_cv_func_frexp_no_libm to 'yes' or 'no' accordingly. |
| 76 |
AC_DEFUN([gl_CHECK_FREXP_NO_LIBM], |
| 77 |
[ |
| 78 |
AC_CACHE_CHECK([whether frexp() can be used without linking with libm], |
| 79 |
[gl_cv_func_frexp_no_libm], |
| 80 |
[ |
| 81 |
AC_LINK_IFELSE( |
| 82 |
[AC_LANG_PROGRAM( |
| 83 |
[[#include <math.h> |
| 84 |
double x;]], |
| 85 |
[[int e; return frexp (x, &e) > 0;]])], |
| 86 |
[gl_cv_func_frexp_no_libm=yes], |
| 87 |
[gl_cv_func_frexp_no_libm=no]) |
| 88 |
]) |
| 89 |
]) |
| 90 |
|
| 91 |
dnl Test whether frexp() works also on denormalized numbers (this fails e.g. on |
| 92 |
dnl NetBSD 3.0), on infinite numbers (this fails e.g. on mingw), and on negative |
| 93 |
dnl zero (this fails e.g. on NetBSD 4.99 and mingw). |
| 94 |
AC_DEFUN([gl_FUNC_FREXP_WORKS], |
| 95 |
[ |
| 96 |
AC_REQUIRE([AC_PROG_CC]) |
| 97 |
AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles |
| 98 |
AC_CHECK_DECLS_ONCE([alarm]) |
| 99 |
AC_CACHE_CHECK([whether frexp works], [gl_cv_func_frexp_works], |
| 100 |
[ |
| 101 |
AC_RUN_IFELSE( |
| 102 |
[AC_LANG_SOURCE([[ |
| 103 |
#include <float.h> |
| 104 |
#include <math.h> |
| 105 |
#include <string.h> |
| 106 |
#if HAVE_DECL_ALARM |
| 107 |
# include <signal.h> |
| 108 |
# include <unistd.h> |
| 109 |
#endif |
| 110 |
/* HP cc on HP-UX 10.20 has a bug with the constant expression -0.0. |
| 111 |
ICC 10.0 has a bug when optimizing the expression -zero. |
| 112 |
The expression -DBL_MIN * DBL_MIN does not work when cross-compiling |
| 113 |
to PowerPC on Mac OS X 10.5. */ |
| 114 |
#if defined __hpux || defined __ICC |
| 115 |
static double |
| 116 |
compute_minus_zero (void) |
| 117 |
{ |
| 118 |
return -DBL_MIN * DBL_MIN; |
| 119 |
} |
| 120 |
# define minus_zero compute_minus_zero () |
| 121 |
#else |
| 122 |
double minus_zero = -0.0; |
| 123 |
#endif |
| 124 |
int main() |
| 125 |
{ |
| 126 |
int result = 0; |
| 127 |
int i; |
| 128 |
volatile double x; |
| 129 |
double zero = 0.0; |
| 130 |
#if HAVE_DECL_ALARM |
| 131 |
/* NeXTstep 3.3 frexp() runs into an endless loop when called on an infinite |
| 132 |
number. Let the test fail in this case. */ |
| 133 |
signal (SIGALRM, SIG_DFL); |
| 134 |
alarm (5); |
| 135 |
#endif |
| 136 |
/* Test on denormalized numbers. */ |
| 137 |
for (i = 1, x = 1.0; i >= DBL_MIN_EXP; i--, x *= 0.5) |
| 138 |
; |
| 139 |
if (x > 0.0) |
| 140 |
{ |
| 141 |
int exp; |
| 142 |
double y = frexp (x, &exp); |
| 143 |
/* On machines with IEEE754 arithmetic: x = 1.11254e-308, exp = -1022. |
| 144 |
On NetBSD: y = 0.75. Correct: y = 0.5. */ |
| 145 |
if (y != 0.5) |
| 146 |
result |= 1; |
| 147 |
} |
| 148 |
/* Test on infinite numbers. */ |
| 149 |
x = 1.0 / zero; |
| 150 |
{ |
| 151 |
int exp; |
| 152 |
double y = frexp (x, &exp); |
| 153 |
if (y != x) |
| 154 |
result |= 2; |
| 155 |
} |
| 156 |
/* Test on negative zero. */ |
| 157 |
x = minus_zero; |
| 158 |
{ |
| 159 |
int exp; |
| 160 |
double y = frexp (x, &exp); |
| 161 |
double x1 = x; |
| 162 |
if (memcmp (&y, &x1, sizeof x1)) |
| 163 |
result |= 4; |
| 164 |
} |
| 165 |
return result; |
| 166 |
}]])], |
| 167 |
[gl_cv_func_frexp_works=yes], |
| 168 |
[gl_cv_func_frexp_works=no], |
| 169 |
[case "$host_os" in |
| 170 |
netbsd*) gl_cv_func_frexp_works="guessing no" ;; |
| 171 |
# Guess yes with MSVC, no with mingw. |
| 172 |
windows*-msvc*) |
| 173 |
gl_cv_func_frexp_works="guessing yes" |
| 174 |
;; |
| 175 |
mingw* | windows*) |
| 176 |
AC_EGREP_CPP([Good], [ |
| 177 |
#ifdef _MSC_VER |
| 178 |
Good |
| 179 |
#endif |
| 180 |
], |
| 181 |
[gl_cv_func_frexp_works="guessing yes"], |
| 182 |
[gl_cv_func_frexp_works="guessing no"]) |
| 183 |
;; |
| 184 |
*) gl_cv_func_frexp_works="guessing yes" ;; |
| 185 |
esac |
| 186 |
]) |
| 187 |
]) |
| 188 |
]) |