Home | History | Annotate | Line # | Download | only in tests
      1 /* tsqrt -- test file for mpc_sqrt.
      2 
      3 Copyright (C) 2008, 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 "mpc-tests.h"
     22 
     23 #define MPC_FUNCTION_CALL                                       \
     24   P[0].mpc_inex = mpc_sqrt (P[1].mpc, P[2].mpc, P[3].mpc_rnd)
     25 #define MPC_FUNCTION_CALL_REUSE_OP1                             \
     26   P[0].mpc_inex = mpc_sqrt (P[1].mpc, P[1].mpc, P[3].mpc_rnd)
     27 
     28 #include "data_check.tpl"
     29 #include "tgeneric.tpl"
     30 
     31 /* check with reduced exponent range */
     32 static void
     33 bug20200207 (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_d (mpc_realref (x), -1.89432151320234e24, MPFR_RNDN);
     45   mpfr_set_d (mpc_imagref (x), -1.06397209600000e9, MPFR_RNDN);
     46   mpc_sqrt (z, x, MPC_RNDNN);
     47   /* square root is 0.00038652126908433 - 1.37634353022868e12*I */
     48   mpfr_set_d (mpc_realref (zr), 0.00038652126908433, MPFR_RNDN);
     49   mpfr_set_d (mpc_imagref (zr), -1.37634353022868e12, MPFR_RNDN);
     50   if (mpc_cmp (z, zr))
     51     {
     52       printf ("Incorrect square root with reduced exponent range:\n");
     53       mpfr_printf ("Expected (%Re,%Re)\n", mpc_realref (zr), mpc_imagref (zr));
     54       mpfr_printf ("Got      (%Re,%Re)\n", mpc_realref (z), mpc_imagref (z));
     55       exit (1);
     56     }
     57   mpc_clear (x);
     58   mpc_clear (z);
     59   mpc_clear (zr);
     60   mpfr_set_emin (emin);
     61   mpfr_set_emax (emax);
     62 }
     63 
     64 int
     65 main (void)
     66 {
     67   test_start ();
     68 
     69   bug20200207 ();
     70   data_check_template ("sqrt.dsc", "sqrt.dat");
     71 
     72   tgeneric_template ("sqrt.dsc", 2, 1024, 7, 256);
     73 
     74   test_end ();
     75 
     76   return 0;
     77 }
     78