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