"Fossies" - the Fresh Open Source Software Archive

Member "mpfr-4.0.2/tests/tset_exp.c" (7 Jan 2019, 2287 Bytes) of package /linux/misc/mpfr-4.0.2.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. See also the latest Fossies "Diffs" side-by-side code changes report for "tset_exp.c": 4.0.1_vs_4.0.2.

    1 /* Test file for mpfr_get_exp and mpfr_set_exp.
    2 
    3 Copyright 2004, 2006-2019 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 (int argc, char *argv[])
   27 {
   28   mpfr_t x;
   29   int ret;
   30   mpfr_exp_t emin, emax, e;
   31 
   32   tests_start_mpfr ();
   33 
   34   emin = mpfr_get_emin ();
   35   emax = mpfr_get_emax ();
   36 
   37   mpfr_init2 (x, 53);
   38 
   39   mpfr_set_ui (x, 1, MPFR_RNDN);
   40   ret = mpfr_set_exp (x, 2);
   41   MPFR_ASSERTN (ret == 0 && mpfr_cmp_ui (x, 2) == 0);
   42   e = mpfr_get_exp (x);
   43   MPFR_ASSERTN (e == 2);
   44   e = (mpfr_get_exp) (x);
   45   MPFR_ASSERTN (e == 2);
   46 
   47   ret = mpfr_set_exp (x, emax);
   48   e = mpfr_get_exp (x);
   49   MPFR_ASSERTN (e == emax);
   50   e = (mpfr_get_exp) (x);
   51   MPFR_ASSERTN (e == emax);
   52 
   53   ret = mpfr_set_exp (x, emin);
   54   e = mpfr_get_exp (x);
   55   MPFR_ASSERTN (e == emin);
   56   e = (mpfr_get_exp) (x);
   57   MPFR_ASSERTN (e == emin);
   58 
   59   set_emin (-1);
   60 
   61   e = mpfr_get_exp (x);
   62   MPFR_ASSERTN (e == emin);
   63   e = (mpfr_get_exp) (x);
   64   MPFR_ASSERTN (e == emin);
   65 
   66   ret = mpfr_set_exp (x, -1);
   67   MPFR_ASSERTN (ret == 0 && mpfr_cmp_ui_2exp (x, 1, -2) == 0);
   68 
   69   set_emax (1);
   70   ret = mpfr_set_exp (x, 1);
   71   MPFR_ASSERTN (ret == 0 && mpfr_cmp_ui (x, 1) == 0);
   72 
   73   ret = mpfr_set_exp (x, -2);
   74   MPFR_ASSERTN (ret != 0 && mpfr_cmp_ui (x, 1) == 0);
   75 
   76   ret = mpfr_set_exp (x, 2);
   77   MPFR_ASSERTN (ret != 0 && mpfr_cmp_ui (x, 1) == 0);
   78 
   79   mpfr_clear (x);
   80 
   81   set_emin (emin);
   82   set_emax (emax);
   83 
   84   tests_end_mpfr ();
   85   return 0;
   86 }