ceil.m4 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. # ceil.m4 serial 9
  2. dnl Copyright (C) 2007, 2009-2014 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 (*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*) gl_cv_func_ceil_ieee="guessing yes" ;;
  50. # If we don't know, assume the worst.
  51. *) gl_cv_func_ceil_ieee="guessing no" ;;
  52. esac
  53. ])
  54. LIBS="$save_LIBS"
  55. ])
  56. case "$gl_cv_func_ceil_ieee" in
  57. *yes) ;;
  58. *) REPLACE_CEIL=1 ;;
  59. esac
  60. fi
  61. ])
  62. if test $REPLACE_CEIL = 1; then
  63. dnl No libraries are needed to link lib/ceil.c.
  64. CEIL_LIBM=
  65. fi
  66. AC_SUBST([CEIL_LIBM])
  67. ])
  68. # Determines the libraries needed to get the ceil() function.
  69. # Sets CEIL_LIBM.
  70. AC_DEFUN([gl_FUNC_CEIL_LIBS],
  71. [
  72. gl_CACHE_VAL_SILENT([gl_cv_func_ceil_libm], [
  73. gl_cv_func_ceil_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 x;]],
  81. [[x = ceil(x);]])],
  82. [gl_cv_func_ceil_libm=])
  83. if test "$gl_cv_func_ceil_libm" = "?"; then
  84. save_LIBS="$LIBS"
  85. LIBS="$LIBS -lm"
  86. AC_LINK_IFELSE(
  87. [AC_LANG_PROGRAM(
  88. [[#ifndef __NO_MATH_INLINES
  89. # define __NO_MATH_INLINES 1 /* for glibc */
  90. #endif
  91. #include <math.h>
  92. double x;]],
  93. [[x = ceil(x);]])],
  94. [gl_cv_func_ceil_libm="-lm"])
  95. LIBS="$save_LIBS"
  96. fi
  97. ])
  98. CEIL_LIBM="$gl_cv_func_ceil_libm"
  99. ])