Home | History | Annotate | Line # | Download | only in tests
tsum.c revision 1.1.1.1
      1  1.1  mrg /* tsum -- test file for mpc_sum.
      2  1.1  mrg 
      3  1.1  mrg Copyright (C) 2018 INRIA
      4  1.1  mrg 
      5  1.1  mrg This file is part of GNU MPC.
      6  1.1  mrg 
      7  1.1  mrg GNU MPC is free software; you can redistribute it and/or modify it under
      8  1.1  mrg the terms of the GNU Lesser General Public License as published by the
      9  1.1  mrg Free Software Foundation; either version 3 of the License, or (at your
     10  1.1  mrg option) any later version.
     11  1.1  mrg 
     12  1.1  mrg GNU MPC is distributed in the hope that it will be useful, but WITHOUT ANY
     13  1.1  mrg WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
     14  1.1  mrg FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for
     15  1.1  mrg more details.
     16  1.1  mrg 
     17  1.1  mrg You should have received a copy of the GNU Lesser General Public License
     18  1.1  mrg along with this program. If not, see http://www.gnu.org/licenses/ .
     19  1.1  mrg */
     20  1.1  mrg 
     21  1.1  mrg #include "mpc-tests.h"
     22  1.1  mrg 
     23  1.1  mrg static void
     24  1.1  mrg check_special (void)
     25  1.1  mrg {
     26  1.1  mrg   mpc_t z[3], res;
     27  1.1  mrg   mpc_ptr t[3];
     28  1.1  mrg   int i, inex;
     29  1.1  mrg 
     30  1.1  mrg   for (i = 0; i < 3; i++)
     31  1.1  mrg     {
     32  1.1  mrg       mpc_init2 (z[i], 17);
     33  1.1  mrg       mpc_set_ui_ui (z[i], i+1, i+2, MPC_RNDNN);
     34  1.1  mrg       t[i] = z[i];
     35  1.1  mrg     }
     36  1.1  mrg   mpc_init2 (res, 17);
     37  1.1  mrg   inex = mpc_sum (res, t, 0, MPC_RNDNN);
     38  1.1  mrg   MPC_ASSERT (inex == 0);
     39  1.1  mrg   MPC_ASSERT (mpfr_cmp_ui (mpc_realref (res), 0) == 0);
     40  1.1  mrg   MPC_ASSERT (mpfr_cmp_ui (mpc_imagref (res), 0) == 0);
     41  1.1  mrg   inex = mpc_sum (res, t, 1, MPC_RNDNN);
     42  1.1  mrg   MPC_ASSERT (inex == 0);
     43  1.1  mrg   MPC_ASSERT (mpfr_cmp_ui (mpc_realref (res), 1) == 0);
     44  1.1  mrg   MPC_ASSERT (mpfr_cmp_ui (mpc_imagref (res), 2) == 0);
     45  1.1  mrg   inex = mpc_sum (res, t, 2, MPC_RNDNN);
     46  1.1  mrg   MPC_ASSERT (inex == 0);
     47  1.1  mrg   MPC_ASSERT (mpfr_cmp_ui (mpc_realref (res), 3) == 0);
     48  1.1  mrg   MPC_ASSERT (mpfr_cmp_ui (mpc_imagref (res), 5) == 0);
     49  1.1  mrg   inex = mpc_sum (res, t, 3, MPC_RNDNN);
     50  1.1  mrg   MPC_ASSERT (inex == 0);
     51  1.1  mrg   MPC_ASSERT (mpfr_cmp_ui (mpc_realref (res), 6) == 0);
     52  1.1  mrg   MPC_ASSERT (mpfr_cmp_ui (mpc_imagref (res), 9) == 0);
     53  1.1  mrg   for (i = 0; i < 3; i++)
     54  1.1  mrg     mpc_clear (z[i]);
     55  1.1  mrg   mpc_clear (res);
     56  1.1  mrg }
     57  1.1  mrg 
     58  1.1  mrg int
     59  1.1  mrg main (void)
     60  1.1  mrg {
     61  1.1  mrg   test_start ();
     62  1.1  mrg 
     63  1.1  mrg   check_special ();
     64  1.1  mrg 
     65  1.1  mrg   test_end ();
     66  1.1  mrg 
     67  1.1  mrg   return 0;
     68  1.1  mrg }
     69  1.1  mrg 
     70