summaryrefslogtreecommitdiff
path: root/tests/tmul.c
diff options
context:
space:
mode:
authorthevenyp <thevenyp@211d60ee-9f03-0410-a15a-8952a2c7a4e4>2008-09-23 13:18:26 +0000
committerthevenyp <thevenyp@211d60ee-9f03-0410-a15a-8952a2c7a4e4>2008-09-23 13:18:26 +0000
commit86b3bc4ee78196ca7bf665c403d19f43e189f710 (patch)
tree5d1c64c2df6f11636e2d5f5b8810b9b9c1600c03 /tests/tmul.c
parentce01a7d314fbfb601571ce357ca19f74c99c9fbe (diff)
downloadmpc-86b3bc4ee78196ca7bf665c403d19f43e189f710.tar.gz
tests/tgeneric_ccc.c: random tests for complex functions of two complex variable and tests for parameter reuse.
tests/Makefile.am: add tgeneric_ccc.c to EXTRA_DIST tests/tdiv.c tests/tadd.c tests/tsub.c tests/tmul.c: use tgeneric_ccc.c git-svn-id: svn://scm.gforge.inria.fr/svn/mpc/trunk@188 211d60ee-9f03-0410-a15a-8952a2c7a4e4
Diffstat (limited to 'tests/tmul.c')
-rw-r--r--tests/tmul.c225
1 files changed, 56 insertions, 169 deletions
diff --git a/tests/tmul.c b/tests/tmul.c
index a2aac2a..9cd44b9 100644
--- a/tests/tmul.c
+++ b/tests/tmul.c
@@ -29,16 +29,12 @@ MA 02111-1307, USA. */
#include "mpc.h"
#include "mpc-impl.h"
-void cmpmul (mpc_srcptr, mpc_srcptr, mpc_rnd_t);
-void cmpmului (mpc_srcptr, unsigned long int, mpc_rnd_t);
-void cmpmulsi (mpc_srcptr, long int, mpc_rnd_t);
-void testmul (long, long, long, long, mp_prec_t, mpc_rnd_t);
-void special (void);
-#ifdef TIMING
-void timemul (void);
-#endif
+#include "random.c"
+#define TEST_FUNCTION mpc_mul
+#include "tgeneric_ccc.c"
-void cmpmul (mpc_srcptr x, mpc_srcptr y, mpc_rnd_t rnd)
+static void
+cmpmul (mpc_srcptr x, mpc_srcptr y, mpc_rnd_t rnd)
/* computes the product of x and y with the naive and Karatsuba methods */
/* using the rounding mode rnd and compares the results and return */
/* values. */
@@ -189,137 +185,70 @@ void cmpmul (mpc_srcptr x, mpc_srcptr y, mpc_rnd_t rnd)
}
-void cmpmului (mpc_srcptr x, unsigned long int y, mpc_rnd_t rnd)
- /* computes the product of x and y using mpc_mul_fr and mpc_mul_ui */
- /* using the rounding mode rnd and compares the results and return */
- /* values. */
- /* In our current test suite, the real and imaginary parts of x have */
- /* the same precision, and we use this precision also for the result. */
-
+static void
+testmul (long a, long b, long c, long d, mp_prec_t prec, mpc_rnd_t rnd)
{
- mpc_t z, t;
- mpfr_t yf;
- int inexact_z, inexact_t;
+ mpc_t x, y;
- mpc_init2 (z, MPC_MAX_PREC (x));
- mpc_init2 (t, MPC_MAX_PREC (x));
- mpfr_init2 (yf, 8 * sizeof (long int));
- mpfr_set_ui (yf, y, GMP_RNDN);
+ mpc_init2 (x, prec);
+ mpc_init2 (y, prec);
- inexact_z = mpc_mul_fr (z, x, yf, rnd);
- inexact_t = mpc_mul_ui (t, x, y, rnd);
+ mpc_set_si_si (x, a, b, rnd);
+ mpc_set_si_si (y, c, d, rnd);
- if (mpc_cmp (z, t))
- {
- fprintf (stderr, "mul_fr and mul_ui 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, "\nand y=%li", y);
- fprintf (stderr, "\nmpc_mul_fr gives ");
- mpc_out_str (stderr, 2, 0, z, MPC_RNDNN);
- fprintf (stderr, "\nmpc_mul_ui 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_fr and mul_ui differ for ");
- fprintf (stderr, "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, "\nand y=%li", y);
- fprintf (stderr, "\nand x*y=");
- mpc_out_str (stderr, 2, 0, z, MPC_RNDNN);
- fprintf (stderr, "\nmpc_mul_fr gives %i", inexact_z);
- fprintf (stderr, "\nmpc_mul_ui gives %i", inexact_t);
- fprintf (stderr, "\n");
- exit (1);
- }
+ cmpmul (x, y, rnd);
- mpc_clear (z);
- mpc_clear (t);
- mpfr_clear (yf);
+ mpc_clear (x);
+ mpc_clear (y);
}
-void cmpmulsi (mpc_srcptr x, long int y, mpc_rnd_t rnd)
- /* computes the product of x and y using mpc_mul_fr and mpc_mul_si */
- /* using the rounding mode rnd and compares the results and return */
- /* values. */
- /* In our current test suite, the real and imaginary parts of x have */
- /* the same precision, and we use this precision also for the result. */
+static void
+check_regular (void)
{
- mpc_t z, t;
- mpfr_t yf;
- int inexact_z, inexact_t;
+ mpc_t x, y;
+ mpc_rnd_t rnd_re, rnd_im;
+ mp_prec_t prec;
+ int i;
- mpc_init2 (z, MPC_MAX_PREC (x));
- mpc_init2 (t, MPC_MAX_PREC (x));
- mpfr_init2 (yf, 8 * sizeof (long int));
- mpfr_set_si (yf, y, GMP_RNDN);
+ testmul (247, -65, -223, 416, 8, 24);
+ testmul (5, -896, 5, -32, 3, 2);
+ testmul (-3, -512, -1, -1, 2, 16);
+ testmul (266013312, 121990769, 110585572, 116491059, 27, 0);
+ testmul (170, 9, 450, 251, 8, 0);
+ testmul (768, 85, 169, 440, 8, 16);
+ testmul (145, 1816, 848, 169, 8, 24);
+ testmul (0, 1816, 848, 169, 8, 24);
+ testmul (145, 0, 848, 169, 8, 24);
+ testmul (145, 1816, 0, 169, 8, 24);
+ testmul (145, 1816, 848, 0, 8, 24);
- inexact_z = mpc_mul_fr (z, x, yf, rnd);
- inexact_t = mpc_mul_si (t, x, y, rnd);
+ mpc_init (x);
+ mpc_init (y);
- if (mpc_cmp (z, t))
+ for (prec = 2; prec < 1000; prec++)
{
- fprintf (stderr, "mul_fr and mul_si 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, "\nand y=%li", y);
- fprintf (stderr, "\nmpc_mul_fr gives ");
- mpc_out_str (stderr, 2, 0, z, MPC_RNDNN);
- fprintf (stderr, "\nmpc_mul_si 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_fr and mul_si differ for ");
- fprintf (stderr, "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, "\nand y=%li", y);
- fprintf (stderr, "\nand x*y=");
- mpc_out_str (stderr, 2, 0, z, MPC_RNDNN);
- fprintf (stderr, "\nmpc_mul_fr gives %i", inexact_z);
- fprintf (stderr, "\nmpc_mul_si gives %i", inexact_t);
- fprintf (stderr, "\n");
- exit (1);
- }
+ mpc_set_prec (x, prec);
+ mpc_set_prec (y, prec);
- mpc_clear (z);
- mpc_clear (t);
- mpfr_clear (yf);
-}
-
-
-void
-testmul (long a, long b, long c, long d, mp_prec_t prec, mpc_rnd_t rnd)
-{
- mpc_t x, y;
-
- mpc_init2 (x, prec);
- mpc_init2 (y, prec);
-
- mpc_set_si_si (x, a, b, rnd);
- mpc_set_si_si (y, c, d, rnd);
+ for (i = 0; i < (int) (1000/prec); i++)
+ {
+ test_default_random (x, -1, 1, 1);
+ test_default_random (y, -1, 1, 1);
- cmpmul (x, y, rnd);
+ for (rnd_re = 0; rnd_re < 4; rnd_re ++)
+ for (rnd_im = 0; rnd_im < 4; rnd_im ++)
+ cmpmul (x, y, RNDC(rnd_re, rnd_im));
+ }
+ }
mpc_clear (x);
mpc_clear (y);
}
-void
-special (void)
+static void
+check_special (void)
{
mpc_t x, y, z, t;
int inexact;
@@ -354,7 +283,7 @@ special (void)
}
#ifdef TIMING
-void
+static void
timemul (void)
{
/* measures the time needed with different precisions for naive and */
@@ -375,8 +304,8 @@ timemul (void)
mpc_set_prec (x, i * BITS_PER_MP_LIMB);
mpc_set_prec (y, i * BITS_PER_MP_LIMB);
mpc_set_prec (z, i * BITS_PER_MP_LIMB);
- mpc_random (x);
- mpc_random (y);
+ test_default_random (x, -1, 1, 1);
+ test_default_random (y, -1, 1, 1);
times (&time_old);
for (j = 0; j < tests; j++)
@@ -403,58 +332,16 @@ timemul (void)
int
main (void)
{
- mpc_t x, y;
- mpc_rnd_t rnd_re, rnd_im;
- mp_prec_t prec;
- int i;
- long int ysi;
+ test_start ();
#ifdef TIMING
timemul ();
#endif
- special ();
-
- testmul (247, -65, -223, 416, 8, 24);
- testmul (5, -896, 5, -32, 3, 2);
- testmul (-3, -512, -1, -1, 2, 16);
- testmul (266013312, 121990769, 110585572, 116491059, 27, 0);
- testmul (170, 9, 450, 251, 8, 0);
- testmul (768, 85, 169, 440, 8, 16);
- testmul (145, 1816, 848, 169, 8, 24);
- testmul (0, 1816, 848, 169, 8, 24);
- testmul (145, 0, 848, 169, 8, 24);
- testmul (145, 1816, 0, 169, 8, 24);
- testmul (145, 1816, 848, 0, 8, 24);
-
- mpc_init (x);
- mpc_init (y);
-
- for (prec = 2; prec < 1000; prec++) {
-
- mpc_set_prec (x, prec);
- mpc_set_prec (y, prec);
-
- for (i = 0; i < (int) (1000/prec); i++)
- {
-
- mpc_random (x);
- mpc_random (y);
- ysi = rand ();
-
- for (rnd_re = 0; rnd_re < 4; rnd_re ++)
- for (rnd_im = 0; rnd_im < 4; rnd_im ++)
- {
- cmpmul (x, y, RNDC(rnd_re, rnd_im));
- cmpmului (x, (unsigned long int) ysi, RNDC(rnd_re, rnd_im));
- cmpmulsi (x, ysi, RNDC(rnd_re, rnd_im));
- cmpmulsi (x, -ysi, RNDC(rnd_re, rnd_im));
- }
- }
- }
-
- mpc_clear (x);
- mpc_clear (y);
+ check_special ();
+ check_regular ();
+ tgeneric (2, 1024, 1, 4096);
+ test_end ();
return 0;
}