floor.m4 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. # floor.m4 serial 8
  2. dnl Copyright (C) 2007, 2009-2017 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_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
  18. AC_CACHE_CHECK([whether floor works according to ISO C 99 with IEC 60559],
  19. [gl_cv_func_floor_ieee],
  20. [
  21. save_LIBS="$LIBS"
  22. LIBS="$LIBS $FLOOR_LIBM"
  23. AC_RUN_IFELSE(
  24. [AC_LANG_SOURCE([[
  25. #ifndef __NO_MATH_INLINES
  26. # define __NO_MATH_INLINES 1 /* for glibc */
  27. #endif
  28. #include <math.h>
  29. ]gl_DOUBLE_MINUS_ZERO_CODE[
  30. ]gl_DOUBLE_SIGNBIT_CODE[
  31. static double dummy (double f) { return 0; }
  32. int main (int argc, char *argv[])
  33. {
  34. double (*my_floor) (double) = argc ? floor : dummy;
  35. /* Test whether floor (-0.0) is -0.0. */
  36. if (signbitd (minus_zerod) && !signbitd (my_floor (minus_zerod)))
  37. return 1;
  38. return 0;
  39. }
  40. ]])],
  41. [gl_cv_func_floor_ieee=yes],
  42. [gl_cv_func_floor_ieee=no],
  43. [case "$host_os" in
  44. # Guess yes on glibc systems.
  45. *-gnu*) gl_cv_func_floor_ieee="guessing yes" ;;
  46. # If we don't know, assume the worst.
  47. *) gl_cv_func_floor_ieee="guessing no" ;;
  48. esac
  49. ])
  50. LIBS="$save_LIBS"
  51. ])
  52. case "$gl_cv_func_floor_ieee" in
  53. *yes) ;;
  54. *) REPLACE_FLOOR=1 ;;
  55. esac
  56. fi
  57. ])
  58. if test $REPLACE_FLOOR = 1; then
  59. dnl No libraries are needed to link lib/floor.c.
  60. FLOOR_LIBM=
  61. fi
  62. AC_SUBST([FLOOR_LIBM])
  63. ])
  64. # Determines the libraries needed to get the floor() function.
  65. # Sets FLOOR_LIBM.
  66. AC_DEFUN([gl_FUNC_FLOOR_LIBS],
  67. [
  68. gl_CACHE_VAL_SILENT([gl_cv_func_floor_libm], [
  69. gl_cv_func_floor_libm=?
  70. AC_LINK_IFELSE(
  71. [AC_LANG_PROGRAM(
  72. [[#ifndef __NO_MATH_INLINES
  73. # define __NO_MATH_INLINES 1 /* for glibc */
  74. #endif
  75. #include <math.h>
  76. double x;]],
  77. [[x = floor(x);]])],
  78. [gl_cv_func_floor_libm=])
  79. if test "$gl_cv_func_floor_libm" = "?"; then
  80. save_LIBS="$LIBS"
  81. LIBS="$LIBS -lm"
  82. AC_LINK_IFELSE(
  83. [AC_LANG_PROGRAM(
  84. [[#ifndef __NO_MATH_INLINES
  85. # define __NO_MATH_INLINES 1 /* for glibc */
  86. #endif
  87. #include <math.h>
  88. double x;]],
  89. [[x = floor(x);]])],
  90. [gl_cv_func_floor_libm="-lm"])
  91. LIBS="$save_LIBS"
  92. fi
  93. ])
  94. FLOOR_LIBM="$gl_cv_func_floor_libm"
  95. ])