Exemple #1
0
static void
reuse_cc_c (mpc_function* function, mpc_srcptr z, mpc_ptr got1, mpc_ptr got2,
            mpc_ptr exp1, mpc_ptr exp2)
{
   known_signs_t ks = {1, 1};

   function->pointer.CC_C (exp1, exp2, z, MPC_RNDNN, MPC_RNDNN);
   mpc_set (got1, z, MPC_RNDNN); /* exact */
   function->pointer.CC_C (got1, got2, got1, MPC_RNDNN, MPC_RNDNN);
   if (   !same_mpc_value (got1, exp1, ks)
       || !same_mpc_value (got2, exp2, ks)) {
      printf ("Reuse error in first result of %s for\n", function->name);
      MPC_OUT (z);
      MPC_OUT (exp1);
      MPC_OUT (got1);
      MPC_OUT (exp2);
      MPC_OUT (got2);
      exit (1);
   }
   mpc_set (got2, z, MPC_RNDNN); /* exact */
   function->pointer.CC_C (got1, got2, got2, MPC_RNDNN, MPC_RNDNN);
   if (   !same_mpc_value (got1, exp1, ks)
       || !same_mpc_value (got2, exp2, ks)) {
      printf ("Reuse error in second result of %s for\n", function->name);
      MPC_OUT (z);
      MPC_OUT (exp1);
      MPC_OUT (got1);
      MPC_OUT (exp2);
      MPC_OUT (got2);
      exit (1);
   }
}
Exemple #2
0
static void
tgeneric_cc_c (mpc_function *function, mpc_ptr op, mpc_ptr rop1, mpc_ptr rop2,
   mpc_ptr rop14, mpc_ptr rop24, mpc_ptr rop14rnd, mpc_ptr rop24rnd,
   mpc_rnd_t rnd1, mpc_rnd_t rnd2)
{
   /* same as the previous function, but for mpc functions computing two
      results from one argument                                          */
   known_signs_t ks = {1, 1};

   function->pointer.CC_C (rop14, rop24, op, rnd1, rnd2);
   function->pointer.CC_C (rop1,  rop2,  op, rnd1, rnd2);

   if (   MPFR_CAN_ROUND (mpc_realref (rop14), 1, MPC_PREC_RE (rop1),
                          MPC_RND_RE (rnd1))
       && MPFR_CAN_ROUND (mpc_imagref (rop14), 1, MPC_PREC_IM (rop1),
                          MPC_RND_IM (rnd1))
       && MPFR_CAN_ROUND (mpc_realref (rop24), 1, MPC_PREC_RE (rop2),
                          MPC_RND_RE (rnd2))
       && MPFR_CAN_ROUND (mpc_imagref (rop24), 1, MPC_PREC_IM (rop2),
                          MPC_RND_IM (rnd2))) {
     mpc_set (rop14rnd, rop14, rnd1);
     mpc_set (rop24rnd, rop24, rnd2);
   }
   else
     return;

   if (!same_mpc_value (rop1, rop14rnd, ks)) {
      /* rounding failed for first result */
      printf ("Rounding might be incorrect for the first result of %s at\n", function->name);
      MPC_OUT (op);
      printf ("with rounding mode (%s, %s)",
          mpfr_print_rnd_mode (MPC_RND_RE (rnd1)),
          mpfr_print_rnd_mode (MPC_RND_IM (rnd1)));
      printf ("\n%s                     gives ", function->name);
      MPC_OUT (rop1);
      printf ("%s quadruple precision gives ", function->name);
      MPC_OUT (rop14);
      printf ("and is rounded to                  ");
      MPC_OUT (rop14rnd);
      exit (1);
   }
   else if (!same_mpc_value (rop2, rop24rnd, ks)) {
      /* rounding failed for second result */
      printf ("Rounding might be incorrect for the second result of %s at\n", function->name);
      MPC_OUT (op);
      printf ("with rounding mode (%s, %s)",
          mpfr_print_rnd_mode (MPC_RND_RE (rnd2)),
          mpfr_print_rnd_mode (MPC_RND_IM (rnd2)));
      printf ("\n%s                     gives ", function->name);
      MPC_OUT (rop2);
      printf ("%s quadruple precision gives ", function->name);
      MPC_OUT (rop24);
      printf ("and is rounded to                  ");
      MPC_OUT (rop24rnd);
      exit (1);
   }
}
Exemple #3
0
static void
tgeneric_cci (mpc_function *function, mpc_ptr op1, int op2,
              mpc_ptr rop, mpc_ptr rop4, mpc_ptr rop4rnd, mpc_rnd_t rnd)
{
  known_signs_t ks = {1, 1};

  function->pointer.CCI (rop4, op1, op2, rnd);
  function->pointer.CCI (rop, op1, op2, rnd);
  if (MPFR_CAN_ROUND (mpc_realref (rop4), 1, MPC_PREC_RE (rop),
                      MPC_RND_RE (rnd))
      && MPFR_CAN_ROUND (mpc_imagref (rop4), 1, MPC_PREC_IM (rop),
                         MPC_RND_IM (rnd)))
    mpc_set (rop4rnd, rop4, rnd);
  else
    return;

  if (same_mpc_value (rop, rop4rnd, ks))
    return;

  printf ("Rounding in %s might be incorrect for\n", function->name);
  MPC_OUT (op1);
  printf ("op2=%d\n", op2);
  printf ("with rounding mode (%s, %s)",
          mpfr_print_rnd_mode (MPC_RND_RE (rnd)),
          mpfr_print_rnd_mode (MPC_RND_IM (rnd)));

  printf ("\n%s                     gives ", function->name);
  MPC_OUT (rop);
  printf ("%s quadruple precision gives ", function->name);
  MPC_OUT (rop4);
  printf ("and is rounded to                  ");
  MPC_OUT (rop4rnd);

  exit (1);
}
Exemple #4
0
/* for functions with one mpc_t output, two mpc_t inputs */
static void
reuse_c_cc (mpc_function* function, mpc_srcptr z, mpc_srcptr x,
           mpc_ptr got, mpc_ptr expected)
{
  known_signs_t ks = {1, 1};

  mpc_set (got, z, MPC_RNDNN); /* exact */
  function->pointer.C_CC (expected, z, x, MPC_RNDNN);
  function->pointer.C_CC (got, got, x, MPC_RNDNN);
  if (!same_mpc_value (got, expected, ks))
    {
      printf ("Reuse error for %s(z, z, x) for\n", function->name);
      MPC_OUT (z);
      MPC_OUT (x);
      MPC_OUT (expected);
      MPC_OUT (got);

      exit (1);
    }
  mpc_set (got, x, MPC_RNDNN); /* exact */
  function->pointer.C_CC (expected, z, x, MPC_RNDNN);
  function->pointer.C_CC (got, z, got, MPC_RNDNN);
  if (!same_mpc_value (got, expected, ks))
    {
      printf ("Reuse error for %s(x, z, x) for\n", function->name);
      MPC_OUT (z);
      MPC_OUT (x);
      MPC_OUT (expected);
      MPC_OUT (got);

      exit (1);
    }
  mpc_set (got, x, MPC_RNDNN); /* exact */
  function->pointer.C_CC (expected, x, x, MPC_RNDNN);
  function->pointer.C_CC (got, got, got, MPC_RNDNN);
  if (!same_mpc_value (got, expected, ks))
    {
      printf ("Reuse error for %s(x, x, x) for\n", function->name);
      MPC_OUT (x);
      MPC_OUT (expected);
      MPC_OUT (got);

      exit (1);
    }
}
Exemple #5
0
/* functions with one input, one output */
static void
tgeneric_cc (mpc_function *function, mpc_ptr op, mpc_ptr rop,
             mpc_ptr rop4, mpc_ptr rop4rnd, mpc_rnd_t rnd)
{
  known_signs_t ks = {1, 1};

  /* We compute the result with four times the precision and check whether the
     rounding is correct. Error reports in this part of the algorithm might
     still be wrong, though, since there are two consecutive roundings (but we
     try to avoid them).  */
  function->pointer.CC (rop4, op, rnd);
  function->pointer.CC (rop, op, rnd);

  /* can't use the mpfr_can_round function when argument is singular,
     use a custom macro instead. */
  if (MPFR_CAN_ROUND (mpc_realref (rop4), 1, MPC_PREC_RE (rop),
                      MPC_RND_RE (rnd))
      && MPFR_CAN_ROUND (mpc_imagref (rop4), 1, MPC_PREC_IM (rop),
                         MPC_RND_IM (rnd)))
    mpc_set (rop4rnd, rop4, rnd);
  else
    /* avoid double rounding error */
    return;

  if (same_mpc_value (rop, rop4rnd, ks))
    return;

  /* rounding failed */
  printf ("Rounding in %s might be incorrect for\n", function->name);
  MPC_OUT (op);

  printf ("with rounding mode (%s, %s)",
          mpfr_print_rnd_mode (MPC_RND_RE (rnd)),
          mpfr_print_rnd_mode (MPC_RND_IM (rnd)));

  printf ("\n%s                     gives ", function->name);
  MPC_OUT (rop);
  printf ("%s quadruple precision gives ", function->name);
  MPC_OUT (rop4);
  printf ("and is rounded to                  ");
  MPC_OUT (rop4rnd);

  exit (1);
}
Exemple #6
0
static void
reuse_cci (mpc_function* function, mpc_srcptr z, int i,
           mpc_ptr got, mpc_ptr expected)
{
  known_signs_t ks = {1, 1};

  mpc_set (got, z, MPC_RNDNN); /* exact */
  function->pointer.CCI (expected, z, i, MPC_RNDNN);
  function->pointer.CCI (got, got, i, MPC_RNDNN);
  if (!same_mpc_value (got, expected, ks))
    {
      printf ("Reuse error for %s(z, z, n) for\n", function->name);
      MPC_OUT (z);
      printf ("n=%d\n", i);
      MPC_OUT (expected);
      MPC_OUT (got);

      exit (1);
    }
}
Exemple #7
0
static void
reuse_cuc (mpc_function* function, unsigned long ul, mpc_srcptr z,
           mpc_ptr got, mpc_ptr expected)
{
  known_signs_t ks = {1, 1};

  mpc_set (got, z, MPC_RNDNN); /* exact */
  function->pointer.CUC (expected, ul, z,MPC_RNDNN);
  function->pointer.CUC (got, ul, got, MPC_RNDNN);
  if (!same_mpc_value (got, expected, ks))
    {
      printf ("Reuse error for %s(z, n, z) for\n", function->name);
      printf ("n=%lu\n", ul);
      MPC_OUT (z);
      MPC_OUT (expected);
      MPC_OUT (got);

      exit (1);
    }
}
Exemple #8
0
static void
check_file (const char* file_name)
{
  FILE *fp;

  int tmp;
  int base;
  int inex_re;
  int inex_im;
  mpc_t expected, got;
  mpc_rnd_t rnd = MPC_RNDNN;
  int inex = 0, expected_inex;
  size_t expected_size, size;
  known_signs_t ks = {1, 1};

  fp = open_data_file (file_name);

  mpc_init2 (expected, 53);
  mpc_init2 (got, 53);

  /* read data file */
  line_number = 1;
  nextchar = getc (fp);
  skip_whitespace_comments (fp);

  while (nextchar != EOF)
    {
      /* 1. read a line of data: expected result, base, rounding mode */
      read_ternary (fp, &inex_re);
      read_ternary (fp, &inex_im);
      read_mpc (fp, expected, &ks);
      if (inex_re == TERNARY_ERROR || inex_im == TERNARY_ERROR)
         expected_inex = -1;
      else
         expected_inex = MPC_INEX (inex_re, inex_im);
      read_int (fp, &tmp, "size");
      expected_size = (size_t)tmp;
      read_int (fp, &base, "base");
      read_mpc_rounding_mode (fp, &rnd);

      /* 2. read string at the same precision as the expected result */
      while (nextchar != '"')
        nextchar = getc (fp);
      mpfr_set_prec (MPC_RE (got), MPC_PREC_RE (expected));
      mpfr_set_prec (MPC_IM (got), MPC_PREC_IM (expected));
      inex = mpc_inp_str (got, fp, &size, base, rnd);

      /* 3. compare this result with the expected one */
      if (inex != expected_inex || !same_mpc_value (got, expected, ks)
          || size != expected_size)
        {
          printf ("mpc_inp_str failed (line %lu) with rounding mode %s\n",
                  line_number, rnd_mode[rnd]);
          if (inex != expected_inex)
            printf("     got inexact value: %d\nexpected inexact value: %d\n",
                   inex, expected_inex);
          if (size !=  expected_size)
            printf ("     got size: %lu\nexpected size: %lu\n     ",
                    (unsigned long int) size, (unsigned long int) expected_size);
          printf ("    ");
          OUT (got);
          OUT (expected);

          exit (1);
        }

      while ((nextchar = getc (fp)) != '"');
      nextchar = getc (fp);

      skip_whitespace_comments (fp);
    }

  mpc_clear (expected);
  mpc_clear (got);
  close_data_file (fp);
}