remainderl-ieee: Work around test failure on OSF/1.
[gnulib.git] / m4 / remainderl.m4
1 # remainderl.m4 serial 2
2 dnl Copyright (C) 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_REMAINDERL],
8 [
9   m4_divert_text([DEFAULTS], [gl_remainderl_required=plain])
10   AC_REQUIRE([gl_MATH_H_DEFAULTS])
11   AC_REQUIRE([gl_LONG_DOUBLE_VS_DOUBLE])
12   AC_REQUIRE([gl_FUNC_REMAINDER])
13
14   dnl Test whether remainderl() exists. Assume that remainderl(), if it exists, is
15   dnl defined in the same library as remainder().
16   save_LIBS="$LIBS"
17   LIBS="$LIBS $REMAINDER_LIBM"
18   AC_CACHE_CHECK([for remainderl],
19     [gl_cv_func_remainderl],
20     [
21       AC_LINK_IFELSE(
22         [AC_LANG_PROGRAM(
23            [[#ifndef __NO_MATH_INLINES
24              # define __NO_MATH_INLINES 1 /* for glibc */
25              #endif
26              #include <math.h>
27              long double (*funcptr) (long double, long double) = remainderl;
28              long double x;
29              long double y;]],
30            [[return funcptr (x, y) > 1
31                     || remainderl (x, y) > 1;]])],
32         [gl_cv_func_remainderl=yes],
33         [gl_cv_func_remainderl=no])
34     ])
35   LIBS="$save_LIBS"
36   if test $gl_cv_func_remainderl = yes; then
37     REMAINDERL_LIBM="$REMAINDER_LIBM"
38     m4_ifdef([gl_FUNC_REMAINDERL_IEEE], [
39       if test $gl_remainderl_required = ieee && test $REPLACE_REMAINDERL = 0; then
40         AC_CACHE_CHECK([whether remainderl works according to ISO C 99 with IEC 60559],
41           [gl_cv_func_remainderl_ieee],
42           [
43             save_LIBS="$LIBS"
44             LIBS="$LIBS $REMAINDERL_LIBM"
45             AC_RUN_IFELSE(
46               [AC_LANG_SOURCE([[
47 #ifndef __NO_MATH_INLINES
48 # define __NO_MATH_INLINES 1 /* for glibc */
49 #endif
50 #include <math.h>
51 /* Compare two numbers with ==.
52    This is a separate function because IRIX 6.5 "cc -O" miscompiles an
53    'x == x' test.  */
54 static int
55 numeric_equal (long double x, long double y)
56 {
57   return x == y;
58 }
59 static long double dummy (long double x, long double y) { return 0; }
60 int main (int argc, char *argv[])
61 {
62   long double (*my_remainderl) (long double, long double) = argc ? remainderl : dummy;
63   long double i;
64   long double f;
65   /* Test remainderl(...,0.0L).
66      This test fails on OSF/1 5.1.  */
67   f = my_remainderl (2.0L, 0.0L);
68   if (numeric_equal (f, f))
69     return 1;
70   return 0;
71 }
72               ]])],
73               [gl_cv_func_remainderl_ieee=yes],
74               [gl_cv_func_remainderl_ieee=no],
75               [gl_cv_func_remainderl_ieee="guessing no"])
76             LIBS="$save_LIBS"
77           ])
78         case "$gl_cv_func_remainderl_ieee" in
79           *yes) ;;
80           *) REPLACE_REMAINDERL=1 ;;
81         esac
82       fi
83     ])
84   else
85     HAVE_REMAINDERL=0
86   fi
87   if test $HAVE_REMAINDERL = 0 || test $REPLACE_REMAINDERL = 1; then
88     dnl Find libraries needed to link lib/remainderl.c.
89     if test $HAVE_SAME_LONG_DOUBLE_AS_DOUBLE = 1; then
90       REMAINDERL_LIBM="$REMAINDER_LIBM"
91     else
92       AC_REQUIRE([gl_FUNC_ROUNDL])
93       AC_REQUIRE([gl_FUNC_FMAL])
94       REMAINDERL_LIBM=
95       dnl Append $ROUNDL_LIBM to REMAINDERL_LIBM, avoiding gratuitous duplicates.
96       case " $REMAINDERL_LIBM " in
97         *" $ROUNDL_LIBM "*) ;;
98         *) REMAINDERL_LIBM="$REMAINDERL_LIBM $ROUNDL_LIBM" ;;
99       esac
100       dnl Append $FMAL_LIBM to REMAINDERL_LIBM, avoiding gratuitous duplicates.
101       case " $REMAINDERL_LIBM " in
102         *" $FMAL_LIBM "*) ;;
103         *) REMAINDERL_LIBM="$REMAINDERL_LIBM $FMAL_LIBM" ;;
104       esac
105     fi
106   fi
107   AC_SUBST([REMAINDERL_LIBM])
108 ])