frexpl.m4 7.0 KB

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