1 /* tdiv -- test file for mpc_div.
2 
3 Copyright (C) 2002, 2008, 2009, 2011, 2013, 2020 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 <stdlib.h>
22 #include "mpc-tests.h"
23 
24 #define MPC_FUNCTION_CALL                                               \
25   P[0].mpc_inex = mpc_div (P[1].mpc, P[2].mpc, P[3].mpc, P[4].mpc_rnd)
26 #define MPC_FUNCTION_CALL_REUSE_OP1                                     \
27   P[0].mpc_inex = mpc_div (P[1].mpc, P[1].mpc, P[3].mpc, P[4].mpc_rnd)
28 #define MPC_FUNCTION_CALL_REUSE_OP2                                     \
29   P[0].mpc_inex = mpc_div (P[1].mpc, P[2].mpc, P[1].mpc, P[4].mpc_rnd)
30 
31 #include "data_check.tpl"
32 #include "tgeneric.tpl"
33 
34 static void
bug20200206(void)35 bug20200206 (void)
36 {
37   mpfr_exp_t emin = mpfr_get_emin ();
38   mpfr_exp_t emax = mpfr_get_emax ();
39   mpc_t x, y, z, zr;
40 
41   mpfr_set_emin (-1073);
42   mpfr_set_emax (0);
43   mpc_init2 (x, 53);
44   mpc_init2 (y, 53);
45   mpc_init2 (z, 53);
46   mpc_init2 (zr, 53);
47   mpfr_set_d (mpc_realref (x), -5.3310997889069899e-216, MPFR_RNDN);
48   mpfr_set_d (mpc_imagref (x), -4.9188093228194944e-89, MPFR_RNDN);
49   mpfr_set_d (mpc_realref (y), -3.6801500191882962e-14, MPFR_RNDN);
50   mpfr_set_d (mpc_imagref (y), 4.5420247980297260e-145, MPFR_RNDN);
51   mpc_div (z, x, y, MPC_RNDNN);
52   /* quotient is 1.44844440684571e-202 + 1.33657848108714e-75*I,
53      where both the real and imaginary parts fit in the exponent range */
54   mpfr_set_d (mpc_realref (zr), 0x2.d69b18295a8cep-672, MPFR_RNDN);
55   mpfr_set_d (mpc_imagref (zr), 0x9.ac3e51d39eea8p-252, MPFR_RNDN);
56   if (mpc_cmp (z, zr))
57     {
58       printf ("Incorrect division with reduced exponent range:\n");
59       mpfr_printf ("Expected (%Re,%Re)\n", mpc_realref (zr), mpc_imagref (zr));
60       mpfr_printf ("Got      (%Re,%Re)\n", mpc_realref (z), mpc_imagref (z));
61       exit (1);
62     }
63   mpc_clear (x);
64   mpc_clear (y);
65   mpc_clear (z);
66   mpc_clear (zr);
67   mpfr_set_emin (emin);
68   mpfr_set_emax (emax);
69 }
70 
71 int
main(void)72 main (void)
73 {
74   test_start ();
75 
76   bug20200206 ();
77   data_check_template ("div.dsc", "div.dat");
78 
79   tgeneric_template ("div.dsc", 2, 1024, 7, 4096);
80 
81   test_end ();
82 
83   return 0;
84 }
85