Blame tests/tfma.c

Packit 80c72f
/* tfma -- test file for mpc_fma.
Packit 80c72f
Packit 80c72f
Copyright (C) 2011, 2012 INRIA
Packit 80c72f
Packit 80c72f
This file is part of GNU MPC.
Packit 80c72f
Packit 80c72f
GNU MPC is free software; you can redistribute it and/or modify it under
Packit 80c72f
the terms of the GNU Lesser General Public License as published by the
Packit 80c72f
Free Software Foundation; either version 3 of the License, or (at your
Packit 80c72f
option) any later version.
Packit 80c72f
Packit 80c72f
GNU MPC is distributed in the hope that it will be useful, but WITHOUT ANY
Packit 80c72f
WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
Packit 80c72f
FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for
Packit 80c72f
more details.
Packit 80c72f
Packit 80c72f
You should have received a copy of the GNU Lesser General Public License
Packit 80c72f
along with this program. If not, see http://www.gnu.org/licenses/ .
Packit 80c72f
*/
Packit 80c72f
Packit 80c72f
#include "mpc-tests.h"
Packit 80c72f
Packit 80c72f
static void
Packit 80c72f
cmpfma (mpc_srcptr a, mpc_srcptr b, mpc_srcptr c, mpc_rnd_t rnd)
Packit 80c72f
   /* computes a*b+c with the naive and fast functions using the rounding
Packit 80c72f
      mode rnd and compares the results and return values.                                          
Packit 80c72f
      In our current test suite, all input precisions are the same, and we
Packit 80c72f
      use this precision also for the result.
Packit 80c72f
   */
Packit 80c72f
{
Packit 80c72f
   mpc_t z, t;
Packit 80c72f
   int   inex_z, inex_t;
Packit 80c72f
Packit 80c72f
   mpc_init2 (z, MPC_MAX_PREC (a));
Packit 80c72f
   mpc_init2 (t, MPC_MAX_PREC (a));
Packit 80c72f
Packit 80c72f
   inex_z = mpc_fma_naive (z, a, b, c, rnd);
Packit 80c72f
   inex_t = mpc_fma (t, a, b, c, rnd);
Packit 80c72f
Packit 80c72f
   if (mpc_cmp (z, t) != 0 || inex_z != inex_t) {
Packit 80c72f
      fprintf (stderr, "fma_naive and fma differ for rnd=(%s,%s)\n",
Packit 80c72f
               mpfr_print_rnd_mode(MPC_RND_RE(rnd)),
Packit 80c72f
               mpfr_print_rnd_mode(MPC_RND_IM(rnd)));
Packit 80c72f
      MPC_OUT (a);
Packit 80c72f
      MPC_OUT (b);
Packit 80c72f
      MPC_OUT (c);
Packit 80c72f
      MPC_OUT (z);
Packit 80c72f
      MPC_OUT (t);
Packit 80c72f
      if (inex_z != inex_t) {
Packit 80c72f
         fprintf (stderr, "inex_re (z): %s\n", MPC_INEX_STR (inex_z));
Packit 80c72f
         fprintf (stderr, "inex_re (t): %s\n", MPC_INEX_STR (inex_t));
Packit 80c72f
      }
Packit 80c72f
      exit (1);
Packit 80c72f
   }
Packit 80c72f
Packit 80c72f
  mpc_clear (z);
Packit 80c72f
  mpc_clear (t);
Packit 80c72f
}
Packit 80c72f
Packit 80c72f
Packit 80c72f
static void
Packit 80c72f
check_random (void)
Packit 80c72f
{
Packit 80c72f
   mpfr_prec_t prec;
Packit 80c72f
   int rnd_re, rnd_im;
Packit 80c72f
   mpc_t a, b, c;
Packit 80c72f
Packit 80c72f
   mpc_init2 (a, 1000);
Packit 80c72f
   mpc_init2 (b, 1000);
Packit 80c72f
   mpc_init2 (c, 1000);
Packit 80c72f
Packit 80c72f
   for (prec = 2; prec < 1000; prec = (mpfr_prec_t) (prec * 1.1 + 1)) {
Packit 80c72f
      mpc_set_prec (a, prec);
Packit 80c72f
      mpc_set_prec (b, prec);
Packit 80c72f
      mpc_set_prec (c, prec);
Packit 80c72f
Packit 80c72f
      test_default_random (a, -1024, 1024, 128, 0);
Packit 80c72f
      test_default_random (b, -1024, 1024, 128, 0);
Packit 80c72f
      test_default_random (c, -1024, 1024, 128, 0);
Packit 80c72f
Packit 80c72f
      for (rnd_re = 0; rnd_re < 4; rnd_re ++)
Packit 80c72f
         for (rnd_im = 0; rnd_im < 4; rnd_im ++)
Packit 80c72f
            cmpfma (a, b, c, MPC_RND (rnd_re, rnd_im));
Packit 80c72f
   }
Packit 80c72f
Packit 80c72f
   mpc_clear (a);
Packit 80c72f
   mpc_clear (b);
Packit 80c72f
   mpc_clear (c);
Packit 80c72f
}
Packit 80c72f
Packit 80c72f
Packit 80c72f
int
Packit 80c72f
main (void)
Packit 80c72f
{
Packit 80c72f
  DECL_FUNC (CCCC, f, mpc_fma);
Packit 80c72f
Packit 80c72f
  test_start ();
Packit 80c72f
Packit 80c72f
  check_random ();
Packit 80c72f
Packit 80c72f
  data_check (f, "fma.dat");
Packit 80c72f
  tgeneric (f, 2, 1024, 1, 256);
Packit 80c72f
Packit 80c72f
  test_end ();
Packit 80c72f
Packit 80c72f
  return 0;
Packit 80c72f
}