1 # remainderf.m4 serial 6
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.
7 AC_DEFUN([gl_FUNC_REMAINDERF],
9 m4_divert_text([DEFAULTS], [gl_remainderf_required=plain])
10 AC_REQUIRE([gl_MATH_H_DEFAULTS])
11 AC_REQUIRE([gl_FUNC_REMAINDER])
13 dnl Persuade glibc <math.h> to declare remainderf().
14 AC_REQUIRE([gl_USE_SYSTEM_EXTENSIONS])
16 dnl Test whether remainderf() exists. Assume that remainderf(), if it exists, is
17 dnl defined in the same library as remainder().
19 LIBS="$LIBS $REMAINDER_LIBM"
20 AC_CACHE_CHECK([for remainderf],
21 [gl_cv_func_remainderf],
25 [[#ifndef __NO_MATH_INLINES
26 # define __NO_MATH_INLINES 1 /* for glibc */
33 float remainderf (float, float);
34 float (*funcptr) (float, float) = remainderf;
37 [[return funcptr (x, y) > 1
38 || remainderf (x, y) > 1;]])],
39 [gl_cv_func_remainderf=yes],
40 [gl_cv_func_remainderf=no])
43 if test $gl_cv_func_remainderf = yes; then
44 REMAINDERF_LIBM="$REMAINDER_LIBM"
47 LIBS="$LIBS $REMAINDERF_LIBM"
48 gl_FUNC_REMAINDERF_WORKS
50 case "$gl_cv_func_remainderf_works" in
52 *) REPLACE_REMAINDERF=1 ;;
55 m4_ifdef([gl_FUNC_REMAINDERF_IEEE], [
56 if test $gl_remainderf_required = ieee && test $REPLACE_REMAINDERF = 0; then
57 AC_CACHE_CHECK([whether remainderf works according to ISO C 99 with IEC 60559],
58 [gl_cv_func_remainderf_ieee],
61 LIBS="$LIBS $REMAINDERF_LIBM"
64 #ifndef __NO_MATH_INLINES
65 # define __NO_MATH_INLINES 1 /* for glibc */
72 float remainderf (float, float);
73 /* Compare two numbers with ==.
74 This is a separate function because IRIX 6.5 "cc -O" miscompiles an
77 numeric_equal (float x, float y)
81 static float dummy (float x, float y) { return 0; }
82 int main (int argc, char *argv[])
84 float (*my_remainderf) (float, float) = argc ? remainderf : dummy;
86 /* Test remainderf(...,0.0f).
87 This test fails on OSF/1 5.1. */
88 f = my_remainderf (2.0f, 0.0f);
89 if (numeric_equal (f, f))
94 [gl_cv_func_remainderf_ieee=yes],
95 [gl_cv_func_remainderf_ieee=no],
96 [gl_cv_func_remainderf_ieee="guessing no"])
99 case "$gl_cv_func_remainderf_ieee" in
101 *) REPLACE_REMAINDERF=1 ;;
108 if test $HAVE_REMAINDERF = 0 || test $REPLACE_REMAINDERF = 1; then
109 dnl Find libraries needed to link lib/remainderf.c.
110 if test $gl_cv_func_remainder_no_libm = yes \
111 || test $gl_cv_func_remainder_in_libm = yes; then
112 AC_DEFINE([HAVE_REMAINDER], [1],
113 [Define to 1 if the remainder() function is available in libc or libm.])
114 REMAINDERF_LIBM="$REMAINDER_LIBM"
116 AC_REQUIRE([gl_FUNC_FABSF])
117 AC_REQUIRE([gl_FUNC_FMODF])
118 AC_REQUIRE([gl_FUNC_ISNANF])
120 dnl Append $FABSF_LIBM to REMAINDERF_LIBM, avoiding gratuitous duplicates.
121 case " $REMAINDERF_LIBM " in
122 *" $FABSF_LIBM "*) ;;
123 *) REMAINDERF_LIBM="$REMAINDERF_LIBM $FABSF_LIBM" ;;
125 dnl Append $FMODF_LIBM to REMAINDERF_LIBM, avoiding gratuitous duplicates.
126 case " $REMAINDERF_LIBM " in
127 *" $FMODF_LIBM "*) ;;
128 *) REMAINDERF_LIBM="$REMAINDERF_LIBM $FMODF_LIBM" ;;
130 dnl Append $ISNANF_LIBM to REMAINDERF_LIBM, avoiding gratuitous duplicates.
131 case " $REMAINDERF_LIBM " in
132 *" $ISNANF_LIBM "*) ;;
133 *) REMAINDERF_LIBM="$REMAINDERF_LIBM $ISNANF_LIBM" ;;
137 AC_SUBST([REMAINDERF_LIBM])
140 dnl Test whether remainderf() works.
141 dnl It runs into an endless loop on IRIX 6.5.
142 AC_DEFUN([gl_FUNC_REMAINDERF_WORKS],
144 AC_REQUIRE([AC_PROG_CC])
145 AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
146 AC_CHECK_FUNCS_ONCE([alarm])
147 AC_CACHE_CHECK([whether remainderf works], [gl_cv_func_remainderf_works],
159 float remainderf (float, float);
168 /* This test fails on IRIX 6.5. */
171 z = remainderf (x, y);
175 [gl_cv_func_remainderf_works=yes],
176 [gl_cv_func_remainderf_works=no],
178 irix*) gl_cv_func_remainderf_works="guessing no";;
179 *) gl_cv_func_remainderf_works="guessing yes";;