log.m4 2.8 KB

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