summaryrefslogtreecommitdiff
path: root/m4/logbl.m4
blob: ef38e80ba3f6510084be457a56258ef67bf4b56b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
# logbl.m4 serial 5
dnl Copyright (C) 2012-2023 Free Software Foundation, Inc.
dnl This file is free software; the Free Software Foundation
dnl gives unlimited permission to copy and/or distribute it,
dnl with or without modifications, as long as this notice is preserved.

AC_DEFUN([gl_FUNC_LOGBL],
[
  AC_REQUIRE([gl_MATH_H_DEFAULTS])
  AC_REQUIRE([gl_LONG_DOUBLE_VS_DOUBLE])
  AC_REQUIRE([gl_FUNC_LOGB])

  dnl Persuade glibc <math.h> to declare logbl().
  AC_REQUIRE([gl_USE_SYSTEM_EXTENSIONS])

  dnl Test whether logbl() exists and determine LOGBL_LIBM. We cannot assume
  dnl that logbl(), if it exists, is defined in the same library as logb().
  dnl This is not the case on AIX >= 5.2, Solaris >= 10.
  gl_MATHFUNC([logbl], [long double], [(long double)])
  if test $gl_cv_func_logbl_no_libm = yes \
     || test $gl_cv_func_logbl_in_libm = yes; then
    save_LIBS="$LIBS"
    LIBS="$LIBS $LOGBL_LIBM"
    gl_FUNC_LOGBL_WORKS
    LIBS="$save_LIBS"
    case "$gl_cv_func_logbl_works" in
      *yes) ;;
      *) REPLACE_LOGBL=1 ;;
    esac
  else
    HAVE_LOGBL=0
  fi
  if test $HAVE_LOGBL = 0 || test $REPLACE_LOGBL = 1; then
    dnl Find libraries needed to link lib/logbl.c.
    if test $HAVE_SAME_LONG_DOUBLE_AS_DOUBLE = 1; then
      LOGBL_LIBM="$LOGB_LIBM"
    else
      AC_REQUIRE([gl_FUNC_FREXPL])
      AC_REQUIRE([gl_FUNC_ISNANL])
      LOGBL_LIBM=
      dnl Append $FREXPL_LIBM to LOGBL_LIBM, avoiding gratuitous duplicates.
      case " $LOGBL_LIBM " in
        *" $FREXPL_LIBM "*) ;;
        *) LOGBL_LIBM="$LOGBL_LIBM $FREXPL_LIBM" ;;
      esac
      dnl Append $ISNANL_LIBM to LOGBL_LIBM, avoiding gratuitous duplicates.
      case " $LOGBL_LIBM " in
        *" $ISNANL_LIBM "*) ;;
        *) LOGBL_LIBM="$LOGBL_LIBM $ISNANL_LIBM" ;;
      esac
    fi
  fi
  AC_SUBST([LOGBL_LIBM])
])

dnl Test whether logbl() works.
dnl On glibc 2.11/powerpc, glibc 2.7/sparc, glibc 2.7/hppa, Solaris 10/SPARC,
dnl Solaris 11.4/x86_64, the return value for subnormal (denormalized) arguments
dnl is too large.
dnl On glibc 2.23/powerpc64le, the return value for negative subnormal arguments
dnl is too large.
AC_DEFUN([gl_FUNC_LOGBL_WORKS],
[
  AC_REQUIRE([AC_PROG_CC])
  AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
  AC_CACHE_CHECK([whether logbl works], [gl_cv_func_logbl_works],
    [
      AC_RUN_IFELSE(
        [AC_LANG_SOURCE([[
#include <float.h>
#include <math.h>
/* Override the values of <float.h>, like done in float.in.h.  */
#if defined __i386__ && (defined __BEOS__ || defined __OpenBSD__)
# undef LDBL_MIN_EXP
# define LDBL_MIN_EXP    (-16381)
#endif
#if defined __i386__ && (defined __FreeBSD__ || defined __DragonFly__)
# undef LDBL_MIN_EXP
# define LDBL_MIN_EXP    (-16381)
#endif
#if (defined _ARCH_PPC || defined _POWER) && defined _AIX && (LDBL_MANT_DIG == 106) && defined __GNUC__
# undef LDBL_MIN_EXP
# define LDBL_MIN_EXP DBL_MIN_EXP
#endif
#if defined __sgi && (LDBL_MANT_DIG >= 106)
# if defined __GNUC__
#  undef LDBL_MIN_EXP
#  define LDBL_MIN_EXP DBL_MIN_EXP
# endif
#endif
volatile long double x;
int main ()
{
  int i;
  for (i = 1, x = 1.0L; i >= LDBL_MIN_EXP - 54; i--, x *= 0.5L)
    /* Either x = 2^(i-1) or x = 0.0.  */
    if ((i == LDBL_MIN_EXP - 1 || i == LDBL_MIN_EXP - 54)
        && (x > 0.0L && !(logbl (x) == (long double)(i - 1))))
      return 1;
  for (i = 1, x = -1.0L; i >= LDBL_MIN_EXP - 54; i--, x *= 0.5L)
    /* Either x = -2^(i-1) or x = 0.0.  */
    if ((i == LDBL_MIN_EXP - 1 || i == LDBL_MIN_EXP - 54)
        && (x < 0.0L && !(logbl (x) == (long double)(i - 1))))
      return 1;
  return 0;
}
]])],
        [gl_cv_func_logbl_works=yes],
        [gl_cv_func_logbl_works=no],
        [case "$host_os" in
           *gnu* | solaris*) gl_cv_func_logbl_works="guessing no" ;;
                             # Guess yes on native Windows.
           mingw*)           gl_cv_func_logbl_works="guessing yes" ;;
           *)                gl_cv_func_logbl_works="guessing yes" ;;
         esac
        ])
    ])
])