(root)/
mpfr-4.2.1/
tests/
tinits.c
       1  /* Test file for mpfr_init2, mpfr_inits, mpfr_inits2 and mpfr_clears.
       2  
       3  Copyright 2003, 2006-2023 Free Software Foundation, Inc.
       4  Contributed by the AriC and Caramba projects, INRIA.
       5  
       6  This file is part of the GNU MPFR Library.
       7  
       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  
      13  The GNU MPFR Library is distributed in the hope that it will be useful, but
      14  WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
      15  or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public
      16  License for more details.
      17  
      18  You should have received a copy of the GNU Lesser General Public License
      19  along with the GNU MPFR Library; see the file COPYING.LESSER.  If not, see
      20  https://www.gnu.org/licenses/ or write to the Free Software Foundation, Inc.,
      21  51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. */
      22  
      23  #include "mpfr-test.h"
      24  
      25  int
      26  main (void)
      27  {
      28    mpfr_t a, b, c;
      29    long large_prec;
      30  
      31    tests_start_mpfr ();
      32  
      33    mpfr_inits (a, b, c, (mpfr_ptr) 0);
      34    mpfr_clears (a, b, c, (mpfr_ptr) 0);
      35    mpfr_inits2 (200, a, b, c, (mpfr_ptr) 0);
      36    mpfr_clears (a, b, c, (mpfr_ptr) 0);
      37  
      38    /* test for precision 2^31-1, see
      39       https://gforge.inria.fr/tracker/index.php?func=detail&aid=13918 */
      40    large_prec = 2147483647;
      41    if (getenv ("MPFR_CHECK_LARGEMEM") != NULL)
      42      {
      43        size_t min_memory_limit;
      44  
      45        /* We assume that the precision won't be increased internally. */
      46        if (large_prec > MPFR_PREC_MAX)
      47          large_prec = MPFR_PREC_MAX;
      48  
      49        /* Increase tests_memory_limit if need be in order to avoid an
      50           obvious failure due to insufficient memory, by choosing a bit
      51           more than the memory used for the variables a and b. Note
      52           that such an increase is necessary, but is not guaranteed to
      53           be sufficient in all cases (e.g. with logging activated). */
      54        min_memory_limit = 2 * (large_prec / MPFR_BYTES_PER_MP_LIMB) + 65536;
      55        if (tests_memory_limit > 0 && tests_memory_limit < min_memory_limit)
      56          tests_memory_limit = min_memory_limit;
      57  
      58        mpfr_inits2 (large_prec, a, b, (mpfr_ptr) 0);
      59        mpfr_set_ui (a, 17, MPFR_RNDN);
      60        mpfr_set (b, a, MPFR_RNDN);
      61        if (mpfr_get_ui (a, MPFR_RNDN) != 17)
      62          {
      63            printf ("Error in mpfr_init2 with precision 2^31-1\n");
      64            exit (1);
      65          }
      66        mpfr_clears (a, b, (mpfr_ptr) 0);
      67      }
      68  
      69    tests_end_mpfr ();
      70  
      71    return 0;
      72  }