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])
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],
22 [AC_LANG_PROGRAM([[#ifndef __NO_MATH_INLINES
23 # define __NO_MATH_INLINES 1 /* for glibc */
26 double (*funcptr) (double, int) = ldexp;
28 [[return ldexp (x, -1) > 0;]])],
29 [gl_cv_func_ldexp_in_libm=yes],
30 [gl_cv_func_ldexp_in_libm=no])
33 if test $gl_cv_func_ldexp_in_libm = yes; then
39 LIBS="$LIBS $LDEXP_LIBM"
42 case "$gl_cv_func_ldexp_works" in
47 if test $REPLACE_LDEXP = 1; then
48 dnl Find libraries needed to link lib/ldexp.c.
49 LDEXP_LIBM="$ISNAND_LIBM"
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],
62 [AC_LANG_PROGRAM([[#ifndef __NO_MATH_INLINES
63 # define __NO_MATH_INLINES 1 /* for glibc */
66 double (*funcptr) (double, int) = ldexp;
68 [[return ldexp (x, -1) > 0;]])],
69 [gl_cv_func_ldexp_no_libm=yes],
70 [gl_cv_func_ldexp_no_libm=no])
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],
88 volatile double x = 1.9269695883136991774e-308;
89 volatile double y = ldexp (x, 0);
95 [gl_cv_func_ldexp_works=yes],
96 [gl_cv_func_ldexp_works=no],
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" ;;