Merge tag 'snapshot-start' into stable
[gnulib.git] / m4 / modf.m4
1 # modf.m4 serial 2
2 dnl Copyright (C) 2011-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
7 AC_DEFUN([gl_FUNC_MODF],
8 [
9   m4_divert_text([DEFAULTS], [gl_modf_required=plain])
10   AC_REQUIRE([gl_MATH_H_DEFAULTS])
11
12   dnl Determine MODF_LIBM.
13   gl_MATHFUNC([modf], [double], [(double, double *)])
14
15   m4_ifdef([gl_FUNC_MODF_IEEE], [
16     if test $gl_modf_required = ieee && test $REPLACE_MODF = 0; then
17       AC_CACHE_CHECK([whether modf works according to ISO C 99 with IEC 60559],
18         [gl_cv_func_modf_ieee],
19         [
20           save_LIBS="$LIBS"
21           LIBS="$LIBS $MODF_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 /* Compare two numbers with ==.
31    This is a separate function because IRIX 6.5 "cc -O" miscompiles an
32    'x == x' test.  */
33 static int
34 numeric_equal (double x, double y)
35 {
36   return x == y;
37 }
38 static double dummy (double x, double *iptr) { return 0; }
39 double zero;
40 double minus_one = - 1.0;
41 int main (int argc, char *argv[])
42 {
43   double (*my_modf) (double, double *) = argc ? modf : dummy;
44   int result = 0;
45   double i;
46   double f;
47   /* Test modf(NaN,...).
48      This test fails on NetBSD 5.1, Cygwin.  */
49   f = my_modf (zero / zero, &i);
50   if (numeric_equal (f, f))
51     result |= 1;
52   /* Test modf(-Inf,...).
53      This test fails on FreeBSD 6.4, OpenBSD 4.9, IRIX 6.5, OSF/1 5.1.  */
54   f = my_modf (minus_one / zero, &i);
55   if (!(f == 0.0) || (signbitd (minus_zerod) && !signbitd (f)))
56     result |= 2;
57   return result;
58 }
59             ]])],
60             [gl_cv_func_modf_ieee=yes],
61             [gl_cv_func_modf_ieee=no],
62             [gl_cv_func_modf_ieee="guessing no"])
63           LIBS="$save_LIBS"
64         ])
65       case "$gl_cv_func_modf_ieee" in
66         *yes) ;;
67         *) REPLACE_MODF=1 ;;
68       esac
69     fi
70   ])
71   if test $REPLACE_MODF = 1; then
72     dnl Find libraries needed to link lib/modf.c.
73     AC_REQUIRE([gl_FUNC_TRUNC])
74     MODF_LIBM="$TRUNC_LIBM"
75   fi
76 ])