1 /* tacos -- test file for mpc_acos.
2 
3 Copyright (C) 2009, 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 #define MPC_FUNCTION_CALL                                       \
24   P[0].mpc_inex = mpc_acos (P[1].mpc, P[2].mpc, P[3].mpc_rnd)
25 #define MPC_FUNCTION_CALL_REUSE_OP1                             \
26   P[0].mpc_inex = mpc_acos (P[1].mpc, P[1].mpc, P[3].mpc_rnd)
27 
28 #include "data_check.tpl"
29 #include "tgeneric.tpl"
30 
31 /* test with reduced exponent range */
32 static void
test_reduced(void)33 test_reduced (void)
34 {
35   mpfr_exp_t emin = mpfr_get_emin ();
36   mpfr_exp_t emax = mpfr_get_emax ();
37   mpc_t x, z, zr;
38 
39   mpfr_set_emin (-148);
40   mpfr_set_emax (128);
41   mpc_init2 (x, 24);
42   mpc_init2 (z, 24);
43   mpc_init2 (zr, 24);
44   mpfr_set_flt (mpc_realref (x), -0x0.01f28c10p0f, MPFR_RNDN);
45   mpfr_set_flt (mpc_imagref (x), -0x6.79cdd0p-68f, MPFR_RNDN);
46   mpc_acos (z, x, MPC_RNDNN);
47   mpfr_set_flt (mpc_realref (zr), 0x1.941242p0f, MPFR_RNDN);
48   mpfr_set_flt (mpc_imagref (zr), 0x6.79da18p-68f, MPFR_RNDN);
49   if (mpc_cmp (z, zr))
50     {
51       printf ("Incorrect acos with reduced exponent range:\n");
52       mpfr_printf ("Expected (%Re,%Re)\n", mpc_realref (zr), mpc_imagref (zr));
53       mpfr_printf ("Got      (%Re,%Re)\n", mpc_realref (z), mpc_imagref (z));
54       exit (1);
55     }
56   mpc_clear (x);
57   mpc_clear (z);
58   mpc_clear (zr);
59   mpfr_set_emin (emin);
60   mpfr_set_emax (emax);
61 }
62 
63 /* another test with reduced exponent range */
64 static void
test_reduced2(void)65 test_reduced2 (void)
66 {
67   mpfr_exp_t emin = mpfr_get_emin ();
68   mpfr_exp_t emax = mpfr_get_emax ();
69   mpc_t x, z, zr;
70 
71   mpfr_set_emin (-1073);
72   mpfr_set_emax (1024);
73   mpc_init2 (x, 53);
74   mpc_init2 (z, 53);
75   mpc_init2 (zr, 53);
76   mpfr_set_d (mpc_realref (x), -2.2694475687286223e-15, MPFR_RNDN);
77   mpfr_set_d (mpc_imagref (x), 2.7236935900137536e-309, MPFR_RNDN);
78   mpc_acos (z, x, MPC_RNDNN);
79   mpfr_set_d (mpc_realref (zr), 1.5707963267948988, MPFR_RNDN);
80   mpfr_set_d (mpc_imagref (zr), -2.7236935900137536e-309, MPFR_RNDN);
81   if (mpc_cmp (z, zr))
82     {
83       printf ("Incorrect acos with reduced exponent range:\n");
84       mpfr_printf ("Expected (%Re,%Re)\n", mpc_realref (zr), mpc_imagref (zr));
85       mpfr_printf ("Got      (%Re,%Re)\n", mpc_realref (z), mpc_imagref (z));
86       exit (1);
87     }
88   mpc_clear (x);
89   mpc_clear (z);
90   mpc_clear (zr);
91   mpfr_set_emin (emin);
92   mpfr_set_emax (emax);
93 }
94 
95 int
main(void)96 main (void)
97 {
98   test_start ();
99 
100   test_reduced ();
101   test_reduced2 ();
102 
103   data_check_template ("acos.dsc", "acos.dat");
104 
105   tgeneric_template ("acos.dsc", 2, 512, 7, 7);
106 
107   test_end ();
108 
109   return 0;
110 }
111