| 1 |
# sqrtl.m4 |
| 2 |
# serial 13 |
| 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_SQRTL], |
| 10 |
[ |
| 11 |
AC_REQUIRE([gl_MATH_H_DEFAULTS]) |
| 12 |
AC_REQUIRE([gl_LONG_DOUBLE_VS_DOUBLE]) |
| 13 |
|
| 14 |
dnl Persuade glibc <math.h> to declare sqrtl(). |
| 15 |
AC_REQUIRE([gl_USE_SYSTEM_EXTENSIONS]) |
| 16 |
|
| 17 |
SQRTL_LIBM= |
| 18 |
AC_CACHE_CHECK([whether sqrtl() can be used without linking with libm], |
| 19 |
[gl_cv_func_sqrtl_no_libm], |
| 20 |
[ |
| 21 |
AC_LINK_IFELSE( |
| 22 |
[AC_LANG_PROGRAM( |
| 23 |
[[#ifndef __NO_MATH_INLINES |
| 24 |
# define __NO_MATH_INLINES 1 /* for glibc */ |
| 25 |
#endif |
| 26 |
#include <math.h> |
| 27 |
long double (* volatile funcptr) (long double) = sqrtl; |
| 28 |
long double x;]], |
| 29 |
[[return funcptr (x) > 0.4 |
| 30 |
|| sqrtl (x) > 0.4;]])], |
| 31 |
[gl_cv_func_sqrtl_no_libm=yes], |
| 32 |
[gl_cv_func_sqrtl_no_libm=no]) |
| 33 |
]) |
| 34 |
if test $gl_cv_func_sqrtl_no_libm = no; then |
| 35 |
AC_CACHE_CHECK([whether sqrtl() can be used with libm], |
| 36 |
[gl_cv_func_sqrtl_in_libm], |
| 37 |
[ |
| 38 |
saved_LIBS="$LIBS" |
| 39 |
LIBS="$LIBS -lm" |
| 40 |
AC_LINK_IFELSE( |
| 41 |
[AC_LANG_PROGRAM( |
| 42 |
[[#ifndef __NO_MATH_INLINES |
| 43 |
# define __NO_MATH_INLINES 1 /* for glibc */ |
| 44 |
#endif |
| 45 |
#include <math.h> |
| 46 |
long double (* volatile funcptr) (long double) = sqrtl; |
| 47 |
long double x;]], |
| 48 |
[[return funcptr (x) > 0.4 |
| 49 |
|| sqrtl (x) > 0.4;]])], |
| 50 |
[gl_cv_func_sqrtl_in_libm=yes], |
| 51 |
[gl_cv_func_sqrtl_in_libm=no]) |
| 52 |
LIBS="$saved_LIBS" |
| 53 |
]) |
| 54 |
if test $gl_cv_func_sqrtl_in_libm = yes; then |
| 55 |
SQRTL_LIBM=-lm |
| 56 |
fi |
| 57 |
fi |
| 58 |
if test $gl_cv_func_sqrtl_no_libm = yes \ |
| 59 |
|| test $gl_cv_func_sqrtl_in_libm = yes; then |
| 60 |
dnl Also check whether it's declared. |
| 61 |
dnl Mac OS X 10.3 has sqrtl() in libc but doesn't declare it in <math.h>. |
| 62 |
AC_CHECK_DECL([sqrtl], , [HAVE_DECL_SQRTL=0], [[#include <math.h>]]) |
| 63 |
|
| 64 |
saved_LIBS="$LIBS" |
| 65 |
LIBS="$LIBS $SQRTL_LIBM" |
| 66 |
gl_FUNC_SQRTL_WORKS |
| 67 |
LIBS="$saved_LIBS" |
| 68 |
case "$gl_cv_func_sqrtl_works" in |
| 69 |
*yes) ;; |
| 70 |
*) REPLACE_SQRTL=1 ;; |
| 71 |
esac |
| 72 |
else |
| 73 |
HAVE_DECL_SQRTL=0 |
| 74 |
HAVE_SQRTL=0 |
| 75 |
fi |
| 76 |
if test $HAVE_SQRTL = 0 || test $REPLACE_SQRTL = 1; then |
| 77 |
dnl Find libraries needed to link lib/sqrtl.c. |
| 78 |
if test $HAVE_SAME_LONG_DOUBLE_AS_DOUBLE = 1; then |
| 79 |
AC_REQUIRE([gl_FUNC_SQRT]) |
| 80 |
SQRTL_LIBM="$SQRT_LIBM" |
| 81 |
else |
| 82 |
AC_REQUIRE([gl_FUNC_ISNANL]) |
| 83 |
AC_REQUIRE([gl_FUNC_FREXPL]) |
| 84 |
AC_REQUIRE([gl_FUNC_LDEXPL]) |
| 85 |
AC_REQUIRE([gl_FUNC_SQRT]) |
| 86 |
dnl Append $ISNANL_LIBM to SQRTL_LIBM, avoiding gratuitous duplicates. |
| 87 |
case " $SQRTL_LIBM " in |
| 88 |
*" $ISNANL_LIBM "*) ;; |
| 89 |
*) SQRTL_LIBM="$SQRTL_LIBM $ISNANL_LIBM" ;; |
| 90 |
esac |
| 91 |
dnl Append $FREXPL_LIBM to SQRTL_LIBM, avoiding gratuitous duplicates. |
| 92 |
case " $SQRTL_LIBM " in |
| 93 |
*" $FREXPL_LIBM "*) ;; |
| 94 |
*) SQRTL_LIBM="$SQRTL_LIBM $FREXPL_LIBM" ;; |
| 95 |
esac |
| 96 |
dnl Append $LDEXPL_LIBM to SQRTL_LIBM, avoiding gratuitous duplicates. |
| 97 |
case " $SQRTL_LIBM " in |
| 98 |
*" $LDEXPL_LIBM "*) ;; |
| 99 |
*) SQRTL_LIBM="$SQRTL_LIBM $LDEXPL_LIBM" ;; |
| 100 |
esac |
| 101 |
dnl Append $SQRT_LIBM to SQRTL_LIBM, avoiding gratuitous duplicates. |
| 102 |
case " $SQRTL_LIBM " in |
| 103 |
*" $SQRT_LIBM "*) ;; |
| 104 |
*) SQRTL_LIBM="$SQRTL_LIBM $SQRT_LIBM" ;; |
| 105 |
esac |
| 106 |
fi |
| 107 |
fi |
| 108 |
AC_SUBST([SQRTL_LIBM]) |
| 109 |
]) |
| 110 |
|
| 111 |
dnl Test whether sqrtl() works. |
| 112 |
dnl On OpenBSD 5.1/SPARC, sqrtl(8.1974099812331540680810141969554806865L) has |
| 113 |
dnl rounding errors that eat up the last 8 to 9 decimal digits. |
| 114 |
AC_DEFUN([gl_FUNC_SQRTL_WORKS], |
| 115 |
[ |
| 116 |
AC_REQUIRE([AC_PROG_CC]) |
| 117 |
AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles |
| 118 |
AC_CACHE_CHECK([whether sqrtl works], [gl_cv_func_sqrtl_works], |
| 119 |
[ |
| 120 |
AC_RUN_IFELSE( |
| 121 |
[AC_LANG_SOURCE([[ |
| 122 |
#include <float.h> |
| 123 |
#include <math.h> |
| 124 |
#ifndef sqrtl /* for AIX */ |
| 125 |
extern |
| 126 |
#ifdef __cplusplus |
| 127 |
"C" |
| 128 |
#endif |
| 129 |
long double sqrtl (long double); |
| 130 |
#endif |
| 131 |
static long double |
| 132 |
my_ldexpl (long double x, int d) |
| 133 |
{ |
| 134 |
for (; d > 0; d--) |
| 135 |
x *= 2.0L; |
| 136 |
for (; d < 0; d++) |
| 137 |
x *= 0.5L; |
| 138 |
return x; |
| 139 |
} |
| 140 |
volatile long double x; |
| 141 |
volatile long double y; |
| 142 |
long double z; |
| 143 |
int main () |
| 144 |
{ |
| 145 |
x = 8.1974099812331540680810141969554806865L; |
| 146 |
y = sqrtl (x); |
| 147 |
z = y * y - x; |
| 148 |
z = my_ldexpl (z, LDBL_MANT_DIG); |
| 149 |
if (z < 0) |
| 150 |
z = - z; |
| 151 |
if (z > 100.0L) |
| 152 |
return 1; |
| 153 |
return 0; |
| 154 |
} |
| 155 |
]])], |
| 156 |
[gl_cv_func_sqrtl_works=yes], |
| 157 |
[gl_cv_func_sqrtl_works=no], |
| 158 |
[case "$host_os" in |
| 159 |
openbsd*) gl_cv_func_sqrtl_works="guessing no" ;; |
| 160 |
# Guess yes on native Windows. |
| 161 |
mingw* | windows*) gl_cv_func_sqrtl_works="guessing yes" ;; |
| 162 |
*) gl_cv_func_sqrtl_works="guessing yes" ;; |
| 163 |
esac |
| 164 |
]) |
| 165 |
]) |
| 166 |
]) |