Import Upstream version 0.8.2
[platform/upstream/mpc.git] / tests / tmul_i.c
1 /* tmul_i -- test file for mpc_mul_i.
2
3 Copyright (C) 2008, 2009 Philippe Theveny
4
5 This file is part of the MPC Library.
6
7 The MPC Library is free software; you can redistribute it and/or modify
8 it under the terms of the GNU Lesser General Public License as published by
9 the Free Software Foundation; either version 2.1 of the License, or (at your
10 option) any later version.
11
12 The MPC Library is distributed in the hope that it will be useful, but
13 WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
14 or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public
15 License for more details.
16
17 You should have received a copy of the GNU Lesser General Public License
18 along with the MPC Library; see the file COPYING.LIB.  If not, write to
19 the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
20 MA 02111-1307, USA. */
21
22 #include "mpc-tests.h"
23
24 static void
25 check_different_precisions()
26 {
27   /* check reuse when real and imaginary part have different precisions. */
28   mpc_t z, expected, got;  
29   int res;
30
31   mpc_init2(z, 128);
32   mpc_init2(expected, 128);
33   mpc_init2(got, 128);
34
35   /* change precision of one part */
36   mpfr_set_prec (MPC_IM (z), 32);
37   mpfr_set_prec (MPC_IM (expected), 32);
38   mpfr_set_prec (MPC_IM (got), 32);
39
40   mpfr_set_str (MPC_RE (z), "0x100000000fp-32", 16, GMP_RNDN);
41   mpfr_set_str (MPC_IM (z), "-1", 2, GMP_RNDN);
42   mpfr_set_str (MPC_RE (expected), "+1", 2, GMP_RNDN);
43   mpfr_set_str (MPC_IM (expected), "0x100000000fp-32", 16, GMP_RNDN);
44
45   mpc_set (got, z, MPC_RNDNN);
46   res = mpc_mul_i (got, got, +1, MPC_RNDNN);
47   if (MPC_INEX_RE(res) != 0 || MPC_INEX_IM(res) >=0)
48     {
49       printf("Wrong inexact flag for mpc_mul_i(z, z, n)\n"
50              "     got (re=%2d, im=%2d)\nexpected (re= 0, im=-1)\n",
51              MPC_INEX_RE(res), MPC_INEX_IM(res));
52       exit(1);
53     }
54   if (mpc_cmp(got, expected) != 0)
55     {
56       printf ("Error for mpc_mul_i(z, z, n) for\n");
57       OUT (z);
58       printf ("n=+1\n");
59       OUT (expected);
60       OUT (got);
61
62       exit (1);
63     }
64
65   mpc_neg (expected, expected, MPC_RNDNN);
66   mpc_set (got, z, MPC_RNDNN);
67   mpc_mul_i (got, got, -1, MPC_RNDNN);
68   if (mpc_cmp(got, expected) != 0)
69     {
70       printf ("Error for mpc_mul_i(z, z, n) for\n");
71       OUT (z);
72       printf ("n=-1\n");
73       OUT (expected);
74       OUT (got);
75
76       exit (1);
77     }
78
79   mpc_clear (z);
80   mpc_clear (expected);
81   mpc_clear (got);
82 }
83
84 int
85 main (void)
86 {
87   DECL_FUNC (CCI, f, mpc_mul_i);
88
89   test_start ();
90
91   check_different_precisions ();
92   tgeneric (f, 2, 1024, 7, -1);
93
94   test_end ();
95
96   return 0;
97 }