diff options
Diffstat (limited to 'tests/tmul.c')
-rw-r--r-- | tests/tmul.c | 80 |
1 files changed, 53 insertions, 27 deletions
diff --git a/tests/tmul.c b/tests/tmul.c index 225cf0e..4064cb5 100644 --- a/tests/tmul.c +++ b/tests/tmul.c @@ -1,6 +1,6 @@ /* tmul -- test file for mpc_mul. -Copyright (C) 2002, 2005, 2008, 2009, 2010, 2011, 2012 INRIA +Copyright (C) 2002, 2005, 2008, 2009, 2010, 2011, 2012, 2013 INRIA This file is part of GNU MPC. @@ -33,32 +33,48 @@ cmpmul (mpc_srcptr x, mpc_srcptr y, mpc_rnd_t rnd) /* all have the same precision, and we use this precision also for the */ /* result. */ { - mpc_t z, t; - int inex_z, inex_t; + mpc_t z, t; + int inexact_z, inexact_t; - mpc_init2 (z, MPC_MAX_PREC (x)); - mpc_init2 (t, MPC_MAX_PREC (x)); + mpc_init2 (z, MPC_MAX_PREC (x)); + mpc_init2 (t, MPC_MAX_PREC (x)); - inex_z = mpc_mul_naive (z, x, y, rnd); - inex_t = mpc_mul_karatsuba (t, x, y, rnd); + inexact_z = mpc_mul_naive (z, x, y, rnd); + inexact_t = mpc_mul_karatsuba (t, x, y, rnd); - if (mpc_cmp (z, t) != 0 || inex_z != inex_t) { - fprintf (stderr, "mul_naive and mul_karatsuba differ for rnd=(%s,%s)\n", + if (mpc_cmp (z, t)) + { + fprintf (stderr, "mul and mul2 differ for rnd=(%s,%s)\nx=", + mpfr_print_rnd_mode(MPC_RND_RE(rnd)), + mpfr_print_rnd_mode(MPC_RND_IM(rnd))); + mpc_out_str (stderr, 2, 0, x, MPC_RNDNN); + fprintf (stderr, "\ny="); + mpc_out_str (stderr, 2, 0, y, MPC_RNDNN); + fprintf (stderr, "\nmpc_mul_naive gives "); + mpc_out_str (stderr, 2, 0, z, MPC_RNDNN); + fprintf (stderr, "\nmpc_mul_karatsuba gives "); + mpc_out_str (stderr, 2, 0, t, MPC_RNDNN); + fprintf (stderr, "\n"); + exit (1); + } + if (inexact_z != inexact_t) + { + fprintf (stderr, "The return values of mul and mul2 differ for rnd=(%s,%s) \nx=", mpfr_print_rnd_mode(MPC_RND_RE(rnd)), mpfr_print_rnd_mode(MPC_RND_IM(rnd))); - MPC_OUT (x); - MPC_OUT (y); - MPC_OUT (z); - MPC_OUT (t); - if (inex_z != inex_t) { - fprintf (stderr, "inex_re (z): %s\n", MPC_INEX_STR (inex_z)); - fprintf (stderr, "inex_re (t): %s\n", MPC_INEX_STR (inex_t)); - } + mpc_out_str (stderr, 2, 0, x, MPC_RNDNN); + fprintf (stderr, "\nand y="); + mpc_out_str (stderr, 2, 0, y, MPC_RNDNN); + fprintf (stderr, "\nand x*y="); + mpc_out_str (stderr, 2, 0, z, MPC_RNDNN); + fprintf (stderr, "\nmpc_mul_naive gives %i", inexact_z); + fprintf (stderr, "\nmpc_mul_karatsuba gives %i", inexact_t); + fprintf (stderr, "\n"); exit (1); - } + } - mpc_clear (z); - mpc_clear (t); + mpc_clear (z); + mpc_clear (t); } @@ -84,7 +100,7 @@ static void check_regular (void) { mpc_t x, y; - int rnd_re, rnd_im; + mpc_rnd_t rnd_re, rnd_im; mpfr_prec_t prec; testmul (247, -65, -223, 416, 8, 24); @@ -123,7 +139,7 @@ check_regular (void) for (rnd_re = 0; rnd_re < 4; rnd_re ++) for (rnd_im = 0; rnd_im < 4; rnd_im ++) - cmpmul (x, y, MPC_RND (rnd_re, rnd_im)); + cmpmul (x, y, MPC_RND(rnd_re, rnd_im)); } mpc_clear (x); @@ -178,13 +194,21 @@ timemul (void) } #endif +#define MPC_FUNCTION_CALL \ + P[0].mpc_inex = mpc_mul (P[1].mpc, P[2].mpc, P[3].mpc, P[4].mpc_rnd) +#define MPC_FUNCTION_CALL_SYMMETRIC \ + P[0].mpc_inex = mpc_mul (P[1].mpc, P[3].mpc, P[2].mpc, P[4].mpc_rnd) +#define MPC_FUNCTION_CALL_REUSE_OP1 \ + P[0].mpc_inex = mpc_mul (P[1].mpc, P[1].mpc, P[3].mpc, P[4].mpc_rnd) +#define MPC_FUNCTION_CALL_REUSE_OP2 \ + P[0].mpc_inex = mpc_mul (P[1].mpc, P[2].mpc, P[1].mpc, P[4].mpc_rnd) + +#include "data_check.tpl" +#include "tgeneric.tpl" int main (void) { - DECL_FUNC (C_CC, f, mpc_mul); - f.properties = FUNC_PROP_SYMETRIC; - test_start (); #ifdef TIMING @@ -193,9 +217,11 @@ main (void) check_regular (); - data_check (f, "mul.dat"); - tgeneric (f, 2, 4096, 41, 100); + data_check_template ("mul.dsc", "mul.dat"); + + tgeneric_template ("mul.dsc", 2, 4096, 41, 1024); test_end (); + return 0; } |