trunc.m4 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. # trunc.m4 serial 15
  2. dnl Copyright (C) 2007, 2010-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_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 (*funcptr) (double) = trunc;
  24. double x;]],
  25. [[x = funcptr(x) + trunc(x);]])],
  26. [TRUNC_LIBM=])
  27. if test "$TRUNC_LIBM" = "?"; then
  28. save_LIBS="$LIBS"
  29. LIBS="$LIBS -lm"
  30. AC_LINK_IFELSE(
  31. [AC_LANG_PROGRAM(
  32. [[#ifndef __NO_MATH_INLINES
  33. # define __NO_MATH_INLINES 1 /* for glibc */
  34. #endif
  35. #include <math.h>
  36. double (*funcptr) (double) = trunc;
  37. double x;]],
  38. [[x = funcptr(x) + trunc(x);]])],
  39. [TRUNC_LIBM="-lm"])
  40. LIBS="$save_LIBS"
  41. fi
  42. if test "$TRUNC_LIBM" = "?"; then
  43. TRUNC_LIBM=
  44. fi
  45. m4_ifdef([gl_FUNC_TRUNC_IEEE], [
  46. if test $gl_trunc_required = ieee && test $REPLACE_TRUNC = 0; then
  47. AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
  48. AC_CACHE_CHECK([whether trunc works according to ISO C 99 with IEC 60559],
  49. [gl_cv_func_trunc_ieee],
  50. [
  51. save_LIBS="$LIBS"
  52. LIBS="$LIBS $TRUNC_LIBM"
  53. AC_RUN_IFELSE(
  54. [AC_LANG_SOURCE([[
  55. #ifndef __NO_MATH_INLINES
  56. # define __NO_MATH_INLINES 1 /* for glibc */
  57. #endif
  58. #include <math.h>
  59. ]gl_DOUBLE_MINUS_ZERO_CODE[
  60. ]gl_DOUBLE_SIGNBIT_CODE[
  61. static double dummy (double f) { return 0; }
  62. int main (int argc, char *argv[])
  63. {
  64. double (* volatile my_trunc) (double) = argc ? trunc : dummy;
  65. /* Test whether trunc (-0.0) is -0.0. */
  66. if (signbitd (minus_zerod) && !signbitd (my_trunc (minus_zerod)))
  67. return 1;
  68. return 0;
  69. }
  70. ]])],
  71. [gl_cv_func_trunc_ieee=yes],
  72. [gl_cv_func_trunc_ieee=no],
  73. [case "$host_os" in
  74. # Guess yes on glibc systems.
  75. *-gnu* | gnu*) gl_cv_func_trunc_ieee="guessing yes" ;;
  76. # Guess yes on musl systems.
  77. *-musl*) gl_cv_func_trunc_ieee="guessing yes" ;;
  78. # Guess yes on native Windows.
  79. mingw*) gl_cv_func_trunc_ieee="guessing yes" ;;
  80. # If we don't know, obey --enable-cross-guesses.
  81. *) gl_cv_func_trunc_ieee="$gl_cross_guess_normal" ;;
  82. esac
  83. ])
  84. LIBS="$save_LIBS"
  85. ])
  86. case "$gl_cv_func_trunc_ieee" in
  87. *yes) ;;
  88. *) REPLACE_TRUNC=1 ;;
  89. esac
  90. fi
  91. ])
  92. else
  93. HAVE_DECL_TRUNC=0
  94. fi
  95. if test $HAVE_DECL_TRUNC = 0 || test $REPLACE_TRUNC = 1; then
  96. dnl No libraries are needed to link lib/trunc.c.
  97. TRUNC_LIBM=
  98. fi
  99. AC_SUBST([TRUNC_LIBM])
  100. ])