version.c 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241
  1. /*
  2. * Output various information about GMP and MPFR.
  3. */
  4. /*
  5. Copyright 2010-2016 Free Software Foundation, Inc.
  6. Contributed by the AriC and Caramba projects, INRIA.
  7. This file is part of the GNU MPFR Library.
  8. The GNU MPFR Library is free software; you can redistribute it and/or modify
  9. it under the terms of the GNU Lesser General Public License as published by
  10. the Free Software Foundation; either version 3 of the License, or (at your
  11. option) any later version.
  12. The GNU MPFR Library is distributed in the hope that it will be useful, but
  13. WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
  14. or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
  15. License for more details.
  16. You should have received a copy of the GNU Lesser General Public License
  17. along with the GNU MPFR Library; see the file COPYING.LESSER. If not, see
  18. http://www.gnu.org/licenses/ or write to the Free Software Foundation, Inc.,
  19. 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
  20. */
  21. #include <stdio.h>
  22. #include <limits.h>
  23. #include <gmp.h>
  24. #include <mpfr.h>
  25. /* The following failure can occur if GMP has been rebuilt with
  26. * a different ABI, e.g.
  27. * 1. GMP built with ABI=mode32.
  28. * 2. MPFR built against this GMP version.
  29. * 3. GMP rebuilt with ABI=32.
  30. */
  31. static void failure_test (void)
  32. {
  33. mpfr_t x;
  34. mpfr_init2 (x, 128);
  35. mpfr_set_str (x, "17", 0, MPFR_RNDN);
  36. if (mpfr_cmp_ui (x, 17) != 0)
  37. printf ("\nFailure in mpfr_set_str! Probably an unmatched ABI!\n");
  38. mpfr_clear (x);
  39. }
  40. static void patches (void)
  41. {
  42. const char *p = mpfr_get_patches ();
  43. printf ("MPFR patches: %s\n", p[0] ? p : "[none]");
  44. }
  45. #define STRINGIZE(S) #S
  46. #define MAKE_STR(S) STRINGIZE(S)
  47. #define SIGNED_STR(V) ((V) < 0 ? "signed" : "unsigned")
  48. #define SIGNED(I) SIGNED_STR((I) - (I) - 1)
  49. int main (void)
  50. {
  51. unsigned long c;
  52. mp_limb_t t[4];
  53. int i;
  54. /* Casts are for C++ compilers. */
  55. for (i = 0; i < (int) (sizeof (t) / sizeof (mp_limb_t)); i++)
  56. t[i] = (mp_limb_t) -1;
  57. /**************** Information about the C implementation ****************/
  58. /* This is useful, as this can affect the behavior of MPFR. */
  59. #define COMP "Compiler: "
  60. #ifdef __INTEL_COMPILER
  61. # ifdef __VERSION__
  62. # define ICCV " [" __VERSION__ "]"
  63. # else
  64. # define ICCV ""
  65. # endif
  66. printf (COMP "ICC %d.%d.%d" ICCV "\n", __INTEL_COMPILER / 100,
  67. __INTEL_COMPILER % 100, __INTEL_COMPILER_UPDATE);
  68. #elif (defined(__GNUC__) || defined(__clang__)) && defined(__VERSION__)
  69. # ifdef __clang__
  70. # define COMP2 COMP
  71. # else
  72. # define COMP2 COMP "GCC "
  73. # endif
  74. printf (COMP2 "%s\n", __VERSION__);
  75. #endif
  76. #if defined(__STDC__) || defined(__STDC_VERSION__)
  77. printf ("C/C++: __STDC__ = "
  78. #if defined(__STDC__)
  79. MAKE_STR(__STDC__)
  80. #else
  81. "undef"
  82. #endif
  83. ", __STDC_VERSION__ = "
  84. #if defined(__STDC_VERSION__)
  85. MAKE_STR(__STDC_VERSION__)
  86. #else
  87. "undef"
  88. #endif
  89. #if defined(__cplusplus)
  90. ", C++"
  91. #endif
  92. "\n");
  93. #endif
  94. #if defined(__GNUC__)
  95. printf ("GNU compatibility: __GNUC__ = " MAKE_STR(__GNUC__)
  96. ", __GNUC_MINOR__ = "
  97. #if defined(__GNUC_MINOR__)
  98. MAKE_STR(__GNUC_MINOR__)
  99. #else
  100. "undef"
  101. #endif
  102. "\n");
  103. #endif
  104. #if defined(__ICC) || defined(__INTEL_COMPILER)
  105. printf ("Intel compiler: __ICC = "
  106. #if defined(__ICC)
  107. MAKE_STR(__ICC)
  108. #else
  109. "undef"
  110. #endif
  111. ", __INTEL_COMPILER = "
  112. #if defined(__INTEL_COMPILER)
  113. MAKE_STR(__INTEL_COMPILER)
  114. #else
  115. "undef"
  116. #endif
  117. "\n");
  118. #endif
  119. #if defined(_WIN32) || defined(_MSC_VER)
  120. printf ("MS Windows: _WIN32 = "
  121. #if defined(_WIN32)
  122. MAKE_STR(_WIN32)
  123. #else
  124. "undef"
  125. #endif
  126. ", _MSC_VER = "
  127. #if defined(_MSC_VER)
  128. MAKE_STR(_MSC_VER)
  129. #else
  130. "undef"
  131. #endif
  132. "\n");
  133. #endif
  134. #if defined(__GLIBC__)
  135. printf ("GNU C library: __GLIBC__ = " MAKE_STR(__GLIBC__)
  136. ", __GLIBC_MINOR__ = "
  137. #if defined(__GLIBC_MINOR__)
  138. MAKE_STR(__GLIBC_MINOR__)
  139. #else
  140. "undef"
  141. #endif
  142. "\n");
  143. #endif
  144. printf ("\n");
  145. /************************************************************************/
  146. #if defined(__MPIR_VERSION)
  147. printf ("MPIR .... Library: %-12s Header: %d.%d.%d\n",
  148. mpir_version, __MPIR_VERSION, __MPIR_VERSION_MINOR,
  149. __MPIR_VERSION_PATCHLEVEL);
  150. #else
  151. printf ("GMP ..... Library: %-12s Header: %d.%d.%d\n",
  152. gmp_version, __GNU_MP_VERSION, __GNU_MP_VERSION_MINOR,
  153. __GNU_MP_VERSION_PATCHLEVEL);
  154. #endif
  155. printf ("MPFR .... Library: %-12s Header: %s (based on %d.%d.%d)\n",
  156. mpfr_get_version (), MPFR_VERSION_STRING, MPFR_VERSION_MAJOR,
  157. MPFR_VERSION_MINOR, MPFR_VERSION_PATCHLEVEL);
  158. printf ("MPFR features: TLS = %s, decimal = %s",
  159. mpfr_buildopt_tls_p () ? "yes" : "no",
  160. mpfr_buildopt_decimal_p () ? "yes" : "no");
  161. #if MPFR_VERSION_MAJOR > 3 || MPFR_VERSION_MINOR >= 1
  162. printf (", GMP internals = %s\nMPFR tuning: %s",
  163. mpfr_buildopt_gmpinternals_p () ? "yes" : "no",
  164. mpfr_buildopt_tune_case ());
  165. #endif /* 3.1 */
  166. printf ("\n");
  167. patches ();
  168. printf ("\n");
  169. #ifdef __GMP_CC
  170. printf ("__GMP_CC = \"%s\"\n", __GMP_CC);
  171. #endif
  172. #ifdef __GMP_CFLAGS
  173. printf ("__GMP_CFLAGS = \"%s\"\n", __GMP_CFLAGS);
  174. #endif
  175. printf ("GMP_LIMB_BITS = %d\n", (int) GMP_LIMB_BITS);
  176. printf ("GMP_NAIL_BITS = %d\n", (int) GMP_NAIL_BITS);
  177. printf ("GMP_NUMB_BITS = %d\n", (int) GMP_NUMB_BITS);
  178. printf ("mp_bits_per_limb = %d\n", (int) mp_bits_per_limb);
  179. printf ("sizeof(mp_limb_t) = %d\n", (int) sizeof(mp_limb_t));
  180. if (mp_bits_per_limb != GMP_LIMB_BITS)
  181. printf ("Warning! mp_bits_per_limb != GMP_LIMB_BITS\n");
  182. if (GMP_LIMB_BITS != sizeof(mp_limb_t) * CHAR_BIT)
  183. printf ("Warning! GMP_LIMB_BITS != sizeof(mp_limb_t) * CHAR_BIT\n");
  184. c = mpn_popcount (t, 1);
  185. printf ("The GMP library expects %lu bits in a mp_limb_t.\n", c);
  186. if (c != GMP_LIMB_BITS)
  187. printf ("Warning! This is different from GMP_LIMB_BITS!\n"
  188. "Different ABI caused by a GMP library upgrade?\n");
  189. printf ("\n");
  190. printf ("sizeof(mpfr_prec_t) = %d (%s type)\n", (int) sizeof(mpfr_prec_t),
  191. SIGNED_STR((mpfr_prec_t) -1));
  192. printf ("sizeof(mpfr_exp_t) = %d (%s type)\n", (int) sizeof(mpfr_exp_t),
  193. SIGNED_STR((mpfr_exp_t) -1));
  194. #ifdef _MPFR_PREC_FORMAT
  195. printf ("_MPFR_PREC_FORMAT = %d\n", (int) _MPFR_PREC_FORMAT);
  196. #endif
  197. /* Note: "long" is sufficient for all current _MPFR_PREC_FORMAT values
  198. (1, 2, 3). Thus we do not need to depend on ISO C99 or later. */
  199. printf ("MPFR_PREC_MIN = %ld (%s)\n", (long) MPFR_PREC_MIN,
  200. SIGNED (MPFR_PREC_MIN));
  201. printf ("MPFR_PREC_MAX = %ld (%s)\n", (long) MPFR_PREC_MAX,
  202. SIGNED (MPFR_PREC_MAX));
  203. #ifdef _MPFR_EXP_FORMAT
  204. printf ("_MPFR_EXP_FORMAT = %d\n", (int) _MPFR_EXP_FORMAT);
  205. #endif
  206. printf ("sizeof(mpfr_t) = %d\n", (int) sizeof(mpfr_t));
  207. printf ("sizeof(mpfr_ptr) = %d\n", (int) sizeof(mpfr_ptr));
  208. failure_test ();
  209. return 0;
  210. }