3 dnl Copyright (C) 2012-2024 Free Software Foundation, Inc.
4 dnl This file is free software; the Free Software Foundation
5 dnl gives unlimited permission to copy and/or distribute it,
6 dnl with or without modifications, as long as this notice is preserved.
8 AC_DEFUN([gl_FUNC_CBRTL],
10 m4_divert_text([DEFAULTS], [gl_cbrtl_required=plain])
11 AC_REQUIRE([gl_MATH_H_DEFAULTS])
12 AC_REQUIRE([gl_LONG_DOUBLE_VS_DOUBLE])
13 AC_REQUIRE([gl_FUNC_CBRT])
15 dnl Persuade glibc <math.h> to declare cbrtl().
16 AC_REQUIRE([gl_USE_SYSTEM_EXTENSIONS])
18 dnl Test whether cbrtl() exists. Assume that cbrtl(), if it exists, is
19 dnl defined in the same library as cbrt().
21 LIBS="$LIBS $CBRT_LIBM"
22 AC_CHECK_FUNCS([cbrtl])
24 if test $ac_cv_func_cbrtl = yes; then
25 CBRTL_LIBM="$CBRT_LIBM"
26 dnl Also check whether it's declared.
27 dnl IRIX 6.5 has cbrtl() in libm but doesn't declare it in <math.h>.
28 AC_CHECK_DECL([cbrtl], , [HAVE_DECL_CBRTL=0], [[#include <math.h>]])
31 LIBS="$LIBS $CBRTL_LIBM"
34 case "$gl_cv_func_cbrtl_works" in
39 m4_ifdef([gl_FUNC_CBRTL_IEEE], [
40 if test $gl_cbrtl_required = ieee && test $REPLACE_CBRTL = 0; then
41 AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
42 AC_CACHE_CHECK([whether cbrtl works according to ISO C 99 with IEC 60559],
43 [gl_cv_func_cbrtl_ieee],
46 LIBS="$LIBS $CBRTL_LIBM"
49 #ifndef __NO_MATH_INLINES
50 # define __NO_MATH_INLINES 1 /* for glibc */
53 ]gl_LONG_DOUBLE_MINUS_ZERO_CODE[
54 ]gl_LONG_DOUBLE_SIGNBIT_CODE[
55 static long double dummy (long double x) { return 0; }
56 int main (int argc, char *argv[])
62 long double cbrtl (long double);
63 long double (* volatile my_cbrtl) (long double) = argc ? cbrtl : dummy;
66 This test fails on IRIX 6.5. */
67 f = my_cbrtl (minus_zerol);
68 if (!(f == 0.0L) || (signbitl (minus_zerol) && !signbitl (f)))
73 [gl_cv_func_cbrtl_ieee=yes],
74 [gl_cv_func_cbrtl_ieee=no],
76 # Guess yes on glibc systems.
77 *-gnu* | gnu*) gl_cv_func_cbrtl_ieee="guessing yes" ;;
78 # Guess yes on musl systems.
79 *-musl* | midipix*) gl_cv_func_cbrtl_ieee="guessing yes" ;;
80 # Guess yes on native Windows.
81 mingw* | windows*) gl_cv_func_cbrtl_ieee="guessing yes" ;;
82 # If we don't know, obey --enable-cross-guesses.
83 *) gl_cv_func_cbrtl_ieee="$gl_cross_guess_normal" ;;
88 case "$gl_cv_func_cbrtl_ieee" in
98 if test $HAVE_CBRTL = 0 || test $REPLACE_CBRTL = 1; then
99 dnl Find libraries needed to link lib/cbrtl.c.
100 if test $HAVE_SAME_LONG_DOUBLE_AS_DOUBLE = 1; then
101 CBRTL_LIBM="$CBRT_LIBM"
103 AC_REQUIRE([gl_FUNC_FREXPL])
104 AC_REQUIRE([gl_FUNC_LDEXPL])
106 dnl Append $FREXPL_LIBM to CBRTL_LIBM, avoiding gratuitous duplicates.
107 case " $CBRTL_LIBM " in
108 *" $FREXPL_LIBM "*) ;;
109 *) CBRTL_LIBM="$CBRTL_LIBM $FREXPL_LIBM" ;;
111 dnl Append $LDEXPL_LIBM to CBRTL_LIBM, avoiding gratuitous duplicates.
112 case " $CBRTL_LIBM " in
113 *" $LDEXPL_LIBM "*) ;;
114 *) CBRTL_LIBM="$CBRTL_LIBM $LDEXPL_LIBM" ;;
118 AC_SUBST([CBRTL_LIBM])
121 dnl Test whether cbrtl() works.
122 dnl On OpenBSD 5.1/SPARC, cbrtl(16.0L) is = 1.2599...
123 AC_DEFUN([gl_FUNC_CBRTL_WORKS],
125 AC_REQUIRE([AC_PROG_CC])
126 AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
127 AC_CACHE_CHECK([whether cbrtl works], [gl_cv_func_cbrtl_works],
136 long double cbrtl (long double);
137 volatile long double x;
148 [gl_cv_func_cbrtl_works=yes],
149 [gl_cv_func_cbrtl_works=no],
151 openbsd*) gl_cv_func_cbrtl_works="guessing no";;
152 # Guess yes on native Windows.
153 mingw* | windows*) gl_cv_func_cbrtl_works="guessing yes";;
154 *) gl_cv_func_cbrtl_works="guessing yes";;