| 1 | # frexpl.m4 serial 21 |
| 2 | dnl Copyright (C) 2007-2019 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. |
| 6 | |
| 7 | AC_DEFUN([gl_FUNC_FREXPL], |
| 8 | [ |
| 9 | AC_REQUIRE([gl_MATH_H_DEFAULTS]) |
| 10 | AC_REQUIRE([gl_LONG_DOUBLE_VS_DOUBLE]) |
| 11 | |
| 12 | dnl Persuade glibc <math.h> to declare frexpl(). |
| 13 | AC_REQUIRE([gl_USE_SYSTEM_EXTENSIONS]) |
| 14 | |
| 15 | dnl Check whether it's declared. |
| 16 | dnl Mac OS X 10.3 has frexpl() in libc but doesn't declare it in <math.h>. |
| 17 | AC_CHECK_DECL([frexpl], , [HAVE_DECL_FREXPL=0], [[#include <math.h>]]) |
| 18 | |
| 19 | FREXPL_LIBM= |
| 20 | if test $HAVE_DECL_FREXPL = 1; then |
| 21 | gl_CHECK_FREXPL_NO_LIBM |
| 22 | if test $gl_cv_func_frexpl_no_libm = no; then |
| 23 | AC_CACHE_CHECK([whether frexpl() can be used with libm], |
| 24 | [gl_cv_func_frexpl_in_libm], |
| 25 | [ |
| 26 | save_LIBS="$LIBS" |
| 27 | LIBS="$LIBS -lm" |
| 28 | AC_LINK_IFELSE( |
| 29 | [AC_LANG_PROGRAM( |
| 30 | [[#include <math.h> |
| 31 | long double x;]], |
| 32 | [[int e; return frexpl (x, &e) > 0;]])], |
| 33 | [gl_cv_func_frexpl_in_libm=yes], |
| 34 | [gl_cv_func_frexpl_in_libm=no]) |
| 35 | LIBS="$save_LIBS" |
| 36 | ]) |
| 37 | if test $gl_cv_func_frexpl_in_libm = yes; then |
| 38 | FREXPL_LIBM=-lm |
| 39 | fi |
| 40 | fi |
| 41 | if test $gl_cv_func_frexpl_no_libm = yes \ |
| 42 | || test $gl_cv_func_frexpl_in_libm = yes; then |
| 43 | save_LIBS="$LIBS" |
| 44 | LIBS="$LIBS $FREXPL_LIBM" |
| 45 | gl_FUNC_FREXPL_WORKS |
| 46 | LIBS="$save_LIBS" |
| 47 | case "$gl_cv_func_frexpl_works" in |
| 48 | *yes) gl_func_frexpl=yes ;; |
| 49 | *) gl_func_frexpl=no; REPLACE_FREXPL=1 ;; |
| 50 | esac |
| 51 | else |
| 52 | gl_func_frexpl=no |
| 53 | fi |
| 54 | if test $gl_func_frexpl = yes; then |
| 55 | AC_DEFINE([HAVE_FREXPL], [1], |
| 56 | [Define if the frexpl() function is available.]) |
| 57 | fi |
| 58 | fi |
| 59 | if test $HAVE_DECL_FREXPL = 0 || test $gl_func_frexpl = no; then |
| 60 | dnl Find libraries needed to link lib/frexpl.c. |
| 61 | if test $HAVE_SAME_LONG_DOUBLE_AS_DOUBLE = 1; then |
| 62 | AC_REQUIRE([gl_FUNC_FREXP]) |
| 63 | FREXPL_LIBM="$FREXP_LIBM" |
| 64 | else |
| 65 | FREXPL_LIBM= |
| 66 | fi |
| 67 | fi |
| 68 | AC_SUBST([FREXPL_LIBM]) |
| 69 | ]) |
| 70 | |
| 71 | AC_DEFUN([gl_FUNC_FREXPL_NO_LIBM], |
| 72 | [ |
| 73 | AC_REQUIRE([gl_MATH_H_DEFAULTS]) |
| 74 | AC_REQUIRE([gl_LONG_DOUBLE_VS_DOUBLE]) |
| 75 | dnl Check whether it's declared. |
| 76 | dnl Mac OS X 10.3 has frexpl() in libc but doesn't declare it in <math.h>. |
| 77 | AC_CHECK_DECL([frexpl], , [HAVE_DECL_FREXPL=0], [[#include <math.h>]]) |
| 78 | if test $HAVE_DECL_FREXPL = 1; then |
| 79 | gl_CHECK_FREXPL_NO_LIBM |
| 80 | if test $gl_cv_func_frexpl_no_libm = yes; then |
| 81 | gl_FUNC_FREXPL_WORKS |
| 82 | case "$gl_cv_func_frexpl_works" in |
| 83 | *yes) gl_func_frexpl_no_libm=yes ;; |
| 84 | *) gl_func_frexpl_no_libm=no; REPLACE_FREXPL=1 ;; |
| 85 | esac |
| 86 | else |
| 87 | gl_func_frexpl_no_libm=no |
| 88 | dnl Set REPLACE_FREXPL here because the system may have frexpl in libm. |
| 89 | REPLACE_FREXPL=1 |
| 90 | fi |
| 91 | if test $gl_func_frexpl_no_libm = yes; then |
| 92 | AC_DEFINE([HAVE_FREXPL_IN_LIBC], [1], |
| 93 | [Define if the frexpl() function is available in libc.]) |
| 94 | fi |
| 95 | fi |
| 96 | ]) |
| 97 | |
| 98 | dnl Test whether frexpl() can be used without linking with libm. |
| 99 | dnl Set gl_cv_func_frexpl_no_libm to 'yes' or 'no' accordingly. |
| 100 | AC_DEFUN([gl_CHECK_FREXPL_NO_LIBM], |
| 101 | [ |
| 102 | AC_CACHE_CHECK([whether frexpl() can be used without linking with libm], |
| 103 | [gl_cv_func_frexpl_no_libm], |
| 104 | [ |
| 105 | AC_LINK_IFELSE( |
| 106 | [AC_LANG_PROGRAM( |
| 107 | [[#include <math.h> |
| 108 | long double x;]], |
| 109 | [[int e; return frexpl (x, &e) > 0;]])], |
| 110 | [gl_cv_func_frexpl_no_libm=yes], |
| 111 | [gl_cv_func_frexpl_no_libm=no]) |
| 112 | ]) |
| 113 | ]) |
| 114 | |
| 115 | dnl Test whether frexpl() works on finite numbers (this fails on |
| 116 | dnl Mac OS X 10.4/PowerPC, on AIX 5.1, and on BeOS), on denormalized numbers |
| 117 | dnl (this fails on Mac OS X 10.5/i386), and also on infinite numbers (this |
| 118 | dnl fails e.g. on IRIX 6.5 and mingw). |
| 119 | AC_DEFUN([gl_FUNC_FREXPL_WORKS], |
| 120 | [ |
| 121 | AC_REQUIRE([AC_PROG_CC]) |
| 122 | AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles |
| 123 | AC_CACHE_CHECK([whether frexpl works], [gl_cv_func_frexpl_works], |
| 124 | [ |
| 125 | AC_RUN_IFELSE( |
| 126 | [AC_LANG_SOURCE([[ |
| 127 | #include <float.h> |
| 128 | #include <math.h> |
| 129 | /* Override the values of <float.h>, like done in float.in.h. */ |
| 130 | #if defined __i386__ && (defined __BEOS__ || defined __OpenBSD__) |
| 131 | # undef LDBL_MIN_EXP |
| 132 | # define LDBL_MIN_EXP (-16381) |
| 133 | #endif |
| 134 | #if defined __i386__ && (defined __FreeBSD__ || defined __DragonFly__) |
| 135 | # undef LDBL_MIN_EXP |
| 136 | # define LDBL_MIN_EXP (-16381) |
| 137 | #endif |
| 138 | #if (defined _ARCH_PPC || defined _POWER) && defined _AIX && (LDBL_MANT_DIG == 106) && defined __GNUC__ |
| 139 | # undef LDBL_MIN_EXP |
| 140 | # define LDBL_MIN_EXP DBL_MIN_EXP |
| 141 | #endif |
| 142 | #if defined __sgi && (LDBL_MANT_DIG >= 106) |
| 143 | # if defined __GNUC__ |
| 144 | # undef LDBL_MIN_EXP |
| 145 | # define LDBL_MIN_EXP DBL_MIN_EXP |
| 146 | # endif |
| 147 | #endif |
| 148 | extern |
| 149 | #ifdef __cplusplus |
| 150 | "C" |
| 151 | #endif |
| 152 | long double frexpl (long double, int *); |
| 153 | int main() |
| 154 | { |
| 155 | int result = 0; |
| 156 | volatile long double x; |
| 157 | /* Test on finite numbers that fails on AIX 5.1. */ |
| 158 | x = 16.0L; |
| 159 | { |
| 160 | int exp = -9999; |
| 161 | frexpl (x, &exp); |
| 162 | if (exp != 5) |
| 163 | result |= 1; |
| 164 | } |
| 165 | /* Test on finite numbers that fails on Mac OS X 10.4, because its frexpl |
| 166 | function returns an invalid (incorrectly normalized) value: it returns |
| 167 | y = { 0x3fe028f5, 0xc28f5c28, 0x3c9eb851, 0xeb851eb8 } |
| 168 | but the correct result is |
| 169 | 0.505L = { 0x3fe028f5, 0xc28f5c29, 0xbc547ae1, 0x47ae1480 } */ |
| 170 | x = 1.01L; |
| 171 | { |
| 172 | int exp = -9999; |
| 173 | long double y = frexpl (x, &exp); |
| 174 | if (!(exp == 1 && y == 0.505L)) |
| 175 | result |= 2; |
| 176 | } |
| 177 | /* Test on large finite numbers. This fails on BeOS at i = 16322, while |
| 178 | LDBL_MAX_EXP = 16384. |
| 179 | In the loop end test, we test x against Infinity, rather than comparing |
| 180 | i with LDBL_MAX_EXP, because BeOS <float.h> has a wrong LDBL_MAX_EXP. */ |
| 181 | { |
| 182 | int i; |
| 183 | for (i = 1, x = 1.0L; x != x + x; i++, x *= 2.0L) |
| 184 | { |
| 185 | int exp = -9999; |
| 186 | frexpl (x, &exp); |
| 187 | if (exp != i) |
| 188 | { |
| 189 | result |= 4; |
| 190 | break; |
| 191 | } |
| 192 | } |
| 193 | } |
| 194 | /* Test on denormalized numbers. */ |
| 195 | { |
| 196 | int i; |
| 197 | for (i = 1, x = 1.0L; i >= LDBL_MIN_EXP; i--, x *= 0.5L) |
| 198 | ; |
| 199 | if (x > 0.0L) |
| 200 | { |
| 201 | int exp; |
| 202 | long double y = frexpl (x, &exp); |
| 203 | /* On machines with IEEE854 arithmetic: x = 1.68105e-4932, |
| 204 | exp = -16382, y = 0.5. On Mac OS X 10.5: exp = -16384, y = 0.5. */ |
| 205 | if (exp != LDBL_MIN_EXP - 1) |
| 206 | result |= 8; |
| 207 | } |
| 208 | } |
| 209 | /* Test on infinite numbers. */ |
| 210 | x = 1.0L / 0.0L; |
| 211 | { |
| 212 | int exp; |
| 213 | long double y = frexpl (x, &exp); |
| 214 | if (y != x) |
| 215 | result |= 16; |
| 216 | } |
| 217 | return result; |
| 218 | }]])], |
| 219 | [gl_cv_func_frexpl_works=yes], |
| 220 | [gl_cv_func_frexpl_works=no], |
| 221 | [ |
| 222 | changequote(,)dnl |
| 223 | case "$host_os" in |
| 224 | aix | aix[3-6]* | beos* | darwin* | irix* | mingw* | pw*) |
| 225 | gl_cv_func_frexpl_works="guessing no";; |
| 226 | *) gl_cv_func_frexpl_works="guessing yes";; |
| 227 | esac |
| 228 | changequote([,])dnl |
| 229 | ]) |
| 230 | ]) |
| 231 | ]) |