| 1 |
# ldexp.m4 |
| 2 |
# serial 3 |
| 3 |
dnl Copyright (C) 2010-2025 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_LDEXP], |
| 10 |
[ |
| 11 |
AC_REQUIRE([gl_MATH_H_DEFAULTS]) |
| 12 |
AC_REQUIRE([gl_FUNC_ISNAND]) dnl for ISNAND_LIBM |
| 13 |
|
| 14 |
AC_REQUIRE([gl_CHECK_LDEXP_NO_LIBM]) |
| 15 |
LDEXP_LIBM= |
| 16 |
if test $gl_cv_func_ldexp_no_libm = no; then |
| 17 |
AC_CACHE_CHECK([whether ldexp() can be used with libm], |
| 18 |
[gl_cv_func_ldexp_in_libm], |
| 19 |
[ |
| 20 |
saved_LIBS="$LIBS" |
| 21 |
LIBS="$LIBS -lm" |
| 22 |
AC_LINK_IFELSE( |
| 23 |
[AC_LANG_PROGRAM([[#ifndef __NO_MATH_INLINES |
| 24 |
# define __NO_MATH_INLINES 1 /* for glibc */ |
| 25 |
#endif |
| 26 |
#include <math.h> |
| 27 |
double (*funcptr) (double, int) = ldexp; |
| 28 |
double x;]], |
| 29 |
[[return ldexp (x, -1) > 0;]])], |
| 30 |
[gl_cv_func_ldexp_in_libm=yes], |
| 31 |
[gl_cv_func_ldexp_in_libm=no]) |
| 32 |
LIBS="$saved_LIBS" |
| 33 |
]) |
| 34 |
if test $gl_cv_func_ldexp_in_libm = yes; then |
| 35 |
LDEXP_LIBM=-lm |
| 36 |
fi |
| 37 |
fi |
| 38 |
|
| 39 |
saved_LIBS="$LIBS" |
| 40 |
LIBS="$LIBS $LDEXP_LIBM" |
| 41 |
gl_FUNC_LDEXP_WORKS |
| 42 |
LIBS="$saved_LIBS" |
| 43 |
case "$gl_cv_func_ldexp_works" in |
| 44 |
*yes) ;; |
| 45 |
*) REPLACE_LDEXP=1 ;; |
| 46 |
esac |
| 47 |
|
| 48 |
if test $REPLACE_LDEXP = 1; then |
| 49 |
dnl Find libraries needed to link lib/ldexp.c. |
| 50 |
LDEXP_LIBM="$ISNAND_LIBM" |
| 51 |
fi |
| 52 |
AC_SUBST([LDEXP_LIBM]) |
| 53 |
]) |
| 54 |
|
| 55 |
dnl Test whether ldexp() can be used without linking with libm. |
| 56 |
dnl Set gl_cv_func_ldexp_no_libm to 'yes' or 'no' accordingly. |
| 57 |
AC_DEFUN([gl_CHECK_LDEXP_NO_LIBM], |
| 58 |
[ |
| 59 |
AC_CACHE_CHECK([whether ldexp() can be used without linking with libm], |
| 60 |
[gl_cv_func_ldexp_no_libm], |
| 61 |
[ |
| 62 |
AC_LINK_IFELSE( |
| 63 |
[AC_LANG_PROGRAM([[#ifndef __NO_MATH_INLINES |
| 64 |
# define __NO_MATH_INLINES 1 /* for glibc */ |
| 65 |
#endif |
| 66 |
#include <math.h> |
| 67 |
double (*funcptr) (double, int) = ldexp; |
| 68 |
double x;]], |
| 69 |
[[return ldexp (x, -1) > 0;]])], |
| 70 |
[gl_cv_func_ldexp_no_libm=yes], |
| 71 |
[gl_cv_func_ldexp_no_libm=no]) |
| 72 |
]) |
| 73 |
]) |
| 74 |
|
| 75 |
dnl Test whether ldexp() works (this fails on OpenBSD 7.3/mips64). |
| 76 |
AC_DEFUN([gl_FUNC_LDEXP_WORKS], |
| 77 |
[ |
| 78 |
AC_REQUIRE([AC_PROG_CC]) |
| 79 |
AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles |
| 80 |
AC_CACHE_CHECK([whether ldexp works], [gl_cv_func_ldexp_works], |
| 81 |
[ |
| 82 |
AC_RUN_IFELSE( |
| 83 |
[AC_LANG_SOURCE([[ |
| 84 |
#include <math.h> |
| 85 |
int main() |
| 86 |
{ |
| 87 |
int result = 0; |
| 88 |
{ |
| 89 |
volatile double x = 1.9269695883136991774e-308; |
| 90 |
volatile double y = ldexp (x, 0); |
| 91 |
if (y != x) |
| 92 |
result |= 1; |
| 93 |
} |
| 94 |
return result; |
| 95 |
}]])], |
| 96 |
[gl_cv_func_ldexp_works=yes], |
| 97 |
[gl_cv_func_ldexp_works=no], |
| 98 |
[case "$host_os" in |
| 99 |
openbsd*) gl_cv_func_ldexp_works="guessing no" ;; |
| 100 |
# Guess yes on native Windows. |
| 101 |
mingw* | windows*) gl_cv_func_ldexp_works="guessing yes" ;; |
| 102 |
*) gl_cv_func_ldexp_works="guessing yes" ;; |
| 103 |
esac |
| 104 |
]) |
| 105 |
]) |
| 106 |
]) |