floorf.m4~ 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. # floorf.m4 serial 13
  2. dnl Copyright (C) 2007, 2009-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. AC_DEFUN([gl_FUNC_FLOORF],
  7. [
  8. m4_divert_text([DEFAULTS], [gl_floorf_required=plain])
  9. AC_REQUIRE([gl_MATH_H_DEFAULTS])
  10. dnl Persuade glibc <math.h> to declare floorf().
  11. AC_REQUIRE([gl_USE_SYSTEM_EXTENSIONS])
  12. dnl Test whether floorf() is declared.
  13. AC_CHECK_DECLS([floorf], , , [[#include <math.h>]])
  14. if test "$ac_cv_have_decl_floorf" = yes; then
  15. dnl Test whether floorf() can be used without libm.
  16. gl_FUNC_FLOORF_LIBS
  17. if test "$FLOORF_LIBM" = "?"; then
  18. dnl Sun C 5.0 on Solaris declares floorf() and has it in the system-wide
  19. dnl libm.so, but not in the libm.so that the compiler uses.
  20. REPLACE_FLOORF=1
  21. fi
  22. m4_ifdef([gl_FUNC_FLOORF_IEEE], [
  23. if test $gl_floorf_required = ieee && test $REPLACE_FLOORF = 0; then
  24. AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
  25. AC_CACHE_CHECK([whether floorf works according to ISO C 99 with IEC 60559],
  26. [gl_cv_func_floorf_ieee],
  27. [
  28. save_LIBS="$LIBS"
  29. LIBS="$LIBS $FLOORF_LIBM"
  30. AC_RUN_IFELSE(
  31. [AC_LANG_SOURCE([[
  32. #ifndef __NO_MATH_INLINES
  33. # define __NO_MATH_INLINES 1 /* for glibc */
  34. #endif
  35. #include <math.h>
  36. ]gl_FLOAT_MINUS_ZERO_CODE[
  37. ]gl_FLOAT_SIGNBIT_CODE[
  38. static float dummy (float f) { return 0; }
  39. int main (int argc, char *argv[])
  40. {
  41. float (*my_floorf) (float) = argc ? floorf : dummy;
  42. /* Test whether floorf (-0.0f) is -0.0f. */
  43. if (signbitf (minus_zerof) && !signbitf (my_floorf (minus_zerof)))
  44. return 1;
  45. return 0;
  46. }
  47. ]])],
  48. [gl_cv_func_floorf_ieee=yes],
  49. [gl_cv_func_floorf_ieee=no],
  50. [case "$host_os" in
  51. # Guess yes on glibc systems.
  52. *-gnu*) gl_cv_func_floorf_ieee="guessing yes" ;;
  53. # If we don't know, assume the worst.
  54. *) gl_cv_func_floorf_ieee="guessing no" ;;
  55. esac
  56. ])
  57. LIBS="$save_LIBS"
  58. ])
  59. case "$gl_cv_func_floorf_ieee" in
  60. *yes) ;;
  61. *) REPLACE_FLOORF=1 ;;
  62. esac
  63. fi
  64. ])
  65. else
  66. HAVE_DECL_FLOORF=0
  67. fi
  68. if test $HAVE_DECL_FLOORF = 0 || test $REPLACE_FLOORF = 1; then
  69. dnl No libraries are needed to link lib/floorf.c.
  70. FLOORF_LIBM=
  71. fi
  72. AC_SUBST([FLOORF_LIBM])
  73. ])
  74. # Determines the libraries needed to get the floorf() function.
  75. # Sets FLOORF_LIBM.
  76. AC_DEFUN([gl_FUNC_FLOORF_LIBS],
  77. [
  78. gl_CACHE_VAL_SILENT([gl_cv_func_floorf_libm], [
  79. gl_cv_func_floorf_libm=?
  80. AC_LINK_IFELSE(
  81. [AC_LANG_PROGRAM(
  82. [[#ifndef __NO_MATH_INLINES
  83. # define __NO_MATH_INLINES 1 /* for glibc */
  84. #endif
  85. #include <math.h>
  86. float (*funcptr) (float) = floorf;
  87. float x;]],
  88. [[x = funcptr(x) + floorf(x);]])],
  89. [gl_cv_func_floorf_libm=])
  90. if test "$gl_cv_func_floorf_libm" = "?"; then
  91. save_LIBS="$LIBS"
  92. LIBS="$LIBS -lm"
  93. AC_LINK_IFELSE(
  94. [AC_LANG_PROGRAM(
  95. [[#ifndef __NO_MATH_INLINES
  96. # define __NO_MATH_INLINES 1 /* for glibc */
  97. #endif
  98. #include <math.h>
  99. float (*funcptr) (float) = floorf;
  100. float x;]],
  101. [[x = funcptr(x) + floorf(x);]])],
  102. [gl_cv_func_floorf_libm="-lm"])
  103. LIBS="$save_LIBS"
  104. fi
  105. ])
  106. FLOORF_LIBM="$gl_cv_func_floorf_libm"
  107. ])