1 # remainderl.m4 serial 8
2 dnl Copyright (C) 2012-2017 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_REMAINDERL],
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])
14 dnl Persuade glibc <math.h> to declare remainderl().
15 AC_REQUIRE([gl_USE_SYSTEM_EXTENSIONS])
17 dnl Test whether remainderl() exists. Assume that remainderl(), if it exists, is
18 dnl defined in the same library as remainder().
20 LIBS="$LIBS $REMAINDER_LIBM"
21 AC_CACHE_CHECK([for remainderl],
22 [gl_cv_func_remainderl],
26 [[#ifndef __NO_MATH_INLINES
27 # define __NO_MATH_INLINES 1 /* for glibc */
34 long double remainderl (long double, long double);
35 long double (*funcptr) (long double, long double) = remainderl;
38 [[return funcptr (x, y) > 1
39 || remainderl (x, y) > 1;]])],
40 [gl_cv_func_remainderl=yes],
41 [gl_cv_func_remainderl=no])
44 if test $gl_cv_func_remainderl = yes; then
46 REMAINDERL_LIBM="$REMAINDER_LIBM"
47 dnl Also check whether it's declared.
48 dnl IRIX 6.5 has remainderl() in libm but doesn't declare it in <math.h>.
49 AC_CHECK_DECLS([remainderl], , [HAVE_DECL_REMAINDERL=0], [[#include <math.h>]])
52 LIBS="$LIBS $REMAINDERL_LIBM"
53 gl_FUNC_REMAINDERL_WORKS
55 case "$gl_cv_func_remainderl_works" in
57 *) REPLACE_REMAINDERL=1 ;;
60 m4_ifdef([gl_FUNC_REMAINDERL_IEEE], [
61 if test $gl_remainderl_required = ieee && test $REPLACE_REMAINDERL = 0; then
62 AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
63 AC_CACHE_CHECK([whether remainderl works according to ISO C 99 with IEC 60559],
64 [gl_cv_func_remainderl_ieee],
67 LIBS="$LIBS $REMAINDERL_LIBM"
70 #ifndef __NO_MATH_INLINES
71 # define __NO_MATH_INLINES 1 /* for glibc */
78 long double remainderl (long double, long double);
79 /* Compare two numbers with ==.
80 This is a separate function because IRIX 6.5 "cc -O" miscompiles an
83 numeric_equal (long double x, long double y)
87 static long double dummy (long double x, long double y) { return 0; }
88 int main (int argc, char *argv[])
90 long double (*my_remainderl) (long double, long double) = argc ? remainderl : dummy;
92 /* Test remainderl(...,0.0L).
93 This test fails on OSF/1 5.1. */
94 f = my_remainderl (2.0L, 0.0L);
95 if (numeric_equal (f, f))
100 [gl_cv_func_remainderl_ieee=yes],
101 [gl_cv_func_remainderl_ieee=no],
103 # Guess yes on glibc systems.
104 *-gnu*) gl_cv_func_remainderl_ieee="guessing yes" ;;
105 # Guess yes on native Windows.
106 mingw*) gl_cv_func_remainderl_ieee="guessing yes" ;;
107 # If we don't know, assume the worst.
108 *) gl_cv_func_remainderl_ieee="guessing no" ;;
113 case "$gl_cv_func_remainderl_ieee" in
115 *) REPLACE_REMAINDERL=1 ;;
121 HAVE_DECL_REMAINDERL=0
123 if test $HAVE_REMAINDERL = 0 || test $REPLACE_REMAINDERL = 1; then
124 dnl Find libraries needed to link lib/remainderl.c.
125 if test $HAVE_SAME_LONG_DOUBLE_AS_DOUBLE = 1; then
126 REMAINDERL_LIBM="$REMAINDER_LIBM"
128 AC_REQUIRE([gl_FUNC_FABSL])
129 AC_REQUIRE([gl_FUNC_FMODL])
130 AC_REQUIRE([gl_FUNC_ISNANL])
132 dnl Append $FABSL_LIBM to REMAINDERL_LIBM, avoiding gratuitous duplicates.
133 case " $REMAINDERL_LIBM " in
134 *" $FABSL_LIBM "*) ;;
135 *) REMAINDERL_LIBM="$REMAINDERL_LIBM $FABSL_LIBM" ;;
137 dnl Append $FMODL_LIBM to REMAINDERL_LIBM, avoiding gratuitous duplicates.
138 case " $REMAINDERL_LIBM " in
139 *" $FMODL_LIBM "*) ;;
140 *) REMAINDERL_LIBM="$REMAINDERL_LIBM $FMODL_LIBM" ;;
142 dnl Append $ISNANL_LIBM to REMAINDERL_LIBM, avoiding gratuitous duplicates.
143 case " $REMAINDERL_LIBM " in
144 *" $ISNANL_LIBM "*) ;;
145 *) REMAINDERL_LIBM="$REMAINDERL_LIBM $ISNANL_LIBM" ;;
149 AC_SUBST([REMAINDERL_LIBM])
152 dnl Test whether remainderl() works.
153 dnl It produces completely wrong values on OpenBSD 5.1/SPARC.
154 AC_DEFUN([gl_FUNC_REMAINDERL_WORKS],
156 AC_REQUIRE([AC_PROG_CC])
157 AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
158 AC_CACHE_CHECK([whether remainderl works], [gl_cv_func_remainderl_works],
162 #ifndef __NO_MATH_INLINES
163 # define __NO_MATH_INLINES 1 /* for glibc */
170 long double remainderl (long double, long double);
171 volatile long double x;
172 volatile long double y;
176 /* This test fails on OpenBSD 5.1/SPARC. */
179 z = remainderl (x, y);
185 [gl_cv_func_remainderl_works=yes],
186 [gl_cv_func_remainderl_works=no],
188 openbsd*) gl_cv_func_remainderl_works="guessing no" ;;
189 # Guess yes on native Windows.
190 mingw*) gl_cv_func_remainderl_works="guessing yes" ;;
191 *) gl_cv_func_remainderl_works="guessing yes" ;;