trunc.m4 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. # trunc.m4 serial 9
  2. dnl Copyright (C) 2007, 2010-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_TRUNC],
  7. [
  8. m4_divert_text([DEFAULTS], [gl_trunc_required=plain])
  9. AC_REQUIRE([gl_MATH_H_DEFAULTS])
  10. dnl Persuade glibc <math.h> to declare trunc().
  11. AC_REQUIRE([gl_USE_SYSTEM_EXTENSIONS])
  12. dnl Test whether trunc() is declared.
  13. AC_CHECK_DECLS([trunc], , , [[#include <math.h>]])
  14. if test "$ac_cv_have_decl_trunc" = yes; then
  15. dnl Test whether trunc() can be used without libm.
  16. TRUNC_LIBM=?
  17. AC_LINK_IFELSE(
  18. [AC_LANG_PROGRAM(
  19. [[#ifndef __NO_MATH_INLINES
  20. # define __NO_MATH_INLINES 1 /* for glibc */
  21. #endif
  22. #include <math.h>
  23. double x;]],
  24. [[x = trunc(x);]])],
  25. [TRUNC_LIBM=])
  26. if test "$TRUNC_LIBM" = "?"; then
  27. save_LIBS="$LIBS"
  28. LIBS="$LIBS -lm"
  29. AC_LINK_IFELSE(
  30. [AC_LANG_PROGRAM(
  31. [[#ifndef __NO_MATH_INLINES
  32. # define __NO_MATH_INLINES 1 /* for glibc */
  33. #endif
  34. #include <math.h>
  35. double x;]],
  36. [[x = trunc(x);]])],
  37. [TRUNC_LIBM="-lm"])
  38. LIBS="$save_LIBS"
  39. fi
  40. if test "$TRUNC_LIBM" = "?"; then
  41. TRUNC_LIBM=
  42. fi
  43. m4_ifdef([gl_FUNC_TRUNC_IEEE], [
  44. if test $gl_trunc_required = ieee && test $REPLACE_TRUNC = 0; then
  45. AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
  46. AC_CACHE_CHECK([whether trunc works according to ISO C 99 with IEC 60559],
  47. [gl_cv_func_trunc_ieee],
  48. [
  49. save_LIBS="$LIBS"
  50. LIBS="$LIBS $TRUNC_LIBM"
  51. AC_RUN_IFELSE(
  52. [AC_LANG_SOURCE([[
  53. #ifndef __NO_MATH_INLINES
  54. # define __NO_MATH_INLINES 1 /* for glibc */
  55. #endif
  56. #include <math.h>
  57. ]gl_DOUBLE_MINUS_ZERO_CODE[
  58. ]gl_DOUBLE_SIGNBIT_CODE[
  59. static double dummy (double f) { return 0; }
  60. int main (int argc, char *argv[])
  61. {
  62. double (*my_trunc) (double) = argc ? trunc : dummy;
  63. /* Test whether trunc (-0.0) is -0.0. */
  64. if (signbitd (minus_zerod) && !signbitd (my_trunc (minus_zerod)))
  65. return 1;
  66. return 0;
  67. }
  68. ]])],
  69. [gl_cv_func_trunc_ieee=yes],
  70. [gl_cv_func_trunc_ieee=no],
  71. [case "$host_os" in
  72. # Guess yes on glibc systems.
  73. *-gnu*) gl_cv_func_trunc_ieee="guessing yes" ;;
  74. # If we don't know, assume the worst.
  75. *) gl_cv_func_trunc_ieee="guessing no" ;;
  76. esac
  77. ])
  78. LIBS="$save_LIBS"
  79. ])
  80. case "$gl_cv_func_trunc_ieee" in
  81. *yes) ;;
  82. *) REPLACE_TRUNC=1 ;;
  83. esac
  84. fi
  85. ])
  86. else
  87. HAVE_DECL_TRUNC=0
  88. fi
  89. if test $HAVE_DECL_TRUNC = 0 || test $REPLACE_TRUNC = 1; then
  90. dnl No libraries are needed to link lib/trunc.c.
  91. TRUNC_LIBM=
  92. fi
  93. AC_SUBST([TRUNC_LIBM])
  94. ])