mathfunc.m4 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. # mathfunc.m4 serial 6
  2. dnl Copyright (C) 2010-2011 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. # gl_MATHFUNC(FUNC, RETTYPE, PARAMTYPES)
  7. # --------------------------------------------------
  8. # tests whether the function FUNC is available in libc or libm.
  9. # RETTYPE is the return type. PARAMTYPES is a parameter list, with parentheses.
  10. # It sets FUNC_LIBM to empty or "-lm" accordingly.
  11. AC_DEFUN([gl_MATHFUNC],
  12. [
  13. dnl We need the RETTYPE and PARAMTYPES in order to force linking with the
  14. dnl function. With gcc >= 4.3 on glibc/x86_64, calls to the 'fabs' function
  15. dnl are inlined by the compiler, therefore linking of these calls does not
  16. dnl require -lm, but taking the function pointer of 'fabs' does.
  17. m4_pushdef([func], [$1])
  18. m4_pushdef([FUNC], [m4_translit([$1],[abcdefghijklmnopqrstuvwxyz],
  19. [ABCDEFGHIJKLMNOPQRSTUVWXYZ])])
  20. FUNC[]_LIBM=
  21. AC_CACHE_CHECK([whether func() can be used without linking with libm],
  22. [gl_cv_func_]func[_no_libm],
  23. [
  24. AC_LINK_IFELSE(
  25. [AC_LANG_PROGRAM(
  26. [[#ifndef __NO_MATH_INLINES
  27. # define __NO_MATH_INLINES 1 /* for glibc */
  28. #endif
  29. #include <math.h>
  30. $2 (*funcptr) $3 = ]func[;
  31. double d_ret;]],
  32. [[$2 y = funcptr ]m4_bpatsubst([m4_bpatsubst([m4_bpatsubst([$3], [int], [2])], [double \*], [&d_ret])], [double], [1.6180339887])[;
  33. return y < 0.3 || y > 1.7;
  34. ]])],
  35. [gl_cv_func_]func[_no_libm=yes],
  36. [gl_cv_func_]func[_no_libm=no])
  37. ])
  38. if test $gl_cv_func_[]func[]_no_libm = no; then
  39. AC_CACHE_CHECK([whether func() can be used with libm],
  40. [gl_cv_func_]func[_in_libm],
  41. [
  42. save_LIBS="$LIBS"
  43. LIBS="$LIBS -lm"
  44. AC_LINK_IFELSE(
  45. [AC_LANG_PROGRAM(
  46. [[#ifndef __NO_MATH_INLINES
  47. # define __NO_MATH_INLINES 1 /* for glibc */
  48. #endif
  49. #include <math.h>
  50. $2 (*funcptr) $3 = ]func[;
  51. double d_ret;]],
  52. [[$2 y = funcptr ]m4_bpatsubst([m4_bpatsubst([m4_bpatsubst([$3], [int], [2])], [double \*], [&d_ret])], [double], [1.6180339887])[;
  53. return y < 0.3 || y > 1.7;
  54. ]])],
  55. [gl_cv_func_]func[_in_libm=yes],
  56. [gl_cv_func_]func[_in_libm=no])
  57. LIBS="$save_LIBS"
  58. ])
  59. if test $gl_cv_func_[]func[]_in_libm = yes; then
  60. FUNC[]_LIBM=-lm
  61. fi
  62. fi
  63. AC_SUBST(FUNC[_LIBM])
  64. m4_popdef([FUNC])
  65. m4_popdef([func])
  66. ])
  67. # gl_COMMON_DOUBLE_MATHFUNC(FUNC)
  68. # -------------------------------
  69. # tests whether the function FUNC is available in libc or libm.
  70. # It sets FUNC_LIBM to empty or "-lm" accordingly.
  71. # FUNC must be one of the following functions, that are present on all systems
  72. # and provided by libm on all systems except MacOS X, BeOS, Haiku:
  73. # acos asin atan atan2 cbrt cos cosh erf erfc exp fmod hypot j0 j1 jn lgamma
  74. # log log10 log1p pow remainder sin sinh sqrt tan tanh y0 y1 yn
  75. AC_DEFUN([gl_COMMON_DOUBLE_MATHFUNC],
  76. [
  77. AC_REQUIRE([gl_COMMON_DOUBLE_MATHFUNC_TEST])
  78. m4_pushdef([FUNC], [m4_translit([$1],[abcdefghijklmnopqrstuvwxyz],
  79. [ABCDEFGHIJKLMNOPQRSTUVWXYZ])])
  80. FUNC[]_LIBM="$POW_LIBM"
  81. AC_SUBST(FUNC[_LIBM])
  82. m4_popdef([FUNC])
  83. ])
  84. AC_DEFUN([gl_COMMON_DOUBLE_MATHFUNC_TEST],
  85. [
  86. dnl We could use any of the following:
  87. dnl gl_MATHFUNC([acos], [double], [(double)])
  88. dnl gl_MATHFUNC([asin], [double], [(double)])
  89. dnl gl_MATHFUNC([atan], [double], [(double)])
  90. dnl gl_MATHFUNC([atan2], [double], [(double, double)])
  91. dnl gl_MATHFUNC([cbrt], [double], [(double)])
  92. dnl gl_MATHFUNC([cos], [double], [(double)])
  93. dnl gl_MATHFUNC([cosh], [double], [(double)])
  94. dnl gl_MATHFUNC([erf], [double], [(double)])
  95. dnl gl_MATHFUNC([erfc], [double], [(double)])
  96. dnl gl_MATHFUNC([exp], [double], [(double)])
  97. dnl gl_MATHFUNC([fmod], [double], [(double, double)])
  98. dnl gl_MATHFUNC([hypot], [double], [(double, double)])
  99. dnl gl_MATHFUNC([j0], [double], [(double)])
  100. dnl gl_MATHFUNC([j1], [double], [(double)])
  101. dnl gl_MATHFUNC([jn], [double], [(int, double)])
  102. dnl gl_MATHFUNC([lgamma], [double], [(double)])
  103. dnl gl_MATHFUNC([log], [double], [(double)])
  104. dnl gl_MATHFUNC([log10], [double], [(double)])
  105. dnl gl_MATHFUNC([log1p], [double], [(double)])
  106. dnl gl_MATHFUNC([pow], [double], [(double, double)])
  107. dnl gl_MATHFUNC([remainder], [double], [(double, double)])
  108. dnl gl_MATHFUNC([sin], [double], [(double)])
  109. dnl gl_MATHFUNC([sinh], [double], [(double)])
  110. dnl gl_MATHFUNC([sqrt], [double], [(double)])
  111. dnl gl_MATHFUNC([tan], [double], [(double)])
  112. dnl gl_MATHFUNC([tanh], [double], [(double)])
  113. dnl gl_MATHFUNC([y0], [double], [(double)])
  114. dnl gl_MATHFUNC([y1], [double], [(double)])
  115. dnl gl_MATHFUNC([yn], [double], [(int, double)])
  116. gl_MATHFUNC([pow], [double], [(double, double)])
  117. ])