resetting manifest requested domain to floor
[platform/upstream/mpc.git] / tests / tui_div.c
1 /* tui_div -- test file for mpc_ui_div.
2
3 Copyright (C) 2008, 2011 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 special (void)
25 {
26   mpc_t a, b;
27
28   mpc_init2 (a, 10);
29   mpc_init2 (b, 10);
30
31   mpc_set_ui_ui (a, 2, 4, MPC_RNDNN);
32   mpc_ui_div (b, 10, a, MPC_RNDNN);
33   if (mpc_cmp_si_si (b, 1, -2) != 0)
34     {
35       printf ("10/(2,4) failed\n");
36       printf ("expected (1,-2)\n");
37       printf ("got      ");
38       mpc_out_str (stdout, 10, 0, b, MPC_RNDNN);
39       printf ("\n");
40       exit (1);
41     }
42
43   /* 0/(-1-0*I) should give (-0, +0) */
44   mpfr_set_str (mpc_realref(a), "-1", 10, GMP_RNDN);
45   mpfr_set_str (mpc_imagref(a), "-0", 10, GMP_RNDN);
46   mpc_ui_div (b, 0, a, MPC_RNDNN);
47   if ((mpc_cmp_si_si (b, 0, 0) != 0) || (MPFR_SIGN (mpc_realref(b)) > 0)
48       || (MPFR_SIGN (mpc_imagref(b)) < 0))
49     {
50       printf ("0/(-1,-0) failed\n");
51       printf ("expected (-0,+0)\n");
52       printf ("got      ");
53       mpc_out_str (stdout, 10, 0, b, MPC_RNDNN);
54       printf ("\n");
55       exit (1);
56     }
57
58   mpc_set_ui_ui (a, 1, 0, MPC_RNDNN);
59   mpc_ui_div (b, 1, a, MPC_RNDNN);
60   if (mpc_cmp_si_si (b, 1, 0) != 0)
61     {
62       printf ("1/(1,0) failed\n");
63       printf ("expected (1,0)\n");
64       printf ("got      ");
65       mpc_out_str (stdout, 10, 0, b, MPC_RNDNN);
66       printf ("\n");
67       exit (1);
68     }
69
70   /* problem reported by Timo Hartmann with mpc-0.7, 21 Oct 2009 */
71   mpc_set_ui_ui (a, 4, 0, MPC_RNDNN);
72   mpc_ui_div (b, 1, a, MPC_RNDNN);
73   if (mpfr_cmp_ui_2exp (mpc_realref(b), 1, -2) != 0 ||
74       mpfr_cmp_ui (mpc_imagref(b), 0) != 0 || mpfr_signbit (mpc_imagref(b)) != 0)
75     {
76       printf ("1/(4,0) failed\n");
77       printf ("expected (1/4,0)\n");
78       printf ("got      ");
79       mpc_out_str (stdout, 10, 0, b, MPC_RNDNN);
80       printf ("\n");
81       exit (1);
82     }
83
84   mpc_clear (a);
85   mpc_clear (b);
86 }
87
88 int
89 main (void)
90 {
91   DECL_FUNC (CUC, f, mpc_ui_div);
92
93   test_start ();
94
95   special ();
96
97   tgeneric (f, 2, 1024, 7, 4096);
98
99   test_end ();
100
101   return 0;
102 }