1/* test file for mpc_cosh. 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 <stdlib.h> 22#include "mpc-tests.h" 23 24static void 25pure_real_argument (void) 26{ 27 /* cosh(x -i*0) = cosh(x) +i*0 if x<0 */ 28 /* cosh(x -i*0) = cosh(x) -i*0 if x>0 */ 29 /* cosh(x +i*0) = cosh(x) -i*0 if x<0 */ 30 /* cosh(x -i*0) = cosh(x) +i*0 if x>0 */ 31 mpc_t u; 32 mpc_t z; 33 mpc_t cosh_z; 34 35 mpc_init2 (z, 2); 36 mpc_init2 (u, 100); 37 mpc_init2 (cosh_z, 100); 38 39 /* cosh(1 +i*0) = cosh(1) +i*0 */ 40 mpc_set_ui_ui (z, 1, 0, MPC_RNDNN); 41 mpfr_cosh (mpc_realref (u), mpc_realref (z), GMP_RNDN); 42 mpfr_set_ui (mpc_imagref (u), 0, GMP_RNDN); 43 mpc_cosh (cosh_z, z, MPC_RNDNN); 44 if (mpc_cmp (cosh_z, u) != 0 || mpfr_signbit (mpc_imagref (cosh_z))) 45 TEST_FAILED ("mpc_cosh", z, cosh_z, u, MPC_RNDNN); 46 47 /* cosh(1 -i*0) = cosh(1) -i*0 */ 48 mpc_conj (z, z, MPC_RNDNN); 49 mpc_conj (u, u, MPC_RNDNN); 50 mpc_cosh (cosh_z, z, MPC_RNDNN); 51 if (mpc_cmp (cosh_z, u) != 0 || !mpfr_signbit (mpc_imagref (cosh_z))) 52 TEST_FAILED ("mpc_cosh", z, cosh_z, u, MPC_RNDNN); 53 54 /* cosh(-1 +i*0) = cosh(1) -i*0 */ 55 mpc_neg (z, z, MPC_RNDNN); 56 mpc_cosh (cosh_z, z, MPC_RNDNN); 57 if (mpc_cmp (cosh_z, u) != 0 || !mpfr_signbit (mpc_imagref (cosh_z))) 58 TEST_FAILED ("mpc_cosh", z, cosh_z, u, MPC_RNDNN); 59 60 /* cosh(-1 -i*0) = cosh(1) +i*0 */ 61 mpc_conj (z, z, MPC_RNDNN); 62 mpc_conj (u, u, MPC_RNDNN); 63 mpc_cosh (cosh_z, z, MPC_RNDNN); 64 if (mpc_cmp (cosh_z, u) != 0 || mpfr_signbit (mpc_imagref (cosh_z))) 65 TEST_FAILED ("mpc_cosh", z, cosh_z, u, MPC_RNDNN); 66 67 mpc_clear (cosh_z); 68 mpc_clear (z); 69 mpc_clear (u); 70} 71 72static void 73pure_imaginary_argument (void) 74{ 75 /* cosh(+0 +i*y) = cos y +i*0*sin y */ 76 /* cosh(-0 +i*y) = cos y -i*0*sin y */ 77 mpc_t u; 78 mpc_t z; 79 mpc_t cosh_z; 80 81 mpc_init2 (z, 2); 82 mpc_init2 (u, 100); 83 mpc_init2 (cosh_z, 100); 84 85 /* cosh(+0 +i) = cos(1) + i*0 */ 86 mpc_set_ui_ui (z, 0, 1, MPC_RNDNN); 87 mpfr_cos (mpc_realref (u), mpc_imagref (z), GMP_RNDN); 88 mpfr_set_ui (mpc_imagref (u), 0, GMP_RNDN); 89 mpc_cosh (cosh_z, z, MPC_RNDNN); 90 if (mpc_cmp (cosh_z, u) != 0 || mpfr_signbit (mpc_imagref (cosh_z))) 91 TEST_FAILED ("mpc_cosh", z, cosh_z, u, MPC_RNDNN); 92 93 /* cosh(+0 -i) = cos(1) - i*0 */ 94 mpc_conj (z, z, MPC_RNDNN); 95 mpc_conj (u, u, MPC_RNDNN); 96 mpc_cosh (cosh_z, z, MPC_RNDNN); 97 if (mpc_cmp (cosh_z, u) != 0 || !mpfr_signbit (mpc_imagref (cosh_z))) 98 TEST_FAILED ("mpc_cosh", z, cosh_z, u, MPC_RNDNN); 99 100 /* cosh(-0 +i) = cos(1) - i*0 */ 101 mpc_neg (z, z, MPC_RNDNN); 102 mpc_cosh (cosh_z, z, MPC_RNDNN); 103 if (mpc_cmp (cosh_z, u) != 0 || !mpfr_signbit (mpc_imagref (cosh_z))) 104 TEST_FAILED ("mpc_cosh", z, cosh_z, u, MPC_RNDNN); 105 106 /* cosh(-0 -i) = cos(1) + i*0 */ 107 mpc_conj (z, z, MPC_RNDNN); 108 mpc_conj (u, u, MPC_RNDNN); 109 mpc_cosh (cosh_z, z, MPC_RNDNN); 110 if (mpc_cmp (cosh_z, u) != 0 || mpfr_signbit (mpc_imagref (cosh_z))) 111 TEST_FAILED ("mpc_cosh", z, cosh_z, u, MPC_RNDNN); 112 113 mpc_clear (cosh_z); 114 mpc_clear (z); 115 mpc_clear (u); 116} 117 118int 119main (void) 120{ 121 DECL_FUNC(CC, f,mpc_cosh); 122 123 test_start (); 124 125 data_check (f, "cosh.dat"); 126 tgeneric (f, 2, 512, 7, 7); 127 128 pure_real_argument (); 129 pure_imaginary_argument (); 130 131 test_end (); 132 133 return 0; 134} 135