1 /* tfma -- test file for mpc_fma.
3 Copyright (C) 2011, 2012 INRIA
5 This file is part of GNU MPC.
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.
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
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/ .
21 #include "mpc-tests.h"
24 cmpfma (mpc_srcptr a, mpc_srcptr b, mpc_srcptr c, mpc_rnd_t rnd)
25 /* computes a*b+c with the naive and fast functions using the rounding
26 mode rnd and compares the results and return values.
27 In our current test suite, all input precisions are the same, and we
28 use this precision also for the result.
34 mpc_init2 (z, MPC_MAX_PREC (a));
35 mpc_init2 (t, MPC_MAX_PREC (a));
37 inex_z = mpc_fma_naive (z, a, b, c, rnd);
38 inex_t = mpc_fma (t, a, b, c, rnd);
40 if (mpc_cmp (z, t) != 0 || inex_z != inex_t) {
41 fprintf (stderr, "fma_naive and fma differ for rnd=(%s,%s)\n",
42 mpfr_print_rnd_mode(MPC_RND_RE(rnd)),
43 mpfr_print_rnd_mode(MPC_RND_IM(rnd)));
49 if (inex_z != inex_t) {
50 fprintf (stderr, "inex_re (z): %s\n", MPC_INEX_STR (inex_z));
51 fprintf (stderr, "inex_re (t): %s\n", MPC_INEX_STR (inex_t));
72 for (prec = 2; prec < 1000; prec = (mpfr_prec_t) (prec * 1.1 + 1)) {
73 mpc_set_prec (a, prec);
74 mpc_set_prec (b, prec);
75 mpc_set_prec (c, prec);
77 test_default_random (a, -1024, 1024, 128, 0);
78 test_default_random (b, -1024, 1024, 128, 0);
79 test_default_random (c, -1024, 1024, 128, 0);
81 for (rnd_re = 0; rnd_re < 4; rnd_re ++)
82 for (rnd_im = 0; rnd_im < 4; rnd_im ++)
83 cmpfma (a, b, c, MPC_RND (rnd_re, rnd_im));
95 DECL_FUNC (CCCC, f, mpc_fma);
101 data_check (f, "fma.dat");
102 tgeneric (f, 2, 1024, 1, 256);