ceil.m4 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. # ceil.m4 serial 15
  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_CEIL],
  7. [
  8. m4_divert_text([DEFAULTS], [gl_ceil_required=plain])
  9. AC_REQUIRE([gl_MATH_H_DEFAULTS])
  10. dnl Test whether ceil() can be used without libm.
  11. gl_FUNC_CEIL_LIBS
  12. if test "$CEIL_LIBM" = "?"; then
  13. CEIL_LIBM=
  14. fi
  15. m4_ifdef([gl_FUNC_CEIL_IEEE], [
  16. if test $gl_ceil_required = ieee && test $REPLACE_CEIL = 0; then
  17. AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
  18. AC_CACHE_CHECK([whether ceil works according to ISO C 99 with IEC 60559],
  19. [gl_cv_func_ceil_ieee],
  20. [
  21. save_LIBS="$LIBS"
  22. LIBS="$LIBS $CEIL_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_ceil) (double) = argc ? ceil : dummy;
  35. int result = 0;
  36. /* Test whether ceil (-0.0) is -0.0. */
  37. if (signbitd (minus_zerod) && !signbitd (my_ceil (minus_zerod)))
  38. result |= 1;
  39. /* Test whether ceil (-0.3) is -0.0. */
  40. if (signbitd (-0.3) && !signbitd (my_ceil (-0.3)))
  41. result |= 2;
  42. return result;
  43. }
  44. ]])],
  45. [gl_cv_func_ceil_ieee=yes],
  46. [gl_cv_func_ceil_ieee=no],
  47. [case "$host_os" in
  48. # Guess yes on glibc systems.
  49. *-gnu* | gnu*) gl_cv_func_ceil_ieee="guessing yes" ;;
  50. # Guess yes on musl systems.
  51. *-musl*) gl_cv_func_ceil_ieee="guessing yes" ;;
  52. # Guess yes on native Windows.
  53. mingw*) gl_cv_func_ceil_ieee="guessing yes" ;;
  54. # If we don't know, obey --enable-cross-guesses.
  55. *) gl_cv_func_ceil_ieee="$gl_cross_guess_normal" ;;
  56. esac
  57. ])
  58. LIBS="$save_LIBS"
  59. ])
  60. case "$gl_cv_func_ceil_ieee" in
  61. *yes) ;;
  62. *) REPLACE_CEIL=1 ;;
  63. esac
  64. fi
  65. ])
  66. if test $REPLACE_CEIL = 1; then
  67. dnl No libraries are needed to link lib/ceil.c.
  68. CEIL_LIBM=
  69. fi
  70. AC_SUBST([CEIL_LIBM])
  71. ])
  72. # Determines the libraries needed to get the ceil() function.
  73. # Sets CEIL_LIBM.
  74. AC_DEFUN([gl_FUNC_CEIL_LIBS],
  75. [
  76. gl_CACHE_VAL_SILENT([gl_cv_func_ceil_libm], [
  77. gl_cv_func_ceil_libm=?
  78. AC_LINK_IFELSE(
  79. [AC_LANG_PROGRAM(
  80. [[#ifndef __NO_MATH_INLINES
  81. # define __NO_MATH_INLINES 1 /* for glibc */
  82. #endif
  83. #include <math.h>
  84. double (*funcptr) (double) = ceil;
  85. double x;]],
  86. [[x = funcptr(x) + ceil(x);]])],
  87. [gl_cv_func_ceil_libm=])
  88. if test "$gl_cv_func_ceil_libm" = "?"; then
  89. save_LIBS="$LIBS"
  90. LIBS="$LIBS -lm"
  91. AC_LINK_IFELSE(
  92. [AC_LANG_PROGRAM(
  93. [[#ifndef __NO_MATH_INLINES
  94. # define __NO_MATH_INLINES 1 /* for glibc */
  95. #endif
  96. #include <math.h>
  97. double (*funcptr) (double) = ceil;
  98. double x;]],
  99. [[x = funcptr(x) + ceil(x);]])],
  100. [gl_cv_func_ceil_libm="-lm"])
  101. LIBS="$save_LIBS"
  102. fi
  103. ])
  104. CEIL_LIBM="$gl_cv_func_ceil_libm"
  105. ])