| 1 |
# truncl.m4 |
| 2 |
# serial 20 |
| 3 |
dnl Copyright (C) 2007-2008, 2010-2025 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. |
| 7 |
dnl This file is offered as-is, without any warranty. |
| 8 |
|
| 9 |
AC_DEFUN([gl_FUNC_TRUNCL], |
| 10 |
[ |
| 11 |
m4_divert_text([DEFAULTS], [gl_truncl_required=plain]) |
| 12 |
AC_REQUIRE([gl_MATH_H_DEFAULTS]) |
| 13 |
AC_REQUIRE([gl_LONG_DOUBLE_VS_DOUBLE]) |
| 14 |
AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles |
| 15 |
|
| 16 |
dnl Persuade glibc <math.h> to declare truncl(). |
| 17 |
AC_REQUIRE([gl_USE_SYSTEM_EXTENSIONS]) |
| 18 |
|
| 19 |
dnl Test whether truncl() is declared. |
| 20 |
AC_CHECK_DECLS([truncl], , , [[#include <math.h>]]) |
| 21 |
if test "$ac_cv_have_decl_truncl" = yes; then |
| 22 |
dnl Test whether truncl() can be used without libm. |
| 23 |
TRUNCL_LIBM=? |
| 24 |
AC_LINK_IFELSE( |
| 25 |
[AC_LANG_PROGRAM( |
| 26 |
[[#ifndef __NO_MATH_INLINES |
| 27 |
# define __NO_MATH_INLINES 1 /* for glibc */ |
| 28 |
#endif |
| 29 |
#include <math.h> |
| 30 |
long double (*funcptr) (long double) = truncl; |
| 31 |
long double x;]], |
| 32 |
[[x = funcptr(x) + truncl(x);]])], |
| 33 |
[TRUNCL_LIBM=]) |
| 34 |
if test "$TRUNCL_LIBM" = "?"; then |
| 35 |
saved_LIBS="$LIBS" |
| 36 |
LIBS="$LIBS -lm" |
| 37 |
AC_LINK_IFELSE( |
| 38 |
[AC_LANG_PROGRAM( |
| 39 |
[[#ifndef __NO_MATH_INLINES |
| 40 |
# define __NO_MATH_INLINES 1 /* for glibc */ |
| 41 |
#endif |
| 42 |
#include <math.h> |
| 43 |
long double (*funcptr) (long double) = truncl; |
| 44 |
long double x;]], |
| 45 |
[[x = funcptr(x) + truncl(x);]])], |
| 46 |
[TRUNCL_LIBM="-lm"]) |
| 47 |
LIBS="$saved_LIBS" |
| 48 |
fi |
| 49 |
if test "$TRUNCL_LIBM" = "?"; then |
| 50 |
TRUNCL_LIBM= |
| 51 |
fi |
| 52 |
dnl Test whether truncl() works. It crashes on OSF/1 4.0d. |
| 53 |
saved_LIBS="$LIBS" |
| 54 |
LIBS="$LIBS $TRUNCL_LIBM" |
| 55 |
AC_CACHE_CHECK([whether truncl works], [gl_cv_func_truncl_works], |
| 56 |
[ |
| 57 |
AC_RUN_IFELSE( |
| 58 |
[AC_LANG_SOURCE([[ |
| 59 |
#include <math.h> |
| 60 |
long double x; |
| 61 |
int main() |
| 62 |
{ |
| 63 |
x = truncl (0.0L); |
| 64 |
return 0; |
| 65 |
}]])], |
| 66 |
[gl_cv_func_truncl_works=yes], |
| 67 |
[gl_cv_func_truncl_works=no], |
| 68 |
[case "$host_os" in |
| 69 |
osf4*) gl_cv_func_truncl_works="guessing no" ;; |
| 70 |
# Guess yes on native Windows. |
| 71 |
mingw* | windows*) gl_cv_func_truncl_works="guessing yes" ;; |
| 72 |
*) gl_cv_func_truncl_works="guessing yes" ;; |
| 73 |
esac |
| 74 |
]) |
| 75 |
]) |
| 76 |
LIBS="$saved_LIBS" |
| 77 |
case "$gl_cv_func_truncl_works" in |
| 78 |
*yes) ;; |
| 79 |
*) REPLACE_TRUNCL=1 ;; |
| 80 |
esac |
| 81 |
m4_ifdef([gl_FUNC_TRUNCL_IEEE], [ |
| 82 |
if test $gl_truncl_required = ieee && test $REPLACE_TRUNCL = 0; then |
| 83 |
AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles |
| 84 |
AC_CACHE_CHECK([whether truncl works according to ISO C 99 with IEC 60559], |
| 85 |
[gl_cv_func_truncl_ieee], |
| 86 |
[ |
| 87 |
saved_LIBS="$LIBS" |
| 88 |
LIBS="$LIBS $TRUNCL_LIBM" |
| 89 |
AC_RUN_IFELSE( |
| 90 |
[AC_LANG_SOURCE([[ |
| 91 |
#ifndef __NO_MATH_INLINES |
| 92 |
# define __NO_MATH_INLINES 1 /* for glibc */ |
| 93 |
#endif |
| 94 |
#include <math.h> |
| 95 |
]gl_LONG_DOUBLE_MINUS_ZERO_CODE[ |
| 96 |
]gl_LONG_DOUBLE_SIGNBIT_CODE[ |
| 97 |
static long double dummy (long double f) { return 0; } |
| 98 |
int main (int argc, char *argv[]) |
| 99 |
{ |
| 100 |
long double (* volatile my_truncl) (long double) = argc ? truncl : dummy; |
| 101 |
/* Test whether truncl (-0.3L) is -0.0L. */ |
| 102 |
if (signbitl (minus_zerol) && !signbitl (my_truncl (-0.3L))) |
| 103 |
return 1; |
| 104 |
return 0; |
| 105 |
} |
| 106 |
]])], |
| 107 |
[gl_cv_func_truncl_ieee=yes], |
| 108 |
[gl_cv_func_truncl_ieee=no], |
| 109 |
[case "$host_os" in |
| 110 |
# Guess yes on glibc systems. |
| 111 |
*-gnu* | gnu*) gl_cv_func_truncl_ieee="guessing yes" ;; |
| 112 |
# Guess yes on musl systems. |
| 113 |
*-musl* | midipix*) gl_cv_func_truncl_ieee="guessing yes" ;; |
| 114 |
# Guess yes on native Windows. |
| 115 |
mingw* | windows*) gl_cv_func_truncl_ieee="guessing yes" ;; |
| 116 |
# If we don't know, obey --enable-cross-guesses. |
| 117 |
*) gl_cv_func_truncl_ieee="$gl_cross_guess_normal" ;; |
| 118 |
esac |
| 119 |
]) |
| 120 |
LIBS="$saved_LIBS" |
| 121 |
]) |
| 122 |
case "$gl_cv_func_truncl_ieee" in |
| 123 |
*yes) ;; |
| 124 |
*) REPLACE_TRUNCL=1 ;; |
| 125 |
esac |
| 126 |
fi |
| 127 |
]) |
| 128 |
else |
| 129 |
HAVE_DECL_TRUNCL=0 |
| 130 |
fi |
| 131 |
if test $HAVE_DECL_TRUNCL = 0 || test $REPLACE_TRUNCL = 1; then |
| 132 |
dnl Find libraries needed to link lib/truncl.c. |
| 133 |
if test $HAVE_SAME_LONG_DOUBLE_AS_DOUBLE = 1; then |
| 134 |
AC_REQUIRE([gl_FUNC_TRUNC]) |
| 135 |
TRUNCL_LIBM="$TRUNC_LIBM" |
| 136 |
else |
| 137 |
TRUNCL_LIBM= |
| 138 |
fi |
| 139 |
fi |
| 140 |
AC_SUBST([TRUNCL_LIBM]) |
| 141 |
]) |