From 44751a0256d8aca8ce1f0118c65841d55d2d8e45 Mon Sep 17 00:00:00 2001 From: Paul Zimmermann Date: Wed, 13 Jun 2018 16:39:11 +0200 Subject: added assertions in tests/tdot.c (which fail currently) --- tests/tdot.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/tests/tdot.c b/tests/tdot.c index b5a61d6..cfd54cd 100644 --- a/tests/tdot.c +++ b/tests/tdot.c @@ -38,21 +38,29 @@ check_special (void) /* dot product of empty vectors is 0 */ inex = mpc_dot (res, t, t, 0, MPC_RNDNN); MPC_ASSERT (inex == 0); + MPC_ASSERT (mpfr_regular_p (mpc_realref (res))); + MPC_ASSERT (mpfr_regular_p (mpc_imagref (res))); MPC_ASSERT (mpfr_cmp_ui (mpc_realref (res), 0) == 0); MPC_ASSERT (mpfr_cmp_ui (mpc_imagref (res), 0) == 0); /* (1,2)*(1,2) = (-3,4) */ inex = mpc_dot (res, t, t, 1, MPC_RNDNN); MPC_ASSERT (inex == 0); + MPC_ASSERT (mpfr_regular_p (mpc_realref (res))); + MPC_ASSERT (mpfr_regular_p (mpc_imagref (res))); MPC_ASSERT (mpfr_cmp_si (mpc_realref (res), -3) == 0); MPC_ASSERT (mpfr_cmp_ui (mpc_imagref (res), 4) == 0); /* (1,2)*(1,2) + (2,3)*(2,3) = (-8,16) */ inex = mpc_dot (res, t, t, 2, MPC_RNDNN); MPC_ASSERT (inex == 0); + MPC_ASSERT (mpfr_regular_p (mpc_realref (res))); + MPC_ASSERT (mpfr_regular_p (mpc_imagref (res))); MPC_ASSERT (mpfr_cmp_si (mpc_realref (res), -8) == 0); MPC_ASSERT (mpfr_cmp_ui (mpc_imagref (res), 16) == 0); /* (1,2)*(1,2) + (2,3)*(2,3) + (3,4)*(3,4) = (-15,40) */ inex = mpc_dot (res, t, t, 3, MPC_RNDNN); MPC_ASSERT (inex == 0); + MPC_ASSERT (mpfr_regular_p (mpc_realref (res))); + MPC_ASSERT (mpfr_regular_p (mpc_imagref (res))); MPC_ASSERT (mpfr_cmp_si (mpc_realref (res), -15) == 0); MPC_ASSERT (mpfr_cmp_ui (mpc_imagref (res), 40) == 0); for (i = 0; i < 3; i++) -- cgit v1.2.1 From e9438ddfc68d8952c02d2a1ed53d13a1d8960b3f Mon Sep 17 00:00:00 2001 From: Paul Zimmermann Date: Wed, 13 Jun 2018 18:30:04 +0200 Subject: fixed a bug in mpc_dot (thanks Trevor Spiteri for identifying it) (also fixed a bug in the tests) --- src/dot.c | 2 +- tests/tdot.c | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/dot.c b/src/dot.c index 7c61018..6f655c0 100644 --- a/src/dot.c +++ b/src/dot.c @@ -53,7 +53,7 @@ mpc_dot (mpc_ptr res, const mpc_ptr *x, const mpc_ptr *y, mpfr_mul (z[i], mpc_realref (x[i]), mpc_realref (y[i]), MPFR_RNDZ); /* idem for z[n+i]: we allocate with prec_x_im + prec_y_max bits */ mpfr_init2 (z[n+i], prec_x_im + prec_y_max); - mpfr_set_prec (z[i], prec_x_im + prec_y_im); + mpfr_set_prec (z[n+i], prec_x_im + prec_y_im); mpfr_mul (z[n+i], mpc_imagref (x[i]), mpc_imagref (y[i]), MPFR_RNDZ); mpfr_neg (z[n+i], z[n+i], MPFR_RNDZ); } diff --git a/tests/tdot.c b/tests/tdot.c index cfd54cd..c6d1f39 100644 --- a/tests/tdot.c +++ b/tests/tdot.c @@ -38,10 +38,10 @@ check_special (void) /* dot product of empty vectors is 0 */ inex = mpc_dot (res, t, t, 0, MPC_RNDNN); MPC_ASSERT (inex == 0); - MPC_ASSERT (mpfr_regular_p (mpc_realref (res))); - MPC_ASSERT (mpfr_regular_p (mpc_imagref (res))); - MPC_ASSERT (mpfr_cmp_ui (mpc_realref (res), 0) == 0); - MPC_ASSERT (mpfr_cmp_ui (mpc_imagref (res), 0) == 0); + MPC_ASSERT (mpfr_zero_p (mpc_realref (res))); + MPC_ASSERT (mpfr_zero_p (mpc_imagref (res))); + MPC_ASSERT (mpfr_signbit (mpc_realref (res)) == 0); + MPC_ASSERT (mpfr_signbit (mpc_imagref (res)) == 0); /* (1,2)*(1,2) = (-3,4) */ inex = mpc_dot (res, t, t, 1, MPC_RNDNN); MPC_ASSERT (inex == 0); -- cgit v1.2.1