maint: don't specify XZ_OPT=-9ev in dist-related rule
[gnulib.git] / m4 / remainderf.m4
1 # remainderf.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_REMAINDERF],
8 [
9   m4_divert_text([DEFAULTS], [gl_remainderf_required=plain])
10   AC_REQUIRE([gl_MATH_H_DEFAULTS])
11   AC_REQUIRE([gl_FUNC_REMAINDER])
12
13   dnl Test whether remainderf() exists. Assume that remainderf(), if it exists, is
14   dnl defined in the same library as remainder().
15   save_LIBS="$LIBS"
16   LIBS="$LIBS $REMAINDER_LIBM"
17   AC_CACHE_CHECK([for remainderf],
18     [gl_cv_func_remainderf],
19     [
20       AC_LINK_IFELSE(
21         [AC_LANG_PROGRAM(
22            [[#ifndef __NO_MATH_INLINES
23              # define __NO_MATH_INLINES 1 /* for glibc */
24              #endif
25              #include <math.h>
26              float (*funcptr) (float, float) = remainderf;
27              float x;
28              float y;]],
29            [[return funcptr (x, y) > 1
30                     || remainderf (x, y) > 1;]])],
31         [gl_cv_func_remainderf=yes],
32         [gl_cv_func_remainderf=no])
33     ])
34   LIBS="$save_LIBS"
35   if test $gl_cv_func_remainderf = yes; then
36     REMAINDERF_LIBM="$REMAINDER_LIBM"
37     m4_ifdef([gl_FUNC_REMAINDERF_IEEE], [
38       if test $gl_remainderf_required = ieee && test $REPLACE_REMAINDERF = 0; then
39         AC_CACHE_CHECK([whether remainderf works according to ISO C 99 with IEC 60559],
40           [gl_cv_func_remainderf_ieee],
41           [
42             save_LIBS="$LIBS"
43             LIBS="$LIBS $REMAINDERF_LIBM"
44             AC_RUN_IFELSE(
45               [AC_LANG_SOURCE([[
46 #ifndef __NO_MATH_INLINES
47 # define __NO_MATH_INLINES 1 /* for glibc */
48 #endif
49 #include <math.h>
50 /* Compare two numbers with ==.
51    This is a separate function because IRIX 6.5 "cc -O" miscompiles an
52    'x == x' test.  */
53 static int
54 numeric_equal (float x, float y)
55 {
56   return x == y;
57 }
58 static float dummy (float x, float y) { return 0; }
59 int main (int argc, char *argv[])
60 {
61   float (*my_remainderf) (float, float) = argc ? remainderf : dummy;
62   float i;
63   float f;
64   /* Test remainderf(...,0.0f).
65      This test fails on OSF/1 5.1.  */
66   f = my_remainderf (2.0f, 0.0f);
67   if (numeric_equal (f, f))
68     return 1;
69   return 0;
70 }
71               ]])],
72               [gl_cv_func_remainderf_ieee=yes],
73               [gl_cv_func_remainderf_ieee=no],
74               [gl_cv_func_remainderf_ieee="guessing no"])
75             LIBS="$save_LIBS"
76           ])
77         case "$gl_cv_func_remainderf_ieee" in
78           *yes) ;;
79           *) REPLACE_REMAINDERF=1 ;;
80         esac
81       fi
82     ])
83   else
84     HAVE_REMAINDERF=0
85   fi
86   if test $HAVE_REMAINDERF = 0 || test $REPLACE_REMAINDERF = 1; then
87     dnl Find libraries needed to link lib/remainderf.c.
88     if test $gl_cv_func_remainder_no_libm = yes \
89        || test $gl_cv_func_remainder_in_libm = yes; then
90       AC_DEFINE([HAVE_REMAINDER], [1],
91         [Define to 1 if the remainder() function is available in libc or libm.])
92       REMAINDERF_LIBM="$REMAINDER_LIBM"
93     else
94       AC_REQUIRE([gl_FUNC_ROUNDF])
95       AC_REQUIRE([gl_FUNC_FMAF])
96       REMAINDERF_LIBM=
97       dnl Append $ROUNDF_LIBM to REMAINDERF_LIBM, avoiding gratuitous duplicates.
98       case " $REMAINDERF_LIBM " in
99         *" $ROUNDF_LIBM "*) ;;
100         *) REMAINDERF_LIBM="$REMAINDERF_LIBM $ROUNDF_LIBM" ;;
101       esac
102       dnl Append $FMAF_LIBM to REMAINDERF_LIBM, avoiding gratuitous duplicates.
103       case " $REMAINDERF_LIBM " in
104         *" $FMAF_LIBM "*) ;;
105         *) REMAINDERF_LIBM="$REMAINDERF_LIBM $FMAF_LIBM" ;;
106       esac
107     fi
108   fi
109   AC_SUBST([REMAINDERF_LIBM])
110 ])