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