ceil.m4 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. # ceil.m4 serial 8
  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_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_CACHE_CHECK([whether ceil works according to ISO C 99 with IEC 60559],
  18. [gl_cv_func_ceil_ieee],
  19. [
  20. save_LIBS="$LIBS"
  21. LIBS="$LIBS $CEIL_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_ceil) (double) = argc ? ceil : dummy;
  34. int result = 0;
  35. /* Test whether ceil (-0.0) is -0.0. */
  36. if (signbitd (minus_zerod) && !signbitd (my_ceil (minus_zerod)))
  37. result |= 1;
  38. /* Test whether ceil (-0.3) is -0.0. */
  39. if (signbitd (-0.3) && !signbitd (my_ceil (-0.3)))
  40. result |= 2;
  41. return result;
  42. }
  43. ]])],
  44. [gl_cv_func_ceil_ieee=yes],
  45. [gl_cv_func_ceil_ieee=no],
  46. [gl_cv_func_ceil_ieee="guessing no"])
  47. LIBS="$save_LIBS"
  48. ])
  49. case "$gl_cv_func_ceil_ieee" in
  50. *yes) ;;
  51. *) REPLACE_CEIL=1 ;;
  52. esac
  53. fi
  54. ])
  55. if test $REPLACE_CEIL = 1; then
  56. dnl No libraries are needed to link lib/ceil.c.
  57. CEIL_LIBM=
  58. fi
  59. AC_SUBST([CEIL_LIBM])
  60. ])
  61. # Determines the libraries needed to get the ceil() function.
  62. # Sets CEIL_LIBM.
  63. AC_DEFUN([gl_FUNC_CEIL_LIBS],
  64. [
  65. gl_CACHE_VAL_SILENT([gl_cv_func_ceil_libm], [
  66. gl_cv_func_ceil_libm=?
  67. AC_LINK_IFELSE(
  68. [AC_LANG_PROGRAM(
  69. [[#ifndef __NO_MATH_INLINES
  70. # define __NO_MATH_INLINES 1 /* for glibc */
  71. #endif
  72. #include <math.h>
  73. double x;]],
  74. [[x = ceil(x);]])],
  75. [gl_cv_func_ceil_libm=])
  76. if test "$gl_cv_func_ceil_libm" = "?"; then
  77. save_LIBS="$LIBS"
  78. LIBS="$LIBS -lm"
  79. AC_LINK_IFELSE(
  80. [AC_LANG_PROGRAM(
  81. [[#ifndef __NO_MATH_INLINES
  82. # define __NO_MATH_INLINES 1 /* for glibc */
  83. #endif
  84. #include <math.h>
  85. double x;]],
  86. [[x = ceil(x);]])],
  87. [gl_cv_func_ceil_libm="-lm"])
  88. LIBS="$save_LIBS"
  89. fi
  90. ])
  91. CEIL_LIBM="$gl_cv_func_ceil_libm"
  92. ])