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