isinf.m4 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  1. # isinf.m4 serial 9
  2. dnl Copyright (C) 2007-2012 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. dnl Persuade glibc <math.h> to declare isinf.
  10. AC_REQUIRE([gl_USE_SYSTEM_EXTENSIONS])
  11. AC_CHECK_DECLS([isinf], , ,
  12. [[#include <math.h>
  13. #ifndef isinf
  14. #error "isinf must be a macro, not a function"
  15. #endif
  16. ]])
  17. if test "$ac_cv_have_decl_isinf" = yes; then
  18. gl_CHECK_MATH_LIB([ISINF_LIBM], [x = isinf (x) + isinf ((float) x);])
  19. if test "$ISINF_LIBM" != missing; then
  20. dnl Test whether isinf() on 'long double' works.
  21. gl_ISINFL_WORKS
  22. case "$gl_cv_func_isinfl_works" in
  23. *yes) ;;
  24. *) ISINF_LIBM=missing;;
  25. esac
  26. fi
  27. fi
  28. if test "$ac_cv_have_decl_isinf" != yes ||
  29. test "$ISINF_LIBM" = missing; then
  30. REPLACE_ISINF=1
  31. dnl No libraries are needed to link lib/isinf.c.
  32. ISINF_LIBM=
  33. fi
  34. AC_SUBST([ISINF_LIBM])
  35. ])
  36. dnl Test whether isinf() works:
  37. dnl 1) Whether it correctly returns false for LDBL_MAX.
  38. dnl 2) Whether on 'long double' recognizes all numbers which are neither
  39. dnl finite nor infinite. This test fails on OpenBSD/x86, but could also
  40. dnl fail e.g. on i686, x86_64, ia64, because of
  41. dnl - pseudo-denormals on x86_64,
  42. dnl - pseudo-zeroes, unnormalized numbers, and pseudo-denormals on i686,
  43. dnl - pseudo-NaN, pseudo-Infinity, pseudo-zeroes, unnormalized numbers, and
  44. dnl pseudo-denormals on ia64.
  45. AC_DEFUN([gl_ISINFL_WORKS],
  46. [
  47. AC_REQUIRE([AC_PROG_CC])
  48. AC_REQUIRE([gl_BIGENDIAN])
  49. AC_REQUIRE([gl_LONG_DOUBLE_VS_DOUBLE])
  50. AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
  51. AC_CACHE_CHECK([whether isinf(long double) works], [gl_cv_func_isinfl_works],
  52. [
  53. AC_RUN_IFELSE(
  54. [AC_LANG_SOURCE([[
  55. #include <float.h>
  56. #include <limits.h>
  57. #include <math.h>
  58. #define NWORDS \
  59. ((sizeof (long double) + sizeof (unsigned int) - 1) / sizeof (unsigned int))
  60. typedef union { unsigned int word[NWORDS]; long double value; }
  61. memory_long_double;
  62. /* On Irix 6.5, gcc 3.4.3 can't compute compile-time NaN, and needs the
  63. runtime type conversion. */
  64. #ifdef __sgi
  65. static long double NaNl ()
  66. {
  67. double zero = 0.0;
  68. return zero / zero;
  69. }
  70. #else
  71. # define NaNl() (0.0L / 0.0L)
  72. #endif
  73. int main ()
  74. {
  75. int result = 0;
  76. if (isinf (LDBL_MAX))
  77. result |= 1;
  78. {
  79. memory_long_double m;
  80. unsigned int i;
  81. /* The isinf macro should be immune against changes in the sign bit and
  82. in the mantissa bits. The xor operation twiddles a bit that can only be
  83. a sign bit or a mantissa bit (since the exponent never extends to
  84. bit 31). */
  85. m.value = NaNl ();
  86. m.word[NWORDS / 2] ^= (unsigned int) 1 << (sizeof (unsigned int) * CHAR_BIT - 1);
  87. for (i = 0; i < NWORDS; i++)
  88. m.word[i] |= 1;
  89. if (isinf (m.value))
  90. result |= 2;
  91. }
  92. #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
  93. /* Representation of an 80-bit 'long double' as an initializer for a sequence
  94. of 'unsigned int' words. */
  95. # ifdef WORDS_BIGENDIAN
  96. # define LDBL80_WORDS(exponent,manthi,mantlo) \
  97. { ((unsigned int) (exponent) << 16) | ((unsigned int) (manthi) >> 16), \
  98. ((unsigned int) (manthi) << 16) | (unsigned int) (mantlo) >> 16), \
  99. (unsigned int) (mantlo) << 16 \
  100. }
  101. # else
  102. # define LDBL80_WORDS(exponent,manthi,mantlo) \
  103. { mantlo, manthi, exponent }
  104. # endif
  105. { /* Quiet NaN. */
  106. static memory_long_double x =
  107. { LDBL80_WORDS (0xFFFF, 0xC3333333, 0x00000000) };
  108. if (isinf (x.value))
  109. result |= 2;
  110. }
  111. {
  112. /* Signalling NaN. */
  113. static memory_long_double x =
  114. { LDBL80_WORDS (0xFFFF, 0x83333333, 0x00000000) };
  115. if (isinf (x.value))
  116. result |= 2;
  117. }
  118. /* The isinf macro should recognize Pseudo-NaNs, Pseudo-Infinities,
  119. Pseudo-Zeroes, Unnormalized Numbers, and Pseudo-Denormals, as defined in
  120. Intel IA-64 Architecture Software Developer's Manual, Volume 1:
  121. Application Architecture.
  122. Table 5-2 "Floating-Point Register Encodings"
  123. Figure 5-6 "Memory to Floating-Point Register Data Translation"
  124. */
  125. { /* Pseudo-NaN. */
  126. static memory_long_double x =
  127. { LDBL80_WORDS (0xFFFF, 0x40000001, 0x00000000) };
  128. if (isinf (x.value))
  129. result |= 4;
  130. }
  131. { /* Pseudo-Infinity. */
  132. static memory_long_double x =
  133. { LDBL80_WORDS (0xFFFF, 0x00000000, 0x00000000) };
  134. if (isinf (x.value))
  135. result |= 8;
  136. }
  137. { /* Pseudo-Zero. */
  138. static memory_long_double x =
  139. { LDBL80_WORDS (0x4004, 0x00000000, 0x00000000) };
  140. if (isinf (x.value))
  141. result |= 16;
  142. }
  143. { /* Unnormalized number. */
  144. static memory_long_double x =
  145. { LDBL80_WORDS (0x4000, 0x63333333, 0x00000000) };
  146. if (isinf (x.value))
  147. result |= 32;
  148. }
  149. { /* Pseudo-Denormal. */
  150. static memory_long_double x =
  151. { LDBL80_WORDS (0x0000, 0x83333333, 0x00000000) };
  152. if (isinf (x.value))
  153. result |= 64;
  154. }
  155. #endif
  156. return result;
  157. }]])], [gl_cv_func_isinfl_works=yes], [gl_cv_func_isinfl_works=no],
  158. [
  159. case "$host" in
  160. # Guess no on OpenBSD ia64, x86_64, i386.
  161. ia64-*-openbsd* | x86_64-*-openbsd* | i*86-*-openbsd*)
  162. gl_cv_func_isinfl_works="guessing no";;
  163. *)
  164. gl_cv_func_isinfl_works="guessing yes";;
  165. esac
  166. ])
  167. ])
  168. ])