New module 'frexpl-nolibm'.
[gnulib.git] / m4 / frexpl.m4
1 # frexpl.m4 serial 3
2 dnl Copyright (C) 2007 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_FREXPL],
8 [
9   AC_REQUIRE([gl_MATH_H_DEFAULTS])
10   FREXPL_LIBM=
11   AC_CACHE_CHECK([whether frexpl() can be used without linking with libm],
12     [gl_cv_func_frexpl_no_libm],
13     [
14       AC_TRY_LINK([#include <math.h>
15                    long double x;],
16                   [int e; return frexpl (x, &e) > 0;],
17         [gl_cv_func_frexpl_no_libm=yes],
18         [gl_cv_func_frexpl_no_libm=no])
19     ])
20   if test $gl_cv_func_frexpl_no_libm = no; then
21     AC_CACHE_CHECK([whether frexpl() can be used with libm],
22       [gl_cv_func_frexpl_in_libm],
23       [
24         save_LIBS="$LIBS"
25         LIBS="$LIBS -lm"
26         AC_TRY_LINK([#include <math.h>
27                      long double x;],
28                     [int e; return frexpl (x, &e) > 0;],
29           [gl_cv_func_frexpl_in_libm=yes],
30           [gl_cv_func_frexpl_in_libm=no])
31         LIBS="$save_LIBS"
32       ])
33     if test $gl_cv_func_frexpl_in_libm = yes; then
34       FREXPL_LIBM=-lm
35     fi
36   fi
37   if test $gl_cv_func_frexpl_no_libm = yes \
38      || test $gl_cv_func_frexpl_in_libm = yes; then
39     save_LIBS="$LIBS"
40     LIBS="$LIBS $FREXPL_LIBM"
41     gl_FUNC_FREXPL_WORKS
42     LIBS="$save_LIBS"
43     case "$gl_cv_func_frexpl_works" in
44       *yes) gl_func_frexpl=yes ;;
45       *)    gl_func_frexpl=no; REPLACE_FREXPL=1; FREXPL_LIBM= ;;
46     esac
47   else
48     gl_func_frexpl=no
49   fi
50   if test $gl_func_frexpl = yes; then
51     AC_DEFINE([HAVE_FREXPL], 1,
52       [Define if the frexpl() function is available.])
53     dnl Also check whether it's declared.
54     dnl MacOS X 10.3 has frexpl() in libc but doesn't declare it in <math.h>.
55     AC_CHECK_DECL([frexpl], , [HAVE_DECL_FREXPL=0], [#include <math.h>])
56   else
57     HAVE_DECL_FREXPL=0
58     AC_LIBOBJ([frexpl])
59   fi
60   AC_SUBST([FREXPL_LIBM])
61 ])
62
63 AC_DEFUN([gl_FUNC_FREXPL_NO_LIBM],
64 [
65   AC_REQUIRE([gl_MATH_H_DEFAULTS])
66   AC_CACHE_CHECK([whether frexpl() can be used without linking with libm],
67     [gl_cv_func_frexpl_no_libm],
68     [
69       AC_TRY_LINK([#include <math.h>
70                    long double x;],
71                   [int e; return frexpl (x, &e) > 0;],
72         [gl_cv_func_frexpl_no_libm=yes],
73         [gl_cv_func_frexpl_no_libm=no])
74     ])
75   if test $gl_cv_func_frexpl_no_libm = yes; then
76     gl_FUNC_FREXPL_WORKS
77     case "$gl_cv_func_frexpl_works" in
78       *yes) gl_func_frexpl_no_libm=yes ;;
79       *)    gl_func_frexpl_no_libm=no; REPLACE_FREXPL=1 ;;
80     esac
81   else
82     gl_func_frexpl_no_libm=no
83   fi
84   if test $gl_func_frexpl_no_libm = yes; then
85     AC_DEFINE([HAVE_FREXPL_IN_LIBC], 1,
86       [Define if the frexpl() function is available in libc.])
87     dnl Also check whether it's declared.
88     dnl MacOS X 10.3 has frexpl() in libc but doesn't declare it in <math.h>.
89     AC_CHECK_DECL([frexpl], , [HAVE_DECL_FREXPL=0], [#include <math.h>])
90   else
91     HAVE_DECL_FREXPL=0
92     AC_LIBOBJ([frexpl])
93   fi
94 ])
95
96 dnl Test whether frexpl() works on finite numbers (this fails on AIX 5.1) and
97 dnl also on infinite numbers (this fails e.g. on IRIX 6.5).
98 AC_DEFUN([gl_FUNC_FREXPL_WORKS],
99 [
100   AC_REQUIRE([AC_PROG_CC])
101   AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
102   AC_CACHE_CHECK([whether frexpl works], [gl_cv_func_frexpl_works],
103     [
104       AC_TRY_RUN([
105 #include <math.h>
106 extern long double frexpl (long double, int *);
107 int main()
108 {
109   volatile long double x;
110   /* Test on finite numbers.  */
111   {
112     int exp = -9999;
113     x = 16.0L;
114     frexpl (x, &exp);
115     if (exp != 5)
116       return 1;
117   }
118   /* Test on infinite numbers.  */
119   {
120     x = 1.0L / 0.0L;
121     int exp;
122     long double y = frexpl (x, &exp);
123     if (y != x)
124       return 1;
125   }
126   return 0;
127 }], [gl_cv_func_frexpl_works=yes], [gl_cv_func_frexpl_works=no],
128       [case "$host_os" in
129          aix* | irix*) gl_cv_func_frexpl_works="guessing no";;
130          *)            gl_cv_func_frexpl_works="guessing yes";;
131        esac
132       ])
133     ])
134 ])