xref: /netbsd-src/external/lgpl3/mpc/dist/tests/tui_div.c (revision 39f28e1e142c5bfb6be935a49cb55e2287fec7ea)
1 /* tui_div -- test file for mpc_ui_div.
2 
3 Copyright (C) 2008, 2011, 2012, 2013 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
test_special(void)24 test_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, MPFR_RNDN);
45   mpfr_set_str (mpc_imagref(a), "-0", 10, MPFR_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 #define MPC_FUNCTION_CALL                                               \
89   P[0].mpc_inex = mpc_ui_div (P[1].mpc, P[2].ui, P[3].mpc, P[4].mpc_rnd)
90 #define MPC_FUNCTION_CALL_REUSE_OP2                                     \
91   P[0].mpc_inex = mpc_ui_div (P[1].mpc, P[2].ui, P[1].mpc, P[4].mpc_rnd)
92 
93 #include "tgeneric.tpl"
94 
95 int
main(void)96 main (void)
97 {
98   test_start ();
99 
100   test_special ();
101 
102   tgeneric_template ("ui_div.dsc", 2, 1024, 7, 4096);
103 
104   test_end ();
105 
106   return 0;
107 }
108