New module 'remainderf'.
[gnulib.git] / m4 / remainderf.m4
1 # remainderf.m4 serial 1
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   AC_REQUIRE([gl_MATH_H_DEFAULTS])
10   AC_REQUIRE([gl_FUNC_REMAINDER])
11
12   dnl Test whether remainderf() exists. Assume that remainderf(), if it exists, is
13   dnl defined in the same library as remainder().
14   save_LIBS="$LIBS"
15   LIBS="$LIBS $REMAINDER_LIBM"
16   AC_CACHE_CHECK([for remainderf],
17     [gl_cv_func_remainderf],
18     [
19       AC_LINK_IFELSE(
20         [AC_LANG_PROGRAM(
21            [[#ifndef __NO_MATH_INLINES
22              # define __NO_MATH_INLINES 1 /* for glibc */
23              #endif
24              #include <math.h>
25              float (*funcptr) (float, float) = remainderf;
26              float x;
27              float y;]],
28            [[return funcptr (x, y) > 1
29                     || remainderf (x, y) > 1;]])],
30         [gl_cv_func_remainderf=yes],
31         [gl_cv_func_remainderf=no])
32     ])
33   LIBS="$save_LIBS"
34   if test $gl_cv_func_remainderf = yes; then
35     REMAINDERF_LIBM="$REMAINDER_LIBM"
36   else
37     HAVE_REMAINDERF=0
38     dnl Find libraries needed to link lib/remainderf.c.
39     if test $gl_cv_func_remainder_no_libm = yes \
40        || test $gl_cv_func_remainder_in_libm = yes; then
41       AC_DEFINE([HAVE_REMAINDER], [1],
42         [Define to 1 if the remainder() function is available in libc or libm.])
43       REMAINDERF_LIBM="$REMAINDER_LIBM"
44     else
45       AC_REQUIRE([gl_FUNC_ROUNDF])
46       AC_REQUIRE([gl_FUNC_FMAF])
47       REMAINDERF_LIBM=
48       dnl Append $ROUNDF_LIBM to REMAINDERF_LIBM, avoiding gratuitous duplicates.
49       case " $REMAINDERF_LIBM " in
50         *" $ROUNDF_LIBM "*) ;;
51         *) REMAINDERF_LIBM="$REMAINDERF_LIBM $ROUNDF_LIBM" ;;
52       esac
53       dnl Append $FMAF_LIBM to REMAINDERF_LIBM, avoiding gratuitous duplicates.
54       case " $REMAINDERF_LIBM " in
55         *" $FMAF_LIBM "*) ;;
56         *) REMAINDERF_LIBM="$REMAINDERF_LIBM $FMAF_LIBM" ;;
57       esac
58     fi
59   fi
60   AC_SUBST([REMAINDERF_LIBM])
61 ])