| 1 |
# log.m4 |
| 2 |
# serial 14 |
| 3 |
dnl Copyright (C) 2011-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_LOG], |
| 10 |
[ |
| 11 |
m4_divert_text([DEFAULTS], [gl_log_required=plain]) |
| 12 |
AC_REQUIRE([gl_MATH_H_DEFAULTS]) |
| 13 |
|
| 14 |
dnl Determine LOG_LIBM. |
| 15 |
gl_COMMON_DOUBLE_MATHFUNC([log]) |
| 16 |
|
| 17 |
saved_LIBS="$LIBS" |
| 18 |
LIBS="$LIBS $LOG_LIBM" |
| 19 |
gl_FUNC_LOG_WORKS |
| 20 |
LIBS="$saved_LIBS" |
| 21 |
case "$gl_cv_func_log_works" in |
| 22 |
*yes) ;; |
| 23 |
*) REPLACE_LOG=1 ;; |
| 24 |
esac |
| 25 |
|
| 26 |
m4_ifdef([gl_FUNC_LOG_IEEE], [ |
| 27 |
if test $gl_log_required = ieee && test $REPLACE_LOG = 0; then |
| 28 |
AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles |
| 29 |
AC_CACHE_CHECK([whether log works according to ISO C 99 with IEC 60559], |
| 30 |
[gl_cv_func_log_ieee], |
| 31 |
[ |
| 32 |
saved_LIBS="$LIBS" |
| 33 |
LIBS="$LIBS $LOG_LIBM" |
| 34 |
AC_RUN_IFELSE( |
| 35 |
[AC_LANG_SOURCE([[ |
| 36 |
#ifndef __NO_MATH_INLINES |
| 37 |
# define __NO_MATH_INLINES 1 /* for glibc */ |
| 38 |
#endif |
| 39 |
#include <math.h> |
| 40 |
/* Compare two numbers with ==. |
| 41 |
This is a separate function because IRIX 6.5 "cc -O" miscompiles an |
| 42 |
'x == x' test. */ |
| 43 |
static int |
| 44 |
numeric_equal (double x, double y) |
| 45 |
{ |
| 46 |
return x == y; |
| 47 |
} |
| 48 |
static double dummy (double x) { return 0; } |
| 49 |
int main (int argc, char *argv[]) |
| 50 |
{ |
| 51 |
double (* volatile my_log) (double) = argc ? log : dummy; |
| 52 |
/* Test log(negative). |
| 53 |
This test fails on NetBSD 5.1, Solaris 11.4. */ |
| 54 |
double y = my_log (-1.0); |
| 55 |
if (numeric_equal (y, y)) |
| 56 |
return 1; |
| 57 |
return 0; |
| 58 |
} |
| 59 |
]])], |
| 60 |
[gl_cv_func_log_ieee=yes], |
| 61 |
[gl_cv_func_log_ieee=no], |
| 62 |
[case "$host_os" in |
| 63 |
# Guess yes on glibc systems. |
| 64 |
*-gnu* | gnu*) gl_cv_func_log_ieee="guessing yes" ;; |
| 65 |
# Guess yes on musl systems. |
| 66 |
*-musl* | midipix*) gl_cv_func_log_ieee="guessing yes" ;; |
| 67 |
# Guess yes on native Windows. |
| 68 |
mingw* | windows*) gl_cv_func_log_ieee="guessing yes" ;; |
| 69 |
# If we don't know, obey --enable-cross-guesses. |
| 70 |
*) gl_cv_func_log_ieee="$gl_cross_guess_normal" ;; |
| 71 |
esac |
| 72 |
]) |
| 73 |
LIBS="$saved_LIBS" |
| 74 |
]) |
| 75 |
case "$gl_cv_func_log_ieee" in |
| 76 |
*yes) ;; |
| 77 |
*) REPLACE_LOG=1 ;; |
| 78 |
esac |
| 79 |
fi |
| 80 |
]) |
| 81 |
]) |
| 82 |
|
| 83 |
dnl Test whether log() works. |
| 84 |
dnl On OSF/1 5.1, log(-0.0) is NaN. |
| 85 |
AC_DEFUN([gl_FUNC_LOG_WORKS], |
| 86 |
[ |
| 87 |
AC_REQUIRE([AC_PROG_CC]) |
| 88 |
AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles |
| 89 |
AC_CACHE_CHECK([whether log works], [gl_cv_func_log_works], |
| 90 |
[ |
| 91 |
AC_RUN_IFELSE( |
| 92 |
[AC_LANG_SOURCE([[ |
| 93 |
#include <math.h> |
| 94 |
volatile double x; |
| 95 |
double y; |
| 96 |
int main () |
| 97 |
{ |
| 98 |
x = -0.0; |
| 99 |
y = log (x); |
| 100 |
if (!(y + y == y)) |
| 101 |
return 1; |
| 102 |
return 0; |
| 103 |
} |
| 104 |
]])], |
| 105 |
[gl_cv_func_log_works=yes], |
| 106 |
[gl_cv_func_log_works=no], |
| 107 |
[case "$host_os" in |
| 108 |
osf*) gl_cv_func_log_works="guessing no" ;; |
| 109 |
# Guess yes on native Windows. |
| 110 |
mingw* | windows*) gl_cv_func_log_works="guessing yes" ;; |
| 111 |
*) gl_cv_func_log_works="guessing yes" ;; |
| 112 |
esac |
| 113 |
]) |
| 114 |
]) |
| 115 |
]) |