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