Home | History | Annotate | Line # | Download | only in m4
      1      1.1  christos # frexp.m4 serial 16
      2  1.1.1.2  christos dnl Copyright (C) 2007-2022 Free Software Foundation, Inc.
      3      1.1  christos dnl This file is free software; the Free Software Foundation
      4      1.1  christos dnl gives unlimited permission to copy and/or distribute it,
      5      1.1  christos dnl with or without modifications, as long as this notice is preserved.
      6      1.1  christos 
      7      1.1  christos AC_DEFUN([gl_FUNC_FREXP],
      8      1.1  christos [
      9      1.1  christos   AC_REQUIRE([gl_MATH_H_DEFAULTS])
     10      1.1  christos   AC_REQUIRE([gl_CHECK_FREXP_NO_LIBM])
     11      1.1  christos   FREXP_LIBM=
     12      1.1  christos   if test $gl_cv_func_frexp_no_libm = no; then
     13      1.1  christos     AC_CACHE_CHECK([whether frexp() can be used with libm],
     14      1.1  christos       [gl_cv_func_frexp_in_libm],
     15      1.1  christos       [
     16      1.1  christos         save_LIBS="$LIBS"
     17      1.1  christos         LIBS="$LIBS -lm"
     18      1.1  christos         AC_LINK_IFELSE(
     19      1.1  christos           [AC_LANG_PROGRAM(
     20      1.1  christos              [[#include <math.h>
     21      1.1  christos                double x;]],
     22      1.1  christos              [[int e; return frexp (x, &e) > 0;]])],
     23      1.1  christos           [gl_cv_func_frexp_in_libm=yes],
     24      1.1  christos           [gl_cv_func_frexp_in_libm=no])
     25      1.1  christos         LIBS="$save_LIBS"
     26      1.1  christos       ])
     27      1.1  christos     if test $gl_cv_func_frexp_in_libm = yes; then
     28      1.1  christos       FREXP_LIBM=-lm
     29      1.1  christos     fi
     30      1.1  christos   fi
     31      1.1  christos   if test $gl_cv_func_frexp_no_libm = yes \
     32      1.1  christos      || test $gl_cv_func_frexp_in_libm = yes; then
     33      1.1  christos     save_LIBS="$LIBS"
     34      1.1  christos     LIBS="$LIBS $FREXP_LIBM"
     35      1.1  christos     gl_FUNC_FREXP_WORKS
     36      1.1  christos     LIBS="$save_LIBS"
     37      1.1  christos     case "$gl_cv_func_frexp_works" in
     38      1.1  christos       *yes) gl_func_frexp=yes ;;
     39      1.1  christos       *)    gl_func_frexp=no; REPLACE_FREXP=1; FREXP_LIBM= ;;
     40      1.1  christos     esac
     41      1.1  christos   else
     42      1.1  christos     gl_func_frexp=no
     43      1.1  christos   fi
     44      1.1  christos   if test $gl_func_frexp = yes; then
     45      1.1  christos     AC_DEFINE([HAVE_FREXP], [1],
     46      1.1  christos       [Define if the frexp() function is available and works.])
     47      1.1  christos   fi
     48      1.1  christos   AC_SUBST([FREXP_LIBM])
     49      1.1  christos ])
     50      1.1  christos 
     51      1.1  christos AC_DEFUN([gl_FUNC_FREXP_NO_LIBM],
     52      1.1  christos [
     53      1.1  christos   AC_REQUIRE([gl_MATH_H_DEFAULTS])
     54      1.1  christos   AC_REQUIRE([gl_CHECK_FREXP_NO_LIBM])
     55      1.1  christos   if test $gl_cv_func_frexp_no_libm = yes; then
     56      1.1  christos     gl_FUNC_FREXP_WORKS
     57      1.1  christos     case "$gl_cv_func_frexp_works" in
     58      1.1  christos       *yes) gl_func_frexp_no_libm=yes ;;
     59      1.1  christos       *)    gl_func_frexp_no_libm=no; REPLACE_FREXP=1 ;;
     60      1.1  christos     esac
     61      1.1  christos   else
     62      1.1  christos     gl_func_frexp_no_libm=no
     63      1.1  christos     dnl Set REPLACE_FREXP here because the system may have frexp in libm.
     64      1.1  christos     REPLACE_FREXP=1
     65      1.1  christos   fi
     66      1.1  christos   if test $gl_func_frexp_no_libm = yes; then
     67      1.1  christos     AC_DEFINE([HAVE_FREXP_IN_LIBC], [1],
     68      1.1  christos       [Define if the frexp() function is available in libc.])
     69      1.1  christos   fi
     70      1.1  christos ])
     71      1.1  christos 
     72      1.1  christos dnl Test whether frexp() can be used without linking with libm.
     73      1.1  christos dnl Set gl_cv_func_frexp_no_libm to 'yes' or 'no' accordingly.
     74      1.1  christos AC_DEFUN([gl_CHECK_FREXP_NO_LIBM],
     75      1.1  christos [
     76      1.1  christos   AC_CACHE_CHECK([whether frexp() can be used without linking with libm],
     77      1.1  christos     [gl_cv_func_frexp_no_libm],
     78      1.1  christos     [
     79      1.1  christos       AC_LINK_IFELSE(
     80      1.1  christos         [AC_LANG_PROGRAM(
     81      1.1  christos            [[#include <math.h>
     82      1.1  christos              double x;]],
     83      1.1  christos            [[int e; return frexp (x, &e) > 0;]])],
     84      1.1  christos         [gl_cv_func_frexp_no_libm=yes],
     85      1.1  christos         [gl_cv_func_frexp_no_libm=no])
     86      1.1  christos     ])
     87      1.1  christos ])
     88      1.1  christos 
     89      1.1  christos dnl Test whether frexp() works also on denormalized numbers (this fails e.g. on
     90      1.1  christos dnl NetBSD 3.0), on infinite numbers (this fails e.g. on IRIX 6.5 and mingw),
     91      1.1  christos dnl and on negative zero (this fails e.g. on NetBSD 4.99 and mingw).
     92      1.1  christos AC_DEFUN([gl_FUNC_FREXP_WORKS],
     93      1.1  christos [
     94      1.1  christos   AC_REQUIRE([AC_PROG_CC])
     95      1.1  christos   AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
     96      1.1  christos   AC_CHECK_DECLS_ONCE([alarm])
     97      1.1  christos   AC_CACHE_CHECK([whether frexp works], [gl_cv_func_frexp_works],
     98      1.1  christos     [
     99      1.1  christos       AC_RUN_IFELSE(
    100      1.1  christos         [AC_LANG_SOURCE([[
    101      1.1  christos #include <float.h>
    102      1.1  christos #include <math.h>
    103      1.1  christos #include <string.h>
    104      1.1  christos #if HAVE_DECL_ALARM
    105      1.1  christos # include <signal.h>
    106      1.1  christos # include <unistd.h>
    107      1.1  christos #endif
    108      1.1  christos /* HP cc on HP-UX 10.20 has a bug with the constant expression -0.0.
    109      1.1  christos    ICC 10.0 has a bug when optimizing the expression -zero.
    110      1.1  christos    The expression -DBL_MIN * DBL_MIN does not work when cross-compiling
    111      1.1  christos    to PowerPC on Mac OS X 10.5.  */
    112      1.1  christos #if defined __hpux || defined __sgi || defined __ICC
    113      1.1  christos static double
    114      1.1  christos compute_minus_zero (void)
    115      1.1  christos {
    116      1.1  christos   return -DBL_MIN * DBL_MIN;
    117      1.1  christos }
    118      1.1  christos # define minus_zero compute_minus_zero ()
    119      1.1  christos #else
    120      1.1  christos double minus_zero = -0.0;
    121      1.1  christos #endif
    122      1.1  christos int main()
    123      1.1  christos {
    124      1.1  christos   int result = 0;
    125      1.1  christos   int i;
    126      1.1  christos   volatile double x;
    127      1.1  christos   double zero = 0.0;
    128      1.1  christos #if HAVE_DECL_ALARM
    129      1.1  christos   /* NeXTstep 3.3 frexp() runs into an endless loop when called on an infinite
    130      1.1  christos      number.  Let the test fail in this case.  */
    131      1.1  christos   signal (SIGALRM, SIG_DFL);
    132      1.1  christos   alarm (5);
    133      1.1  christos #endif
    134      1.1  christos   /* Test on denormalized numbers.  */
    135      1.1  christos   for (i = 1, x = 1.0; i >= DBL_MIN_EXP; i--, x *= 0.5)
    136      1.1  christos     ;
    137      1.1  christos   if (x > 0.0)
    138      1.1  christos     {
    139      1.1  christos       int exp;
    140      1.1  christos       double y = frexp (x, &exp);
    141      1.1  christos       /* On machines with IEEE754 arithmetic: x = 1.11254e-308, exp = -1022.
    142      1.1  christos          On NetBSD: y = 0.75. Correct: y = 0.5.  */
    143      1.1  christos       if (y != 0.5)
    144      1.1  christos         result |= 1;
    145      1.1  christos     }
    146      1.1  christos   /* Test on infinite numbers.  */
    147      1.1  christos   x = 1.0 / zero;
    148      1.1  christos   {
    149      1.1  christos     int exp;
    150      1.1  christos     double y = frexp (x, &exp);
    151      1.1  christos     if (y != x)
    152      1.1  christos       result |= 2;
    153      1.1  christos   }
    154      1.1  christos   /* Test on negative zero.  */
    155      1.1  christos   x = minus_zero;
    156      1.1  christos   {
    157      1.1  christos     int exp;
    158      1.1  christos     double y = frexp (x, &exp);
    159      1.1  christos     if (memcmp (&y, &x, sizeof x))
    160      1.1  christos       result |= 4;
    161      1.1  christos   }
    162      1.1  christos   return result;
    163      1.1  christos }]])],
    164      1.1  christos         [gl_cv_func_frexp_works=yes],
    165      1.1  christos         [gl_cv_func_frexp_works=no],
    166      1.1  christos         [case "$host_os" in
    167  1.1.1.2  christos            netbsd* | irix*) gl_cv_func_frexp_works="guessing no" ;;
    168      1.1  christos            mingw*) # Guess yes with MSVC, no with mingw.
    169      1.1  christos              AC_EGREP_CPP([Good], [
    170      1.1  christos #ifdef _MSC_VER
    171      1.1  christos  Good
    172      1.1  christos #endif
    173      1.1  christos                ],
    174      1.1  christos                [gl_cv_func_frexp_works="guessing yes"],
    175      1.1  christos                [gl_cv_func_frexp_works="guessing no"])
    176      1.1  christos              ;;
    177      1.1  christos            *) gl_cv_func_frexp_works="guessing yes" ;;
    178      1.1  christos          esac
    179      1.1  christos         ])
    180      1.1  christos     ])
    181      1.1  christos ])
    182