floor.m4 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. # floor.m4 serial 7
  2. dnl Copyright (C) 2007, 2009-2012 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_FLOOR],
  7. [
  8. m4_divert_text([DEFAULTS], [gl_floor_required=plain])
  9. AC_REQUIRE([gl_MATH_H_DEFAULTS])
  10. dnl Test whether floor() can be used without libm.
  11. gl_FUNC_FLOOR_LIBS
  12. if test "$FLOOR_LIBM" = "?"; then
  13. FLOOR_LIBM=
  14. fi
  15. m4_ifdef([gl_FUNC_FLOOR_IEEE], [
  16. if test $gl_floor_required = ieee && test $REPLACE_FLOOR = 0; then
  17. AC_CACHE_CHECK([whether floor works according to ISO C 99 with IEC 60559],
  18. [gl_cv_func_floor_ieee],
  19. [
  20. save_LIBS="$LIBS"
  21. LIBS="$LIBS $FLOOR_LIBM"
  22. AC_RUN_IFELSE(
  23. [AC_LANG_SOURCE([[
  24. #ifndef __NO_MATH_INLINES
  25. # define __NO_MATH_INLINES 1 /* for glibc */
  26. #endif
  27. #include <math.h>
  28. ]gl_DOUBLE_MINUS_ZERO_CODE[
  29. ]gl_DOUBLE_SIGNBIT_CODE[
  30. static double dummy (double f) { return 0; }
  31. int main (int argc, char *argv[])
  32. {
  33. double (*my_floor) (double) = argc ? floor : dummy;
  34. /* Test whether floor (-0.0) is -0.0. */
  35. if (signbitd (minus_zerod) && !signbitd (my_floor (minus_zerod)))
  36. return 1;
  37. return 0;
  38. }
  39. ]])],
  40. [gl_cv_func_floor_ieee=yes],
  41. [gl_cv_func_floor_ieee=no],
  42. [gl_cv_func_floor_ieee="guessing no"])
  43. LIBS="$save_LIBS"
  44. ])
  45. case "$gl_cv_func_floor_ieee" in
  46. *yes) ;;
  47. *) REPLACE_FLOOR=1 ;;
  48. esac
  49. fi
  50. ])
  51. if test $REPLACE_FLOOR = 1; then
  52. dnl No libraries are needed to link lib/floor.c.
  53. FLOOR_LIBM=
  54. fi
  55. AC_SUBST([FLOOR_LIBM])
  56. ])
  57. # Determines the libraries needed to get the floor() function.
  58. # Sets FLOOR_LIBM.
  59. AC_DEFUN([gl_FUNC_FLOOR_LIBS],
  60. [
  61. gl_CACHE_VAL_SILENT([gl_cv_func_floor_libm], [
  62. gl_cv_func_floor_libm=?
  63. AC_LINK_IFELSE(
  64. [AC_LANG_PROGRAM(
  65. [[#ifndef __NO_MATH_INLINES
  66. # define __NO_MATH_INLINES 1 /* for glibc */
  67. #endif
  68. #include <math.h>
  69. double x;]],
  70. [[x = floor(x);]])],
  71. [gl_cv_func_floor_libm=])
  72. if test "$gl_cv_func_floor_libm" = "?"; then
  73. save_LIBS="$LIBS"
  74. LIBS="$LIBS -lm"
  75. AC_LINK_IFELSE(
  76. [AC_LANG_PROGRAM(
  77. [[#ifndef __NO_MATH_INLINES
  78. # define __NO_MATH_INLINES 1 /* for glibc */
  79. #endif
  80. #include <math.h>
  81. double x;]],
  82. [[x = floor(x);]])],
  83. [gl_cv_func_floor_libm="-lm"])
  84. LIBS="$save_LIBS"
  85. fi
  86. ])
  87. FLOOR_LIBM="$gl_cv_func_floor_libm"
  88. ])