2 dnl Copyright (C) 2007-2008 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_FREXPL],
9 AC_REQUIRE([gl_MATH_H_DEFAULTS])
11 AC_CACHE_CHECK([whether frexpl() can be used without linking with libm],
12 [gl_cv_func_frexpl_no_libm],
14 AC_TRY_LINK([#include <math.h>
16 [int e; return frexpl (x, &e) > 0;],
17 [gl_cv_func_frexpl_no_libm=yes],
18 [gl_cv_func_frexpl_no_libm=no])
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],
26 AC_TRY_LINK([#include <math.h>
28 [int e; return frexpl (x, &e) > 0;],
29 [gl_cv_func_frexpl_in_libm=yes],
30 [gl_cv_func_frexpl_in_libm=no])
33 if test $gl_cv_func_frexpl_in_libm = yes; then
37 if test $gl_cv_func_frexpl_no_libm = yes \
38 || test $gl_cv_func_frexpl_in_libm = yes; then
40 LIBS="$LIBS $FREXPL_LIBM"
43 case "$gl_cv_func_frexpl_works" in
44 *yes) gl_func_frexpl=yes ;;
45 *) gl_func_frexpl=no; REPLACE_FREXPL=1; FREXPL_LIBM= ;;
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>])
60 AC_SUBST([FREXPL_LIBM])
63 AC_DEFUN([gl_FUNC_FREXPL_NO_LIBM],
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],
69 AC_TRY_LINK([#include <math.h>
71 [int e; return frexpl (x, &e) > 0;],
72 [gl_cv_func_frexpl_no_libm=yes],
73 [gl_cv_func_frexpl_no_libm=no])
75 if test $gl_cv_func_frexpl_no_libm = yes; then
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 ;;
82 gl_func_frexpl_no_libm=no
83 dnl Set REPLACE_FREXPL here because the system may have frexpl in libm.
86 if test $gl_func_frexpl_no_libm = yes; then
87 AC_DEFINE([HAVE_FREXPL_IN_LIBC], 1,
88 [Define if the frexpl() function is available in libc.])
89 dnl Also check whether it's declared.
90 dnl MacOS X 10.3 has frexpl() in libc but doesn't declare it in <math.h>.
91 AC_CHECK_DECL([frexpl], , [HAVE_DECL_FREXPL=0], [#include <math.h>])
98 dnl Test whether frexpl() works on finite numbers (this fails on
99 dnl MacOS X 10.4/PowerPC, on AIX 5.1, and on BeOS), on denormalized numbers
100 dnl (this fails on MacOS X 10.5/i386), and also on infinite numbers (this
101 dnl fails e.g. on IRIX 6.5 and mingw).
102 AC_DEFUN([gl_FUNC_FREXPL_WORKS],
104 AC_REQUIRE([AC_PROG_CC])
105 AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
106 AC_CACHE_CHECK([whether frexpl works], [gl_cv_func_frexpl_works],
110 extern long double frexpl (long double, int *);
113 volatile long double x;
114 /* Test on finite numbers that fails on AIX 5.1. */
122 /* Test on finite numbers that fails on MacOS X 10.4, because its frexpl
123 function returns an invalid (incorrectly normalized) value: it returns
124 y = { 0x3fe028f5, 0xc28f5c28, 0x3c9eb851, 0xeb851eb8 }
125 but the correct result is
126 0.505L = { 0x3fe028f5, 0xc28f5c29, 0xbc547ae1, 0x47ae1480 } */
130 long double y = frexpl (x, &exp);
131 if (!(exp == 1 && y == 0.505L))
134 /* Test on large finite numbers. This fails on BeOS at i = 16322, while
135 LDBL_MAX_EXP = 16384.
136 In the loop end test, we test x against Infinity, rather than comparing
137 i with LDBL_MAX_EXP, because BeOS <float.h> has a wrong LDBL_MAX_EXP. */
140 for (i = 1, x = 1.0L; x != x + x; i++, x *= 2.0L)
148 /* Test on denormalized numbers. */
151 for (i = 1, x = 1.0L; i >= LDBL_MIN_EXP; i--, x *= 0.5L)
156 long double y = frexpl (x, &exp);
157 /* On machines with IEEE854 arithmetic: x = 1.68105e-4932,
158 exp = -16382, y = 0.5. On MacOS X 10.5: exp = -16384, y = 0.5. */
159 if (exp != LDBL_MIN_EXP - 1)
163 /* Test on infinite numbers. */
167 long double y = frexpl (x, &exp);
172 }], [gl_cv_func_frexpl_works=yes], [gl_cv_func_frexpl_works=no],
174 aix* | beos* | darwin* | irix* | mingw* | pw*)
175 gl_cv_func_frexpl_works="guessing no";;
176 *) gl_cv_func_frexpl_works="guessing yes";;