update NEWS.stable
[gnulib.git] / m4 / modff.m4
1 # modff.m4 serial 4
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_MODFF],
8 [
9   m4_divert_text([DEFAULTS], [gl_modff_required=plain])
10   AC_REQUIRE([gl_MATH_H_DEFAULTS])
11   AC_REQUIRE([gl_FUNC_MODF])
12
13   dnl Persuade glibc <math.h> to declare modff().
14   AC_REQUIRE([gl_USE_SYSTEM_EXTENSIONS])
15
16   dnl Test whether modff() exists. We cannot assume that modff(), if it
17   dnl exists, is defined in the same library as modf(). This is not the case
18   dnl on FreeBSD, NetBSD, OpenBSD.
19   gl_MATHFUNC([modff], [float], [(float, float *)])
20   if test $gl_cv_func_modff_no_libm = yes \
21      || test $gl_cv_func_modff_in_libm = yes; then
22     :
23     m4_ifdef([gl_FUNC_MODFF_IEEE], [
24       if test $gl_modff_required = ieee && test $REPLACE_MODFF = 0; then
25         AC_CACHE_CHECK([whether modff works according to ISO C 99 with IEC 60559],
26           [gl_cv_func_modff_ieee],
27           [
28             save_LIBS="$LIBS"
29             LIBS="$LIBS $MODFF_LIBM"
30             AC_RUN_IFELSE(
31               [AC_LANG_SOURCE([[
32 #ifndef __NO_MATH_INLINES
33 # define __NO_MATH_INLINES 1 /* for glibc */
34 #endif
35 #include <math.h>
36 ]gl_FLOAT_MINUS_ZERO_CODE[
37 ]gl_FLOAT_SIGNBIT_CODE[
38 /* Compare two numbers with ==.
39    This is a separate function because IRIX 6.5 "cc -O" miscompiles an
40    'x == x' test.  */
41 static int
42 numeric_equal (float x, float y)
43 {
44   return x == y;
45 }
46 static float dummy (float x, float *iptr) { return 0; }
47 float zero;
48 float minus_one = - 1.0f;
49 int main (int argc, char *argv[])
50 {
51   float (*my_modff) (float, float *) = argc ? modff : dummy;
52   int result = 0;
53   float i;
54   float f;
55   /* Test modff(NaN,...).
56      This test fails on NetBSD 5.1, OpenBSD 4.9, Solaris 9, Cygwin.  */
57   f = my_modff (zero / zero, &i);
58   if (numeric_equal (f, f))
59     result |= 1;
60   /* Test modff(-Inf,...).
61      This test fails on IRIX 6.5, OSF/1 5.1, mingw.  */
62   f = my_modff (minus_one / zero, &i);
63   if (!(f == 0.0f) || (signbitf (minus_zerof) && !signbitf (f)))
64     result |= 2;
65   return result;
66 }
67               ]])],
68               [gl_cv_func_modff_ieee=yes],
69               [gl_cv_func_modff_ieee=no],
70               [gl_cv_func_modff_ieee="guessing no"])
71             LIBS="$save_LIBS"
72           ])
73         case "$gl_cv_func_modff_ieee" in
74           *yes) ;;
75           *) REPLACE_MODFF=1 ;;
76         esac
77       fi
78     ])
79   else
80     HAVE_MODFF=0
81   fi
82   if test $HAVE_MODFF = 0 || test $REPLACE_MODFF = 1; then
83     dnl Find libraries needed to link lib/modff.c.
84     MODFF_LIBM="$MODF_LIBM"
85   fi
86   AC_SUBST([MODFF_LIBM])
87 ])