1/* tmul_i -- test file for mpc_mul_i. 2 3Copyright (C) 2008, 2009, 2010, 2011 INRIA 4 5This file is part of GNU MPC. 6 7GNU MPC is free software; you can redistribute it and/or modify it under 8the terms of the GNU Lesser General Public License as published by the 9Free Software Foundation; either version 3 of the License, or (at your 10option) any later version. 11 12GNU MPC is distributed in the hope that it will be useful, but WITHOUT ANY 13WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 14FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for 15more details. 16 17You should have received a copy of the GNU Lesser General Public License 18along with this program. If not, see http://www.gnu.org/licenses/ . 19*/ 20 21#include "mpc-tests.h" 22 23static void 24check_different_precisions(void) 25{ 26 /* check reuse when real and imaginary part have different precisions. */ 27 mpc_t z, expected, got; 28 int res; 29 30 mpc_init2(z, 128); 31 mpc_init2(expected, 128); 32 mpc_init2(got, 128); 33 34 /* change precision of one part */ 35 mpfr_set_prec (mpc_imagref (z), 32); 36 mpfr_set_prec (mpc_imagref (expected), 32); 37 mpfr_set_prec (mpc_imagref (got), 32); 38 39 mpfr_set_str (mpc_realref (z), "0x100000000fp-32", 16, GMP_RNDN); 40 mpfr_set_str (mpc_imagref (z), "-1", 2, GMP_RNDN); 41 mpfr_set_str (mpc_realref (expected), "+1", 2, GMP_RNDN); 42 mpfr_set_str (mpc_imagref (expected), "0x100000000fp-32", 16, GMP_RNDN); 43 44 mpc_set (got, z, MPC_RNDNN); 45 res = mpc_mul_i (got, got, +1, MPC_RNDNN); 46 if (MPC_INEX_RE(res) != 0 || MPC_INEX_IM(res) >=0) 47 { 48 printf("Wrong inexact flag for mpc_mul_i(z, z, n)\n" 49 " got (re=%2d, im=%2d)\nexpected (re= 0, im=-1)\n", 50 MPC_INEX_RE(res), MPC_INEX_IM(res)); 51 exit(1); 52 } 53 if (mpc_cmp(got, expected) != 0) 54 { 55 printf ("Error for mpc_mul_i(z, z, n) for\n"); 56 MPC_OUT (z); 57 printf ("n=+1\n"); 58 MPC_OUT (expected); 59 MPC_OUT (got); 60 61 exit (1); 62 } 63 64 mpc_neg (expected, expected, MPC_RNDNN); 65 mpc_set (got, z, MPC_RNDNN); 66 mpc_mul_i (got, got, -1, MPC_RNDNN); 67 if (mpc_cmp(got, expected) != 0) 68 { 69 printf ("Error for mpc_mul_i(z, z, n) for\n"); 70 MPC_OUT (z); 71 printf ("n=-1\n"); 72 MPC_OUT (expected); 73 MPC_OUT (got); 74 75 exit (1); 76 } 77 78 mpc_clear (z); 79 mpc_clear (expected); 80 mpc_clear (got); 81} 82 83int 84main (void) 85{ 86 DECL_FUNC (CCI, f, mpc_mul_i); 87 88 test_start (); 89 90 check_different_precisions (); 91 tgeneric (f, 2, 1024, 7, -1); 92 93 test_end (); 94 95 return 0; 96} 97