summaryrefslogtreecommitdiff
path: root/m4/ilogbf.m4
diff options
context:
space:
mode:
authorBruno Haible <bruno@clisp.org>2012-04-03 21:13:26 +0200
committerBruno Haible <bruno@clisp.org>2012-04-03 21:14:16 +0200
commitd6d7a9dc245badda81a34e336dda7baaeee78322 (patch)
tree3392d28d0bf27211ae246208ed2620f2c9deed42 /m4/ilogbf.m4
parent2d538ff2c61e29c9a323b5e0f300ccc3610cebab (diff)
downloadgnulib-d6d7a9dc245badda81a34e336dda7baaeee78322.tar.gz
New module 'ilogbf'.
* lib/math.in.h (ilogbf): New declaration. * lib/ilogbf.c: New file. * m4/ilogbf.m4: New file. * m4/math_h.m4 (gl_MATH_H): Test whether ilogbf is declared. (gl_MATH_H_DEFAULTS): Initialize GNULIB_ILOGBF, HAVE_ILOGBF, REPLACE_ILOGBF. * modules/math (Makefile.am): Substitute GNULIB_ILOGBF, HAVE_ILOGBF, REPLACE_ILOGBF. * modules/ilogbf: New file. * tests/test-math-c++.cc: Check the declaration of ilogbf. * doc/posix-functions/ilogbf.texi: Mention the new module.
Diffstat (limited to 'm4/ilogbf.m4')
-rw-r--r--m4/ilogbf.m4107
1 files changed, 107 insertions, 0 deletions
diff --git a/m4/ilogbf.m4 b/m4/ilogbf.m4
new file mode 100644
index 0000000000..1044dfa283
--- /dev/null
+++ b/m4/ilogbf.m4
@@ -0,0 +1,107 @@
+# ilogbf.m4 serial 1
+dnl Copyright (C) 2010-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_ILOGBF],
+[
+ AC_REQUIRE([gl_MATH_H_DEFAULTS])
+
+ dnl Persuade glibc <math.h> to declare ilogbf().
+ AC_REQUIRE([gl_USE_SYSTEM_EXTENSIONS])
+
+ dnl Determine ILOGBF_LIBM.
+ gl_MATHFUNC([ilogbf], [int], [(float)])
+ if test $gl_cv_func_ilogbf_no_libm = yes \
+ || test $gl_cv_func_ilogbf_in_libm = yes; then
+ save_LIBS="$LIBS"
+ LIBS="$LIBS $ILOGBF_LIBM"
+ gl_FUNC_ILOGBF_WORKS
+ LIBS="$save_LIBS"
+ case "$gl_cv_func_ilogbf_works" in
+ *yes) ;;
+ *) REPLACE_ILOGBF=1 ;;
+ esac
+ else
+ HAVE_ILOGBF=0
+ fi
+ if test $HAVE_ILOGBF = 0 || test $REPLACE_ILOGBF = 1; then
+ dnl Find libraries needed to link lib/ilogbf.c.
+ AC_REQUIRE([gl_FUNC_FREXPF])
+ AC_REQUIRE([gl_FUNC_ISNANF])
+ ILOGBF_LIBM=
+ dnl Append $FREXPF_LIBM to ILOGBF_LIBM, avoiding gratuitous duplicates.
+ case " $ILOGBF_LIBM " in
+ *" $FREXPF_LIBM "*) ;;
+ *) ILOGBF_LIBM="$ILOGBF_LIBM $FREXPF_LIBM" ;;
+ esac
+ dnl Append $ISNANF_LIBM to ILOGBF_LIBM, avoiding gratuitous duplicates.
+ case " $ILOGBF_LIBM " in
+ *" $ISNANF_LIBM "*) ;;
+ *) ILOGBF_LIBM="$ILOGBF_LIBM $ISNANF_LIBM" ;;
+ esac
+ fi
+ AC_SUBST([ILOGBF_LIBM])
+])
+
+dnl Test whether ilogbf() works.
+dnl On OpenBSD 4.9, ilogbf(0.0) is wrong.
+dnl On NetBSD 5.1, OpenBSD 4.9, ilogbf(Infinity) is wrong.
+AC_DEFUN([gl_FUNC_ILOGBF_WORKS],
+[
+ AC_REQUIRE([AC_PROG_CC])
+ AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
+ AC_CACHE_CHECK([whether ilogbf works], [gl_cv_func_ilogbf_works],
+ [
+ AC_RUN_IFELSE(
+ [AC_LANG_SOURCE([[
+#include <limits.h>
+#include <math.h>
+/* Provide FP_ILOGB0, FP_ILOGBNAN, like in math.in.h. */
+#if !(defined FP_ILOGB0 && defined FP_ILOGBNAN)
+# if defined __NetBSD__ || defined __sgi
+ /* NetBSD, IRIX 6.5: match what ilogbf() does */
+# define FP_ILOGB0 INT_MIN
+# define FP_ILOGBNAN INT_MIN
+# elif defined _AIX
+ /* AIX 5.1: match what ilogbf() does in AIX >= 5.2 */
+# define FP_ILOGB0 INT_MIN
+# define FP_ILOGBNAN INT_MAX
+# elif defined __sun
+ /* Solaris 9: match what ilogbf() does */
+# define FP_ILOGB0 (- INT_MAX)
+# define FP_ILOGBNAN INT_MAX
+# endif
+#endif
+volatile float x;
+static float zero;
+static int dummy (float x) { return 0; }
+int main (int argc, char *argv[])
+{
+ int (*my_ilogbf) (float) = argc ? ilogbf : dummy;
+ int result = 0;
+ /* This test fails on OpenBSD 4.9. */
+ {
+ x = 0.0f;
+ if (my_ilogbf (x) != FP_ILOGB0)
+ result |= 1;
+ }
+ /* This test fails on NetBSD 5.1, OpenBSD 4.9. */
+ {
+ x = 1.0f / zero;
+ if (my_ilogbf (x) != INT_MAX)
+ result |= 2;
+ }
+ return result;
+}
+]])],
+ [gl_cv_func_ilogbf_works=yes],
+ [gl_cv_func_ilogbf_works=no],
+ [case "$host_os" in
+ openbsd* | netbsd*) gl_cv_func_ilogbf_works="guessing no";;
+ *) gl_cv_func_ilogbf_works="guessing yes";;
+ esac
+ ])
+ ])
+])