log.m4 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. # log.m4 serial 11
  2. dnl Copyright (C) 2011-2023 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 (* volatile my_log) (double) = argc ? log : dummy;
  46. /* Test log(negative).
  47. This test fails on NetBSD 5.1, Solaris 11.4. */
  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* | gnu*) gl_cv_func_log_ieee="guessing yes" ;;
  59. # Guess yes on musl systems.
  60. *-musl*) gl_cv_func_log_ieee="guessing yes" ;;
  61. # Guess yes on native Windows.
  62. mingw*) gl_cv_func_log_ieee="guessing yes" ;;
  63. # If we don't know, obey --enable-cross-guesses.
  64. *) gl_cv_func_log_ieee="$gl_cross_guess_normal" ;;
  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. dnl Test whether log() works.
  77. dnl On OSF/1 5.1, log(-0.0) is NaN.
  78. AC_DEFUN([gl_FUNC_LOG_WORKS],
  79. [
  80. AC_REQUIRE([AC_PROG_CC])
  81. AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
  82. AC_CACHE_CHECK([whether log works], [gl_cv_func_log_works],
  83. [
  84. AC_RUN_IFELSE(
  85. [AC_LANG_SOURCE([[
  86. #include <math.h>
  87. volatile double x;
  88. double y;
  89. int main ()
  90. {
  91. x = -0.0;
  92. y = log (x);
  93. if (!(y + y == y))
  94. return 1;
  95. return 0;
  96. }
  97. ]])],
  98. [gl_cv_func_log_works=yes],
  99. [gl_cv_func_log_works=no],
  100. [case "$host_os" in
  101. osf*) gl_cv_func_log_works="guessing no" ;;
  102. # Guess yes on native Windows.
  103. mingw*) gl_cv_func_log_works="guessing yes" ;;
  104. *) gl_cv_func_log_works="guessing yes" ;;
  105. esac
  106. ])
  107. ])
  108. ])