e2dc60d7fe204db47532217dabab2fc01f8d1c07
[gnulib.git] / m4 / log10f.m4
1 # log10f.m4 serial 4
2 dnl Copyright (C) 2011-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_LOG10F],
8 [
9   m4_divert_text([DEFAULTS], [gl_log10f_required=plain])
10   AC_REQUIRE([gl_MATH_H_DEFAULTS])
11   AC_REQUIRE([gl_FUNC_LOG10])
12
13   dnl Persuade glibc <math.h> to declare log10f().
14   AC_REQUIRE([gl_USE_SYSTEM_EXTENSIONS])
15
16   dnl Test whether log10f() exists. Assume that log10f(), if it exists, is
17   dnl defined in the same library as log10().
18   save_LIBS="$LIBS"
19   LIBS="$LIBS $LOG10_LIBM"
20   AC_CHECK_FUNCS([log10f])
21   LIBS="$save_LIBS"
22   if test $ac_cv_func_log10f = yes; then
23     LOG10F_LIBM="$LOG10_LIBM"
24
25     save_LIBS="$LIBS"
26     LIBS="$LIBS $LOG10F_LIBM"
27     gl_FUNC_LOG10F_WORKS
28     LIBS="$save_LIBS"
29     case "$gl_cv_func_log10f_works" in
30       *yes) ;;
31       *) REPLACE_LOG10F=1 ;;
32     esac
33
34     m4_ifdef([gl_FUNC_LOG10F_IEEE], [
35       if test $gl_log10f_required = ieee && test $REPLACE_LOG10F = 0; then
36         AC_CACHE_CHECK([whether log10f works according to ISO C 99 with IEC 60559],
37           [gl_cv_func_log10f_ieee],
38           [
39             save_LIBS="$LIBS"
40             LIBS="$LIBS $LOGF_LIBM"
41             AC_RUN_IFELSE(
42               [AC_LANG_SOURCE([[
43 #ifndef __NO_MATH_INLINES
44 # define __NO_MATH_INLINES 1 /* for glibc */
45 #endif
46 #include <math.h>
47 /* Compare two numbers with ==.
48    This is a separate function because IRIX 6.5 "cc -O" miscompiles an
49    'x == x' test.  */
50 static int
51 numeric_equal (float x, float y)
52 {
53   return x == y;
54 }
55 static float dummy (float x) { return 0; }
56 int main (int argc, char *argv[])
57 {
58   float (*my_log10f) (float) = argc ? log10f : dummy;
59   /* Test log10f(negative).
60      This test fails on NetBSD 5.1.  */
61   float y = my_log10f (-1.0f);
62   if (numeric_equal (y, y))
63     return 1;
64   return 0;
65 }
66               ]])],
67               [gl_cv_func_log10f_ieee=yes],
68               [gl_cv_func_log10f_ieee=no],
69               [gl_cv_func_log10f_ieee="guessing no"])
70             LIBS="$save_LIBS"
71           ])
72         case "$gl_cv_func_log10f_ieee" in
73           *yes) ;;
74           *) REPLACE_LOG10F=1 ;;
75         esac
76       fi
77     ])
78   else
79     HAVE_LOG10F=0
80   fi
81   if test $HAVE_LOG10F = 0 || test $REPLACE_LOG10F = 1; then
82     dnl Find libraries needed to link lib/log10f.c.
83     if test $HAVE_LOG10F = 0; then
84       LOG10F_LIBM="$LOG10_LIBM"
85     fi
86   fi
87   AC_SUBST([LOG10F_LIBM])
88 ])
89
90 dnl Test whether log10f() works.
91 dnl On OSF/1 5.1, log10f(-0.0f) is NaN.
92 AC_DEFUN([gl_FUNC_LOG10F_WORKS],
93 [
94   AC_REQUIRE([AC_PROG_CC])
95   AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
96   AC_CACHE_CHECK([whether log10f works], [gl_cv_func_log10f_works],
97     [
98       AC_RUN_IFELSE(
99         [AC_LANG_SOURCE([[
100 #include <math.h>
101 volatile float x;
102 float y;
103 int main ()
104 {
105   x = -0.0f;
106   y = log10f (x);
107   if (!(y + y == y))
108     return 1;
109   return 0;
110 }
111 ]])],
112         [gl_cv_func_log10f_works=yes],
113         [gl_cv_func_log10f_works=no],
114         [case "$host_os" in
115            osf*) gl_cv_func_log10f_works="guessing no";;
116            *)    gl_cv_func_log10f_works="guessing yes";;
117          esac
118         ])
119     ])
120 ])