Debian Codegraph @

m4/ldexpl.m4

raw
1 # ldexpl.m4
2 # serial 19
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_LDEXPL],
10 [
11 AC_REQUIRE([gl_MATH_H_DEFAULTS])
12 AC_REQUIRE([gl_LONG_DOUBLE_VS_DOUBLE])
13 AC_REQUIRE([gl_FUNC_ISNANL]) dnl for ISNANL_LIBM
14
15 dnl Persuade glibc <math.h> to declare ldexpl().
16 AC_REQUIRE([gl_USE_SYSTEM_EXTENSIONS])
17
18 dnl Check whether it's declared.
19 dnl Mac OS X 10.3 has ldexpl() in libc but doesn't declare it in <math.h>.
20 AC_CHECK_DECL([ldexpl], , [HAVE_DECL_LDEXPL=0], [[#include <math.h>]])
21
22 LDEXPL_LIBM=
23 if test $HAVE_DECL_LDEXPL = 1; then
24 gl_CHECK_LDEXPL_NO_LIBM
25 if test $gl_cv_func_ldexpl_no_libm = no; then
26 AC_CACHE_CHECK([whether ldexpl() can be used with libm],
27 [gl_cv_func_ldexpl_in_libm],
28 [
29 saved_LIBS="$LIBS"
30 LIBS="$LIBS -lm"
31 AC_LINK_IFELSE(
32 [AC_LANG_PROGRAM(
33 [[#include <math.h>
34 long double x;]],
35 [[return ldexpl (x, -1) > 0;]])],
36 [gl_cv_func_ldexpl_in_libm=yes],
37 [gl_cv_func_ldexpl_in_libm=no])
38 LIBS="$saved_LIBS"
39 ])
40 if test $gl_cv_func_ldexpl_in_libm = yes; then
41 LDEXPL_LIBM=-lm
42 fi
43 fi
44 if test $gl_cv_func_ldexpl_no_libm = yes \
45 || test $gl_cv_func_ldexpl_in_libm = yes; then
46 saved_LIBS="$LIBS"
47 LIBS="$LIBS $LDEXPL_LIBM"
48 gl_FUNC_LDEXPL_WORKS
49 LIBS="$saved_LIBS"
50 case "$gl_cv_func_ldexpl_works" in
51 *yes) gl_func_ldexpl=yes ;;
52 *) gl_func_ldexpl=no; REPLACE_LDEXPL=1 ;;
53 esac
54 else
55 gl_func_ldexpl=no
56 fi
57 if test $gl_func_ldexpl = yes; then
58 AC_DEFINE([HAVE_LDEXPL], [1],
59 [Define if the ldexpl() function is available.])
60 fi
61 fi
62 if test $HAVE_DECL_LDEXPL = 0 || test $gl_func_ldexpl = no; then
63 dnl Find libraries needed to link lib/ldexpl.c.
64 if test $HAVE_SAME_LONG_DOUBLE_AS_DOUBLE = 1; then
65 AC_REQUIRE([gl_FUNC_LDEXP])
66 LDEXPL_LIBM="$LDEXP_LIBM"
67 else
68 LDEXPL_LIBM="$ISNANL_LIBM"
69 fi
70 fi
71 AC_SUBST([LDEXPL_LIBM])
72 ])
73
74 dnl Test whether ldexpl() can be used without linking with libm.
75 dnl Set gl_cv_func_ldexpl_no_libm to 'yes' or 'no' accordingly.
76 AC_DEFUN([gl_CHECK_LDEXPL_NO_LIBM],
77 [
78 AC_CACHE_CHECK([whether ldexpl() can be used without linking with libm],
79 [gl_cv_func_ldexpl_no_libm],
80 [
81 AC_LINK_IFELSE(
82 [AC_LANG_PROGRAM(
83 [[#include <math.h>
84 long double x;]],
85 [[return ldexpl (x, -1) > 0;]])],
86 [gl_cv_func_ldexpl_no_libm=yes],
87 [gl_cv_func_ldexpl_no_libm=no])
88 ])
89 ])
90
91 dnl Test whether ldexpl() works on finite numbers (this fails on AIX 5.1
92 dnl and Mac OS X 10.4/PowerPC).
93 AC_DEFUN([gl_FUNC_LDEXPL_WORKS],
94 [
95 AC_REQUIRE([AC_PROG_CC])
96 AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
97 AC_CACHE_CHECK([whether ldexpl works], [gl_cv_func_ldexpl_works],
98 [
99 AC_RUN_IFELSE(
100 [AC_LANG_SOURCE([[
101 #include <math.h>
102 extern
103 #ifdef __cplusplus
104 "C"
105 #endif
106 long double ldexpl (long double, int);
107 int main()
108 {
109 int result = 0;
110 {
111 volatile long double x = 1.0;
112 volatile long double y = ldexpl (x, -1);
113 if (y != 0.5L)
114 result |= 1;
115 }
116 {
117 volatile long double x = 1.73205L;
118 volatile long double y = ldexpl (x, 0);
119 if (y != x)
120 result |= 2;
121 }
122 return result;
123 }]])],
124 [gl_cv_func_ldexpl_works=yes],
125 [gl_cv_func_ldexpl_works=no],
126 [
127 changequote(,)dnl
128 case "$host_os" in
129 aix | aix[3-6]*) gl_cv_func_ldexpl_works="guessing no" ;;
130 # Guess yes on native Windows.
131 mingw* | windows*) gl_cv_func_ldexpl_works="guessing yes" ;;
132 *) gl_cv_func_ldexpl_works="guessing yes" ;;
133 esac
134 changequote([,])dnl
135 ])
136 ])
137 ])