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