hypot: Prepare for hypotf module.
[gnulib.git] / m4 / fmodl.m4
1 # fmodl.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_FMODL],
8 [
9   m4_divert_text([DEFAULTS], [gl_fmodl_required=plain])
10   AC_REQUIRE([gl_MATH_H_DEFAULTS])
11   AC_REQUIRE([gl_LONG_DOUBLE_VS_DOUBLE])
12   AC_REQUIRE([gl_FUNC_FMOD])
13
14   dnl Test whether fmodl() is declared.
15   dnl AIX 5.1 has fmodl() in libc but doesn't declare it in <math.h>, and the
16   dnl function produces NaN results for finite values.
17   AC_CHECK_DECL([fmodl],
18     [ac_cv_have_decl_fmodl=yes], [ac_cv_have_decl_fmodl=no],
19     [[#include <math.h>]])
20
21   dnl Test whether fmodl() exists. Assume that fmodl(), if it exists, is
22   dnl defined in the same library as fmod().
23   save_LIBS="$LIBS"
24   LIBS="$LIBS $FMOD_LIBM"
25   AC_CHECK_FUNCS([fmodl])
26   LIBS="$save_LIBS"
27   if test $ac_cv_func_fmodl = yes; then
28     FMODL_LIBM="$FMOD_LIBM"
29     if test $ac_cv_have_decl_fmodl = no; then
30       REPLACE_FMODL=1
31     fi
32     m4_ifdef([gl_FUNC_FMODL_IEEE], [
33       if test $gl_fmodl_required = ieee && test $REPLACE_FMODL = 0; then
34         AC_CACHE_CHECK([whether fmodl works according to ISO C 99 with IEC 60559],
35           [gl_cv_func_fmodl_ieee],
36           [
37             save_LIBS="$LIBS"
38             LIBS="$LIBS $FMODL_LIBM"
39             AC_RUN_IFELSE(
40               [AC_LANG_SOURCE([[
41 #ifndef __NO_MATH_INLINES
42 # define __NO_MATH_INLINES 1 /* for glibc */
43 #endif
44 #include <math.h>
45 /* Compare two numbers with ==.
46    This is a separate function because IRIX 6.5 "cc -O" miscompiles an
47    'x == x' test.  */
48 static int
49 numeric_equal (long double x, long double y)
50 {
51   return x == y;
52 }
53 static long double dummy (long double x, long double y) { return 0; }
54 int main (int argc, char *argv[])
55 {
56   long double (*my_fmodl) (long double, long double) = argc ? fmodl : dummy;
57   long double i;
58   long double f;
59   /* Test fmodl(...,0.0L).
60      This test fails on OSF/1 5.1.  */
61   f = my_fmodl (2.0L, 0.0L);
62   if (numeric_equal (f, f))
63     return 1;
64   return 0;
65 }
66               ]])],
67               [gl_cv_func_fmodl_ieee=yes],
68               [gl_cv_func_fmodl_ieee=no],
69               [gl_cv_func_fmodl_ieee="guessing no"])
70             LIBS="$save_LIBS"
71           ])
72         case "$gl_cv_func_fmodl_ieee" in
73           *yes) ;;
74           *) REPLACE_FMODL=1 ;;
75         esac
76       fi
77     ])
78   else
79     HAVE_FMODL=0
80   fi
81   if test $HAVE_FMODL = 0 || test $REPLACE_FMODL = 1; then
82     dnl Find libraries needed to link lib/fmodl.c.
83     if test $HAVE_SAME_LONG_DOUBLE_AS_DOUBLE = 1; then
84       FMODL_LIBM="$FMOD_LIBM"
85     else
86       AC_REQUIRE([gl_FUNC_TRUNCL])
87       AC_REQUIRE([gl_FUNC_FMAL])
88       FMODL_LIBM=
89       dnl Append $TRUNCL_LIBM to FMODL_LIBM, avoiding gratuitous duplicates.
90       case " $FMODL_LIBM " in
91         *" $TRUNCL_LIBM "*) ;;
92         *) FMODL_LIBM="$FMODL_LIBM $TRUNCL_LIBM" ;;
93       esac
94       dnl Append $FMAL_LIBM to FMODL_LIBM, avoiding gratuitous duplicates.
95       case " $FMODL_LIBM " in
96         *" $FMAL_LIBM "*) ;;
97         *) FMODL_LIBM="$FMODL_LIBM $FMAL_LIBM" ;;
98       esac
99     fi
100   fi
101   AC_SUBST([FMODL_LIBM])
102 ])