1 /* tdot -- test file for mpc_dot. 2 3 Copyright (C) 2018, 2020 INRIA 4 5 This file is part of GNU MPC. 6 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. 11 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 15 more details. 16 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/ . 19 */ 20 21 #include "mpc-tests.h" 22 23 static void 24 check_special (void) 25 { 26 mpc_t z[3], res; 27 mpc_ptr t[3]; 28 int i, inex; 29 30 /* z[0] = (1,2), z[1] = (2,3), z[2] = (3,4) */ 31 for (i = 0; i < 3; i++) 32 { 33 mpc_init2 (z[i], 17); 34 mpc_set_ui_ui (z[i], i+1, i+2, MPC_RNDNN); 35 t[i] = z[i]; 36 } 37 mpc_init2 (res, 17); 38 /* dot product of empty vectors is 0 */ 39 inex = mpc_dot (res, t, t, 0, MPC_RNDNN); 40 MPC_ASSERT (inex == 0); 41 MPC_ASSERT (mpfr_zero_p (mpc_realref (res))); 42 MPC_ASSERT (mpfr_zero_p (mpc_imagref (res))); 43 MPC_ASSERT (mpfr_signbit (mpc_realref (res)) == 0); 44 MPC_ASSERT (mpfr_signbit (mpc_imagref (res)) == 0); 45 /* (1,2)*(1,2) = (-3,4) */ 46 inex = mpc_dot (res, t, t, 1, MPC_RNDNN); 47 MPC_ASSERT (inex == 0); 48 MPC_ASSERT (mpfr_regular_p (mpc_realref (res))); 49 MPC_ASSERT (mpfr_regular_p (mpc_imagref (res))); 50 MPC_ASSERT (mpfr_cmp_si (mpc_realref (res), -3) == 0); 51 MPC_ASSERT (mpfr_cmp_ui (mpc_imagref (res), 4) == 0); 52 /* (1,2)*(1,2) + (2,3)*(2,3) = (-8,16) */ 53 inex = mpc_dot (res, t, t, 2, MPC_RNDNN); 54 MPC_ASSERT (inex == 0); 55 MPC_ASSERT (mpfr_regular_p (mpc_realref (res))); 56 MPC_ASSERT (mpfr_regular_p (mpc_imagref (res))); 57 MPC_ASSERT (mpfr_cmp_si (mpc_realref (res), -8) == 0); 58 MPC_ASSERT (mpfr_cmp_ui (mpc_imagref (res), 16) == 0); 59 /* (1,2)*(1,2) + (2,3)*(2,3) + (3,4)*(3,4) = (-15,40) */ 60 inex = mpc_dot (res, t, t, 3, MPC_RNDNN); 61 MPC_ASSERT (inex == 0); 62 MPC_ASSERT (mpfr_regular_p (mpc_realref (res))); 63 MPC_ASSERT (mpfr_regular_p (mpc_imagref (res))); 64 MPC_ASSERT (mpfr_cmp_si (mpc_realref (res), -15) == 0); 65 MPC_ASSERT (mpfr_cmp_ui (mpc_imagref (res), 40) == 0); 66 for (i = 0; i < 3; i++) 67 mpc_clear (z[i]); 68 mpc_clear (res); 69 } 70 71 /* bug reported by Trevor Spiteri */ 72 static void 73 bug20200717 (void) 74 { 75 mpc_t a; 76 mpc_ptr p[1]; 77 mpc_init2 (a, 53); 78 mpc_set_ui_ui (a, 1, 2, MPC_RNDNN); 79 p[0] = a; 80 mpc_dot (a, p, p, 1, MPC_RNDNN); 81 MPC_ASSERT (mpfr_cmp_si (mpc_realref (a), -3) == 0); 82 MPC_ASSERT (mpfr_cmp_ui (mpc_imagref (a), 4) == 0); 83 mpc_clear (a); 84 } 85 86 int 87 main (void) 88 { 89 test_start (); 90 91 bug20200717 (); 92 check_special (); 93 94 test_end (); 95 96 return 0; 97 } 98 99