remainder: Support for MSVC.
[gnulib.git] / m4 / remainder.m4
1 # remainder.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_REMAINDER],
8 [
9   AC_REQUIRE([gl_MATH_H_DEFAULTS])
10
11   dnl Test whether remainder() is declared. On IRIX 5.3 it is not declared.
12   AC_CHECK_DECL([remainder], , [HAVE_DECL_REMAINDER=0], [[#include <math.h>]])
13
14   REMAINDER_LIBM=
15   AC_CACHE_CHECK([whether remainder() can be used without linking with libm],
16     [gl_cv_func_remainder_no_libm],
17     [
18       AC_LINK_IFELSE(
19         [AC_LANG_PROGRAM(
20            [[#ifndef __NO_MATH_INLINES
21              # define __NO_MATH_INLINES 1 /* for glibc */
22              #endif
23              #include <math.h>
24              double x;
25              double y;]],
26            [[return remainder (x, y) > 1;]])],
27         [gl_cv_func_remainder_no_libm=yes],
28         [gl_cv_func_remainder_no_libm=no])
29     ])
30   if test $gl_cv_func_remainder_no_libm = no; then
31     AC_CACHE_CHECK([whether remainder() can be used with libm],
32       [gl_cv_func_remainder_in_libm],
33       [
34         save_LIBS="$LIBS"
35         LIBS="$LIBS -lm"
36         AC_LINK_IFELSE(
37           [AC_LANG_PROGRAM(
38              [[#ifndef __NO_MATH_INLINES
39                # define __NO_MATH_INLINES 1 /* for glibc */
40                #endif
41                #include <math.h>
42                double x;
43                double y;]],
44              [[return remainder (x, y) > 1;]])],
45           [gl_cv_func_remainder_in_libm=yes],
46           [gl_cv_func_remainder_in_libm=no])
47         LIBS="$save_LIBS"
48       ])
49     if test $gl_cv_func_remainder_in_libm = yes; then
50       REMAINDER_LIBM=-lm
51     fi
52   fi
53   if test $gl_cv_func_remainder_no_libm = no \
54      && test $gl_cv_func_remainder_in_libm = no; then
55     HAVE_REMAINDER=0
56     dnl Find libraries needed to link lib/remainder.c.
57     AC_REQUIRE([gl_FUNC_ROUND])
58     AC_REQUIRE([gl_FUNC_FMA])
59     REMAINDER_LIBM=
60     dnl Append $ROUND_LIBM to REMAINDER_LIBM, avoiding gratuitous duplicates.
61     case " $REMAINDER_LIBM " in
62       *" $ROUND_LIBM "*) ;;
63       *) REMAINDER_LIBM="$REMAINDER_LIBM $ROUND_LIBM" ;;
64     esac
65     dnl Append $FMA_LIBM to REMAINDER_LIBM, avoiding gratuitous duplicates.
66     case " $REMAINDER_LIBM " in
67       *" $FMA_LIBM "*) ;;
68       *) REMAINDER_LIBM="$REMAINDER_LIBM $FMA_LIBM" ;;
69     esac
70   fi
71   AC_SUBST([REMAINDER_LIBM])
72 ])