root/maint/gnulib/tests/test-libgmp.c

/* [previous][next][first][last][top][bottom][index][help] */

DEFINITIONS

This source file includes following definitions.
  1. main

   1 /* Test of libgmp or its mini-gmp substitute.
   2    Copyright (C) 2020-2021 Free Software Foundation, Inc.
   3 
   4    This program is free software: you can redistribute it and/or modify
   5    it under the terms of the GNU General Public License as published by
   6    the Free Software Foundation; either version 3 of the License, or
   7    (at your option) any later version.
   8 
   9    This program is distributed in the hope that it will be useful,
  10    but WITHOUT ANY WARRANTY; without even the implied warranty of
  11    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  12    GNU General Public License for more details.
  13 
  14    You should have received a copy of the GNU General Public License
  15    along with this program.  If not, see <https://www.gnu.org/licenses/>.  */
  16 
  17 #include <config.h>
  18 
  19 /* Specification.  */
  20 #include <gmp.h>
  21 
  22 #include <limits.h>
  23 #include <string.h>
  24 
  25 #include "verify.h"
  26 
  27 #include "macros.h"
  28 
  29 #ifndef MINI_GMP_LIMB_TYPE
  30 /* Verify that the gmp.h header file was generated for the same
  31    machine word size as we are using.  */
  32 verify (GMP_NUMB_BITS == sizeof (mp_limb_t) * CHAR_BIT);
  33 #endif
  34 
  35 int
  36 main ()
     /* [previous][next][first][last][top][bottom][index][help] */
  37 {
  38 #ifndef MINI_GMP_LIMB_TYPE
  39   /* Verify that the gmp.h header file and the libgmp library come from
  40      the same GMP version.  */
  41   {
  42     char gmp_header_version[32];
  43     sprintf (gmp_header_version, "%d.%d.%d", __GNU_MP_VERSION,
  44              __GNU_MP_VERSION_MINOR, __GNU_MP_VERSION_PATCHLEVEL);
  45     if (strcmp (gmp_version, gmp_header_version) != 0)
  46       {
  47         char gmp_header_version2[32];
  48         if (__GNU_MP_VERSION_PATCHLEVEL > 0
  49             || (sprintf (gmp_header_version2, "%d.%d", __GNU_MP_VERSION,
  50                          __GNU_MP_VERSION_MINOR),
  51                 strcmp (gmp_version, gmp_header_version2) != 0))
  52           {
  53             fprintf (stderr,
  54                      "gmp header version (%s) does not match gmp library version (%s).\n",
  55                      gmp_header_version, gmp_version);
  56             exit (1);
  57           }
  58       }
  59   }
  60 #endif
  61 
  62   /* A simple sanity check that 2 + 2 = 4.  */
  63   static mp_limb_t const twobody[] = { 2 };
  64   static mpz_t const two = MPZ_ROINIT_N ((mp_limb_t *) twobody, 1);
  65   ASSERT (mpz_fits_slong_p (two));
  66   ASSERT (mpz_get_si (two) == 2);
  67 
  68   mpz_t four;
  69   mpz_init (four);
  70   mpz_add (four, two, two);
  71   ASSERT (mpz_fits_slong_p (four));
  72   ASSERT (mpz_get_si (four) == 4);
  73   mpz_clear (four);
  74 
  75   return 0;
  76 }

/* [previous][next][first][last][top][bottom][index][help] */