diff options
author | Bruno Haible <bruno@clisp.org> | 2012-02-25 18:27:46 +0100 |
---|---|---|
committer | Bruno Haible <bruno@clisp.org> | 2012-02-25 18:56:37 +0100 |
commit | 59cd972bd4e6d5a53e31ed175779f24c63d4b6c4 (patch) | |
tree | 2f1bf4951bf4f09c1ae4c42e5f8d1346814a9ec4 /m4/remainder.m4 | |
parent | 157f0eaa5c453d7e1c1c172d1ef808e2ac2dd2d0 (diff) | |
download | gnulib-59cd972bd4e6d5a53e31ed175779f24c63d4b6c4.tar.gz |
remainder: Support for MSVC.
* lib/math.in.h (remainder): New declaration.
* lib/remainder.c: New file.
* m4/remainder.m4: New file.
* modules/remainder (Files): Add lib/remainder.c, m4/remainder.m4.
(Depends-on): Add math, round, fma.
(configure.ac): Use results of gl_FUNC_REMAINDER.
* m4/math_h.m4 (gl_MATH_H): Test whether remainder is declared.
(gl_MATH_H_DEFAULTS): Initialize GNULIB_REMAINDER, HAVE_REMAINDER,
HAVE_DECL_REMAINDER.
* modules/math (Makefile.am): Substitute GNULIB_REMAINDER,
HAVE_REMAINDER, HAVE_DECL_REMAINDER.
* tests/test-math-c++.cc: Check the declaration of remainder.
* doc/posix-functions/remainder.texi: Mention that the MSVC and IRIX 5
problems are fixed.
Diffstat (limited to 'm4/remainder.m4')
-rw-r--r-- | m4/remainder.m4 | 72 |
1 files changed, 72 insertions, 0 deletions
diff --git a/m4/remainder.m4 b/m4/remainder.m4 new file mode 100644 index 0000000000..6cc0001b5f --- /dev/null +++ b/m4/remainder.m4 @@ -0,0 +1,72 @@ +# remainder.m4 serial 1 +dnl Copyright (C) 2012 Free Software Foundation, Inc. +dnl This file is free software; the Free Software Foundation +dnl gives unlimited permission to copy and/or distribute it, +dnl with or without modifications, as long as this notice is preserved. + +AC_DEFUN([gl_FUNC_REMAINDER], +[ + AC_REQUIRE([gl_MATH_H_DEFAULTS]) + + dnl Test whether remainder() is declared. On IRIX 5.3 it is not declared. + AC_CHECK_DECL([remainder], , [HAVE_DECL_REMAINDER=0], [[#include <math.h>]]) + + REMAINDER_LIBM= + AC_CACHE_CHECK([whether remainder() can be used without linking with libm], + [gl_cv_func_remainder_no_libm], + [ + AC_LINK_IFELSE( + [AC_LANG_PROGRAM( + [[#ifndef __NO_MATH_INLINES + # define __NO_MATH_INLINES 1 /* for glibc */ + #endif + #include <math.h> + double x; + double y;]], + [[return remainder (x, y) > 1;]])], + [gl_cv_func_remainder_no_libm=yes], + [gl_cv_func_remainder_no_libm=no]) + ]) + if test $gl_cv_func_remainder_no_libm = no; then + AC_CACHE_CHECK([whether remainder() can be used with libm], + [gl_cv_func_remainder_in_libm], + [ + save_LIBS="$LIBS" + LIBS="$LIBS -lm" + AC_LINK_IFELSE( + [AC_LANG_PROGRAM( + [[#ifndef __NO_MATH_INLINES + # define __NO_MATH_INLINES 1 /* for glibc */ + #endif + #include <math.h> + double x; + double y;]], + [[return remainder (x, y) > 1;]])], + [gl_cv_func_remainder_in_libm=yes], + [gl_cv_func_remainder_in_libm=no]) + LIBS="$save_LIBS" + ]) + if test $gl_cv_func_remainder_in_libm = yes; then + REMAINDER_LIBM=-lm + fi + fi + if test $gl_cv_func_remainder_no_libm = no \ + && test $gl_cv_func_remainder_in_libm = no; then + HAVE_REMAINDER=0 + dnl Find libraries needed to link lib/remainder.c. + AC_REQUIRE([gl_FUNC_ROUND]) + AC_REQUIRE([gl_FUNC_FMA]) + REMAINDER_LIBM= + dnl Append $ROUND_LIBM to REMAINDER_LIBM, avoiding gratuitous duplicates. + case " $REMAINDER_LIBM " in + *" $ROUND_LIBM "*) ;; + *) REMAINDER_LIBM="$REMAINDER_LIBM $ROUND_LIBM" ;; + esac + dnl Append $FMA_LIBM to REMAINDER_LIBM, avoiding gratuitous duplicates. + case " $REMAINDER_LIBM " in + *" $FMA_LIBM "*) ;; + *) REMAINDER_LIBM="$REMAINDER_LIBM $FMA_LIBM" ;; + esac + fi + AC_SUBST([REMAINDER_LIBM]) +]) |