isinf.m4 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  1. # isinf.m4 serial 13
  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_ISINF],
  7. [
  8. AC_REQUIRE([gl_MATH_H_DEFAULTS])
  9. AC_REQUIRE([AC_CANONICAL_HOST])
  10. dnl Persuade glibc <math.h> to declare isinf.
  11. AC_REQUIRE([gl_USE_SYSTEM_EXTENSIONS])
  12. AC_CHECK_DECLS([isinf], , ,
  13. [[#include <math.h>
  14. #ifndef isinf
  15. #error "isinf must be a macro, not a function"
  16. #endif
  17. ]])
  18. if test "$ac_cv_have_decl_isinf" = yes; then
  19. gl_CHECK_MATH_LIB([ISINF_LIBM], [x = isinf (x) + isinf ((float) x);])
  20. if test "$ISINF_LIBM" != missing; then
  21. dnl Test whether isinf() on 'long double' works.
  22. gl_ISINFL_WORKS
  23. case "$gl_cv_func_isinfl_works" in
  24. *yes) ;;
  25. *) ISINF_LIBM=missing;;
  26. esac
  27. fi
  28. fi
  29. dnl On Solaris 10, with CC in C++ mode, isinf is not available although
  30. dnl is with cc in C mode. This cannot be worked around by defining
  31. dnl _XOPEN_SOURCE=600, because the latter does not work in C++ mode on
  32. dnl Solaris 11.0. Therefore use the replacement functions on Solaris.
  33. if test "$ac_cv_have_decl_isinf" != yes \
  34. || test "$ISINF_LIBM" = missing \
  35. || { case "$host_os" in solaris*) true;; *) false;; esac; }; then
  36. REPLACE_ISINF=1
  37. dnl No libraries are needed to link lib/isinf.c.
  38. ISINF_LIBM=
  39. fi
  40. AC_SUBST([ISINF_LIBM])
  41. ])
  42. dnl Test whether isinf() works:
  43. dnl 1) Whether it correctly returns false for LDBL_MAX.
  44. dnl 2) Whether on 'long double' recognizes all canonical values which are
  45. dnl infinite.
  46. AC_DEFUN([gl_ISINFL_WORKS],
  47. [
  48. AC_REQUIRE([AC_PROG_CC])
  49. AC_REQUIRE([gl_BIGENDIAN])
  50. AC_REQUIRE([gl_LONG_DOUBLE_VS_DOUBLE])
  51. AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
  52. AC_CACHE_CHECK([whether isinf(long double) works], [gl_cv_func_isinfl_works],
  53. [
  54. AC_RUN_IFELSE(
  55. [AC_LANG_SOURCE([[
  56. #include <float.h>
  57. #include <limits.h>
  58. #include <math.h>
  59. #define NWORDS \
  60. ((sizeof (long double) + sizeof (unsigned int) - 1) / sizeof (unsigned int))
  61. typedef union { unsigned int word[NWORDS]; long double value; }
  62. memory_long_double;
  63. /* On Irix 6.5, gcc 3.4.3 can't compute compile-time NaN, and needs the
  64. runtime type conversion. */
  65. #ifdef __sgi
  66. static long double NaNl ()
  67. {
  68. double zero = 0.0;
  69. return zero / zero;
  70. }
  71. #else
  72. # define NaNl() (0.0L / 0.0L)
  73. #endif
  74. int main ()
  75. {
  76. int result = 0;
  77. if (isinf (LDBL_MAX))
  78. result |= 1;
  79. {
  80. memory_long_double m;
  81. unsigned int i;
  82. /* The isinf macro should be immune against changes in the sign bit and
  83. in the mantissa bits. The xor operation twiddles a bit that can only be
  84. a sign bit or a mantissa bit (since the exponent never extends to
  85. bit 31). */
  86. m.value = NaNl ();
  87. m.word[NWORDS / 2] ^= (unsigned int) 1 << (sizeof (unsigned int) * CHAR_BIT - 1);
  88. for (i = 0; i < NWORDS; i++)
  89. m.word[i] |= 1;
  90. if (isinf (m.value))
  91. result |= 2;
  92. }
  93. #if ((defined __ia64 && LDBL_MANT_DIG == 64) || (defined __x86_64__ || defined __amd64__) || (defined __i386 || defined __i386__ || defined _I386 || defined _M_IX86 || defined _X86_)) && !HAVE_SAME_LONG_DOUBLE_AS_DOUBLE
  94. /* Representation of an 80-bit 'long double' as an initializer for a sequence
  95. of 'unsigned int' words. */
  96. # ifdef WORDS_BIGENDIAN
  97. # define LDBL80_WORDS(exponent,manthi,mantlo) \
  98. { ((unsigned int) (exponent) << 16) | ((unsigned int) (manthi) >> 16), \
  99. ((unsigned int) (manthi) << 16) | ((unsigned int) (mantlo) >> 16), \
  100. (unsigned int) (mantlo) << 16 \
  101. }
  102. # else
  103. # define LDBL80_WORDS(exponent,manthi,mantlo) \
  104. { mantlo, manthi, exponent }
  105. # endif
  106. { /* Quiet NaN. */
  107. static memory_long_double x =
  108. { LDBL80_WORDS (0xFFFF, 0xC3333333, 0x00000000) };
  109. if (isinf (x.value))
  110. result |= 2;
  111. }
  112. {
  113. /* Signalling NaN. */
  114. static memory_long_double x =
  115. { LDBL80_WORDS (0xFFFF, 0x83333333, 0x00000000) };
  116. if (isinf (x.value))
  117. result |= 2;
  118. }
  119. /* isinf should return something even for noncanonical values. */
  120. { /* Pseudo-NaN. */
  121. static memory_long_double x =
  122. { LDBL80_WORDS (0xFFFF, 0x40000001, 0x00000000) };
  123. if (isinf (x.value) && !isinf (x.value))
  124. result |= 4;
  125. }
  126. { /* Pseudo-Infinity. */
  127. static memory_long_double x =
  128. { LDBL80_WORDS (0xFFFF, 0x00000000, 0x00000000) };
  129. if (isinf (x.value) && !isinf (x.value))
  130. result |= 8;
  131. }
  132. { /* Pseudo-Zero. */
  133. static memory_long_double x =
  134. { LDBL80_WORDS (0x4004, 0x00000000, 0x00000000) };
  135. if (isinf (x.value) && !isinf (x.value))
  136. result |= 16;
  137. }
  138. { /* Unnormalized number. */
  139. static memory_long_double x =
  140. { LDBL80_WORDS (0x4000, 0x63333333, 0x00000000) };
  141. if (isinf (x.value) && !isinf (x.value))
  142. result |= 32;
  143. }
  144. { /* Pseudo-Denormal. */
  145. static memory_long_double x =
  146. { LDBL80_WORDS (0x0000, 0x83333333, 0x00000000) };
  147. if (isinf (x.value) && !isinf (x.value))
  148. result |= 64;
  149. }
  150. #endif
  151. return result;
  152. }]])],
  153. [gl_cv_func_isinfl_works=yes],
  154. [gl_cv_func_isinfl_works=no],
  155. [case "$host_os" in
  156. mingw*) # Guess yes on mingw, no on MSVC.
  157. AC_EGREP_CPP([Known], [
  158. #ifdef __MINGW32__
  159. Known
  160. #endif
  161. ],
  162. [gl_cv_func_isinfl_works="guessing yes"],
  163. [gl_cv_func_isinfl_works="guessing no"])
  164. ;;
  165. *)
  166. gl_cv_func_isinfl_works="guessing yes"
  167. ;;
  168. esac
  169. ])
  170. ])
  171. ])