version.c revision 1.1.1.1
1/* 2 * Output various information about GMP and MPFR. 3 */ 4 5/* 6Copyright 2010, 2011 Free Software Foundation, Inc. 7Contributed by the Arenaire and Cacao 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, GMP_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 printf ("MPFR patches: %s\n\n", mpfr_get_patches ()); 66 67#ifdef __GMP_CC 68 printf ("__GMP_CC = \"%s\"\n", __GMP_CC); 69#endif 70#ifdef __GMP_CFLAGS 71 printf ("__GMP_CFLAGS = \"%s\"\n", __GMP_CFLAGS); 72#endif 73 printf ("GMP_LIMB_BITS = %d\n", (int) GMP_LIMB_BITS); 74 printf ("GMP_NAIL_BITS = %d\n", (int) GMP_NAIL_BITS); 75 printf ("GMP_NUMB_BITS = %d\n", (int) GMP_NUMB_BITS); 76 printf ("mp_bits_per_limb = %d\n", (int) mp_bits_per_limb); 77 printf ("sizeof(mp_limb_t) = %d\n", (int) sizeof(mp_limb_t)); 78 if (mp_bits_per_limb != GMP_LIMB_BITS) 79 printf ("Warning! mp_bits_per_limb != GMP_LIMB_BITS\n"); 80 if (GMP_LIMB_BITS != sizeof(mp_limb_t) * CHAR_BIT) 81 printf ("Warning! GMP_LIMB_BITS != sizeof(mp_limb_t) * CHAR_BIT\n"); 82 83 c = mpn_popcount (t, 1); 84 printf ("The GMP library expects %lu bits in a mp_limb_t.\n", c); 85 if (c != GMP_LIMB_BITS) 86 printf ("Warning! This is different from GMP_LIMB_BITS!\n" 87 "Different ABI caused by a GMP library upgrade?\n"); 88 89 failure_test (); 90 91 return 0; 92} 93