maint: update copyright
[gnulib.git] / m4 / modff.m4
1 # modff.m4 serial 5
2 dnl Copyright (C) 2011-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_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_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
26         AC_CACHE_CHECK([whether modff works according to ISO C 99 with IEC 60559],
27           [gl_cv_func_modff_ieee],
28           [
29             save_LIBS="$LIBS"
30             LIBS="$LIBS $MODFF_LIBM"
31             AC_RUN_IFELSE(
32               [AC_LANG_SOURCE([[
33 #ifndef __NO_MATH_INLINES
34 # define __NO_MATH_INLINES 1 /* for glibc */
35 #endif
36 #include <math.h>
37 ]gl_FLOAT_MINUS_ZERO_CODE[
38 ]gl_FLOAT_SIGNBIT_CODE[
39 /* Compare two numbers with ==.
40    This is a separate function because IRIX 6.5 "cc -O" miscompiles an
41    'x == x' test.  */
42 static int
43 numeric_equal (float x, float y)
44 {
45   return x == y;
46 }
47 static float dummy (float x, float *iptr) { return 0; }
48 float zero;
49 float minus_one = - 1.0f;
50 int main (int argc, char *argv[])
51 {
52   float (*my_modff) (float, float *) = argc ? modff : dummy;
53   int result = 0;
54   float i;
55   float f;
56   /* Test modff(NaN,...).
57      This test fails on NetBSD 5.1, OpenBSD 4.9, Solaris 9, Cygwin.  */
58   f = my_modff (zero / zero, &i);
59   if (numeric_equal (f, f))
60     result |= 1;
61   /* Test modff(-Inf,...).
62      This test fails on IRIX 6.5, OSF/1 5.1, mingw.  */
63   f = my_modff (minus_one / zero, &i);
64   if (!(f == 0.0f) || (signbitf (minus_zerof) && !signbitf (f)))
65     result |= 2;
66   return result;
67 }
68               ]])],
69               [gl_cv_func_modff_ieee=yes],
70               [gl_cv_func_modff_ieee=no],
71               [case "$host_os" in
72                          # Guess yes on glibc systems.
73                  *-gnu*) gl_cv_func_modff_ieee="guessing yes" ;;
74                          # If we don't know, assume the worst.
75                  *)      gl_cv_func_modff_ieee="guessing no" ;;
76                esac
77               ])
78             LIBS="$save_LIBS"
79           ])
80         case "$gl_cv_func_modff_ieee" in
81           *yes) ;;
82           *) REPLACE_MODFF=1 ;;
83         esac
84       fi
85     ])
86   else
87     HAVE_MODFF=0
88   fi
89   if test $HAVE_MODFF = 0 || test $REPLACE_MODFF = 1; then
90     dnl Find libraries needed to link lib/modff.c.
91     MODFF_LIBM="$MODF_LIBM"
92   fi
93   AC_SUBST([MODFF_LIBM])
94 ])