floor.m4 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. # floor.m4 serial 14
  2. dnl Copyright (C) 2007, 2009-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_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 (* volatile 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* | gnu*) gl_cv_func_floor_ieee="guessing yes" ;;
  46. # Guess yes on musl systems.
  47. *-musl*) gl_cv_func_floor_ieee="guessing yes" ;;
  48. # Guess yes on native Windows.
  49. mingw*) gl_cv_func_floor_ieee="guessing yes" ;;
  50. # If we don't know, obey --enable-cross-guesses.
  51. *) gl_cv_func_floor_ieee="$gl_cross_guess_normal" ;;
  52. esac
  53. ])
  54. LIBS="$save_LIBS"
  55. ])
  56. case "$gl_cv_func_floor_ieee" in
  57. *yes) ;;
  58. *) REPLACE_FLOOR=1 ;;
  59. esac
  60. fi
  61. ])
  62. if test $REPLACE_FLOOR = 1; then
  63. dnl No libraries are needed to link lib/floor.c.
  64. FLOOR_LIBM=
  65. fi
  66. AC_SUBST([FLOOR_LIBM])
  67. ])
  68. # Determines the libraries needed to get the floor() function.
  69. # Sets FLOOR_LIBM.
  70. AC_DEFUN([gl_FUNC_FLOOR_LIBS],
  71. [
  72. gl_CACHE_VAL_SILENT([gl_cv_func_floor_libm], [
  73. gl_cv_func_floor_libm=?
  74. AC_LINK_IFELSE(
  75. [AC_LANG_PROGRAM(
  76. [[#ifndef __NO_MATH_INLINES
  77. # define __NO_MATH_INLINES 1 /* for glibc */
  78. #endif
  79. #include <math.h>
  80. double (*funcptr) (double) = floor;
  81. double x;]],
  82. [[x = funcptr(x) + floor(x);]])],
  83. [gl_cv_func_floor_libm=])
  84. if test "$gl_cv_func_floor_libm" = "?"; then
  85. save_LIBS="$LIBS"
  86. LIBS="$LIBS -lm"
  87. AC_LINK_IFELSE(
  88. [AC_LANG_PROGRAM(
  89. [[#ifndef __NO_MATH_INLINES
  90. # define __NO_MATH_INLINES 1 /* for glibc */
  91. #endif
  92. #include <math.h>
  93. double (*funcptr) (double) = floor;
  94. double x;]],
  95. [[x = funcptr(x) + floor(x);]])],
  96. [gl_cv_func_floor_libm="-lm"])
  97. LIBS="$save_LIBS"
  98. fi
  99. ])
  100. FLOOR_LIBM="$gl_cv_func_floor_libm"
  101. ])