version.c revision 1.1.1.2
1/* 2 * Output various information about GMP and MPFR. 3 */ 4 5/* 6Copyright 2010, 2011, 2012, 2013 Free Software Foundation, Inc. 7Contributed by the AriC and Caramel projects, INRIA. 8 9This file is part of the GNU MPFR Library. 10 11The GNU MPFR Library is free software; you can redistribute it and/or modify 12it under the terms of the GNU Lesser General Public License as published by 13the Free Software Foundation; either version 3 of the License, or (at your 14option) any later version. 15 16The GNU MPFR Library is distributed in the hope that it will be useful, but 17WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 18or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public 19License for more details. 20 21You should have received a copy of the GNU Lesser General Public License 22along with the GNU MPFR Library; see the file COPYING.LESSER. If not, see 23http://www.gnu.org/licenses/ or write to the Free Software Foundation, Inc., 2451 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 */ 38static 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 49int main (void) 50{ 51 unsigned long c; 52 mp_limb_t t[4] = { -1, -1, -1, -1 }; 53 54#if defined(__cplusplus) 55 printf ("A C++ compiler is used.\n"); 56#endif 57 58 printf ("GMP ..... Library: %-12s Header: %d.%d.%d\n", 59 gmp_version, __GNU_MP_VERSION, __GNU_MP_VERSION_MINOR, 60 __GNU_MP_VERSION_PATCHLEVEL); 61 62 printf ("MPFR .... Library: %-12s Header: %s (based on %d.%d.%d)\n", 63 mpfr_get_version (), MPFR_VERSION_STRING, MPFR_VERSION_MAJOR, 64 MPFR_VERSION_MINOR, MPFR_VERSION_PATCHLEVEL); 65 66#if MPFR_VERSION_MAJOR >= 3 67 printf ("MPFR features: TLS = %s, decimal = %s", 68 mpfr_buildopt_tls_p () ? "yes" : "no", 69 mpfr_buildopt_decimal_p () ? "yes" : "no"); 70# if MPFR_VERSION_MAJOR > 3 || MPFR_VERSION_MINOR >= 1 71 printf (", GMP internals = %s\nMPFR tuning: %s", 72 mpfr_buildopt_gmpinternals_p () ? "yes" : "no", 73 mpfr_buildopt_tune_case ()); 74# endif 75 printf ("\n"); 76#endif 77 78 printf ("MPFR patches: %s\n\n", mpfr_get_patches ()); 79 80#ifdef __GMP_CC 81 printf ("__GMP_CC = \"%s\"\n", __GMP_CC); 82#endif 83#ifdef __GMP_CFLAGS 84 printf ("__GMP_CFLAGS = \"%s\"\n", __GMP_CFLAGS); 85#endif 86 printf ("GMP_LIMB_BITS = %d\n", (int) GMP_LIMB_BITS); 87 printf ("GMP_NAIL_BITS = %d\n", (int) GMP_NAIL_BITS); 88 printf ("GMP_NUMB_BITS = %d\n", (int) GMP_NUMB_BITS); 89 printf ("mp_bits_per_limb = %d\n", (int) mp_bits_per_limb); 90 printf ("sizeof(mp_limb_t) = %d\n", (int) sizeof(mp_limb_t)); 91 if (mp_bits_per_limb != GMP_LIMB_BITS) 92 printf ("Warning! mp_bits_per_limb != GMP_LIMB_BITS\n"); 93 if (GMP_LIMB_BITS != sizeof(mp_limb_t) * CHAR_BIT) 94 printf ("Warning! GMP_LIMB_BITS != sizeof(mp_limb_t) * CHAR_BIT\n"); 95 96 c = mpn_popcount (t, 1); 97 printf ("The GMP library expects %lu bits in a mp_limb_t.\n", c); 98 if (c != GMP_LIMB_BITS) 99 printf ("Warning! This is different from GMP_LIMB_BITS!\n" 100 "Different ABI caused by a GMP library upgrade?\n"); 101 102#if MPFR_VERSION_MAJOR >= 3 103 printf ("\n"); 104 printf ("sizeof(mpfr_prec_t) = %d\n", (int) sizeof(mpfr_prec_t)); 105 printf ("sizeof(mpfr_exp_t) = %d\n", (int) sizeof(mpfr_exp_t)); 106#endif 107 108 failure_test (); 109 110 return 0; 111} 112