| 1 |
# logl.m4 |
| 2 |
# serial 18 |
| 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_LOGL], |
| 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 logl(). |
| 15 |
AC_REQUIRE([gl_USE_SYSTEM_EXTENSIONS]) |
| 16 |
|
| 17 |
LOGL_LIBM= |
| 18 |
AC_CACHE_CHECK([whether logl() can be used without linking with libm], |
| 19 |
[gl_cv_func_logl_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 (*funcptr) (long double) = logl; |
| 28 |
long double x;]], |
| 29 |
[[return funcptr (x) > 1 |
| 30 |
|| logl (x) > 1;]])], |
| 31 |
[gl_cv_func_logl_no_libm=yes], |
| 32 |
[gl_cv_func_logl_no_libm=no]) |
| 33 |
]) |
| 34 |
if test $gl_cv_func_logl_no_libm = no; then |
| 35 |
AC_CACHE_CHECK([whether logl() can be used with libm], |
| 36 |
[gl_cv_func_logl_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 (*funcptr) (long double) = logl; |
| 47 |
long double x;]], |
| 48 |
[[return funcptr (x) > 1 |
| 49 |
|| logl (x) > 1;]])], |
| 50 |
[gl_cv_func_logl_in_libm=yes], |
| 51 |
[gl_cv_func_logl_in_libm=no]) |
| 52 |
LIBS="$saved_LIBS" |
| 53 |
]) |
| 54 |
if test $gl_cv_func_logl_in_libm = yes; then |
| 55 |
LOGL_LIBM=-lm |
| 56 |
fi |
| 57 |
fi |
| 58 |
if test $gl_cv_func_logl_no_libm = yes \ |
| 59 |
|| test $gl_cv_func_logl_in_libm = yes; then |
| 60 |
dnl Also check whether it's declared. |
| 61 |
dnl Mac OS X 10.3 has logl() in libc but doesn't declare it in <math.h>. |
| 62 |
AC_CHECK_DECL([logl], , [HAVE_DECL_LOGL=0], [[#include <math.h>]]) |
| 63 |
saved_LIBS="$LIBS" |
| 64 |
LIBS="$LIBS $LOGL_LIBM" |
| 65 |
gl_FUNC_LOGL_WORKS |
| 66 |
LIBS="$saved_LIBS" |
| 67 |
case "$gl_cv_func_logl_works" in |
| 68 |
*yes) ;; |
| 69 |
*) REPLACE_LOGL=1 ;; |
| 70 |
esac |
| 71 |
else |
| 72 |
HAVE_LOGL=0 |
| 73 |
HAVE_DECL_LOGL=0 |
| 74 |
fi |
| 75 |
if test $HAVE_LOGL = 0 || test $REPLACE_LOGL = 1; then |
| 76 |
dnl Find libraries needed to link lib/logl.c. |
| 77 |
if test $HAVE_SAME_LONG_DOUBLE_AS_DOUBLE = 1; then |
| 78 |
AC_REQUIRE([gl_FUNC_LOG]) |
| 79 |
LOGL_LIBM="$LOG_LIBM" |
| 80 |
else |
| 81 |
if test $HAVE_LOGL = 0; then |
| 82 |
AC_REQUIRE([gl_FUNC_FREXPL]) |
| 83 |
AC_REQUIRE([gl_FUNC_ISNANL]) |
| 84 |
AC_REQUIRE([gl_FUNC_FLOORL]) |
| 85 |
dnl Append $FREXPL_LIBM to LOGL_LIBM, avoiding gratuitous duplicates. |
| 86 |
case " $LOGL_LIBM " in |
| 87 |
*" $FREXPL_LIBM "*) ;; |
| 88 |
*) LOGL_LIBM="$LOGL_LIBM $FREXPL_LIBM" ;; |
| 89 |
esac |
| 90 |
dnl Append $ISNANL_LIBM to LOGL_LIBM, avoiding gratuitous duplicates. |
| 91 |
case " $LOGL_LIBM " in |
| 92 |
*" $ISNANL_LIBM "*) ;; |
| 93 |
*) LOGL_LIBM="$LOGL_LIBM $ISNANL_LIBM" ;; |
| 94 |
esac |
| 95 |
dnl Append $FLOORL_LIBM to LOGL_LIBM, avoiding gratuitous duplicates. |
| 96 |
case " $LOGL_LIBM " in |
| 97 |
*" $FLOORL_LIBM "*) ;; |
| 98 |
*) LOGL_LIBM="$LOGL_LIBM $FLOORL_LIBM" ;; |
| 99 |
esac |
| 100 |
fi |
| 101 |
fi |
| 102 |
fi |
| 103 |
AC_SUBST([LOGL_LIBM]) |
| 104 |
]) |
| 105 |
|
| 106 |
dnl Test whether logl() works. |
| 107 |
dnl On OSF/1 5.1, logl(-0.0L) is NaN. |
| 108 |
dnl On NetBSD 9.3, the result is accurate to only 16 digits. |
| 109 |
AC_DEFUN([gl_FUNC_LOGL_WORKS], |
| 110 |
[ |
| 111 |
AC_REQUIRE([AC_PROG_CC]) |
| 112 |
AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles |
| 113 |
AC_CACHE_CHECK([whether logl works], [gl_cv_func_logl_works], |
| 114 |
[ |
| 115 |
AC_RUN_IFELSE( |
| 116 |
[AC_LANG_SOURCE([[ |
| 117 |
#ifndef __NO_MATH_INLINES |
| 118 |
# define __NO_MATH_INLINES 1 /* for glibc */ |
| 119 |
#endif |
| 120 |
#include <float.h> |
| 121 |
#include <math.h> |
| 122 |
/* Override the values of <float.h>, like done in float.in.h. */ |
| 123 |
#if defined __i386__ && (defined __BEOS__ || defined __OpenBSD__) |
| 124 |
# undef LDBL_MANT_DIG |
| 125 |
# define LDBL_MANT_DIG 64 |
| 126 |
# undef LDBL_MIN_EXP |
| 127 |
# define LDBL_MIN_EXP (-16381) |
| 128 |
# undef LDBL_MAX_EXP |
| 129 |
# define LDBL_MAX_EXP 16384 |
| 130 |
#endif |
| 131 |
#if defined __i386__ && (defined __FreeBSD__ || defined __DragonFly__) |
| 132 |
# undef LDBL_MANT_DIG |
| 133 |
# define LDBL_MANT_DIG 64 |
| 134 |
# undef LDBL_MIN_EXP |
| 135 |
# define LDBL_MIN_EXP (-16381) |
| 136 |
# undef LDBL_MAX_EXP |
| 137 |
# define LDBL_MAX_EXP 16384 |
| 138 |
#endif |
| 139 |
#if (defined _ARCH_PPC || defined _POWER) && defined _AIX && (LDBL_MANT_DIG == 106) && defined __GNUC__ |
| 140 |
# undef LDBL_MIN_EXP |
| 141 |
# define LDBL_MIN_EXP DBL_MIN_EXP |
| 142 |
#endif |
| 143 |
#if defined __sgi && (LDBL_MANT_DIG >= 106) |
| 144 |
# undef LDBL_MANT_DIG |
| 145 |
# define LDBL_MANT_DIG 106 |
| 146 |
# if defined __GNUC__ |
| 147 |
# undef LDBL_MIN_EXP |
| 148 |
# define LDBL_MIN_EXP DBL_MIN_EXP |
| 149 |
# endif |
| 150 |
#endif |
| 151 |
#undef logl |
| 152 |
extern |
| 153 |
#ifdef __cplusplus |
| 154 |
"C" |
| 155 |
#endif |
| 156 |
long double logl (long double); |
| 157 |
static long double dummy (long double x) { return 0; } |
| 158 |
volatile long double gx; |
| 159 |
long double gy; |
| 160 |
int main (int argc, char *argv[]) |
| 161 |
{ |
| 162 |
long double (* volatile my_logl) (long double) = argc ? logl : dummy; |
| 163 |
int result = 0; |
| 164 |
/* This test fails on OSF/1 5.1. */ |
| 165 |
{ |
| 166 |
gx = -0.0L; |
| 167 |
gy = logl (gx); |
| 168 |
if (!(gy + gy == gy)) |
| 169 |
result |= 1; |
| 170 |
} |
| 171 |
/* This test fails on musl 1.2.2/arm64, musl 1.2.2/s390x, NetBSD 9.3. */ |
| 172 |
{ |
| 173 |
const long double TWO_LDBL_MANT_DIG = /* 2^LDBL_MANT_DIG */ |
| 174 |
(long double) (1U << ((LDBL_MANT_DIG - 1) / 5)) |
| 175 |
* (long double) (1U << ((LDBL_MANT_DIG - 1 + 1) / 5)) |
| 176 |
* (long double) (1U << ((LDBL_MANT_DIG - 1 + 2) / 5)) |
| 177 |
* (long double) (1U << ((LDBL_MANT_DIG - 1 + 3) / 5)) |
| 178 |
* (long double) (1U << ((LDBL_MANT_DIG - 1 + 4) / 5)); |
| 179 |
long double x = 16.981137113807045L; |
| 180 |
long double err = (my_logl (x) + my_logl (1.0L / x)) * TWO_LDBL_MANT_DIG; |
| 181 |
if (!(err >= -100.0L && err <= 100.0L)) |
| 182 |
result |= 2; |
| 183 |
} |
| 184 |
|
| 185 |
return result; |
| 186 |
} |
| 187 |
]])], |
| 188 |
[gl_cv_func_logl_works=yes], |
| 189 |
[gl_cv_func_logl_works=no], |
| 190 |
[case "$host_os" in |
| 191 |
# Guess yes on glibc systems. |
| 192 |
*-gnu* | gnu*) gl_cv_func_logl_works="guessing yes" ;; |
| 193 |
# Guess no on musl systems. |
| 194 |
*-musl* | midipix*) gl_cv_func_logl_works="guessing no" ;; |
| 195 |
# Guess yes on native Windows. |
| 196 |
mingw* | windows*) gl_cv_func_logl_works="guessing yes" ;; |
| 197 |
# If we don't know, obey --enable-cross-guesses. |
| 198 |
*) gl_cv_func_logl_works="$gl_cross_guess_normal" ;; |
| 199 |
esac |
| 200 |
]) |
| 201 |
]) |
| 202 |
]) |