1/* Test file for hyperbolic function : mpfr_cosh, mpfr_sinh, mpfr_tanh, mpfr_acosh, mpfr_asinh, mpfr_atanh. 2 3Copyright 2001, 2002, 2003, 2004, 2006, 2007, 2008, 2009, 2010, 2011 Free Software Foundation, Inc. 4Contributed by the Arenaire and Cacao projects, INRIA. 5 6This file is part of the GNU MPFR Library. 7 8The GNU MPFR Library is free software; you can redistribute it and/or modify 9it under the terms of the GNU Lesser General Public License as published 10by 11the Free Software Foundation; either version 3 of the License, or (at youroption) any later version. 12 13The GNU MPFR Library is distributed in the hope that it will be useful, but 14WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITYor FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public 15License for more details. 16 17You should have received a copy of the GNU Lesser General Public License 18along with the GNU MPFR Library; see the file COPYING.LESSER. If not, see 19http://www.gnu.org/licenses/ or write to the Free Software Foundation, Inc., 2051 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. */ 21 22#include <stdlib.h> 23#include <stdio.h> 24 25#include "mpfr-test.h" 26 27static int 28check_NAN (void) 29{ 30 mpfr_t t, ch,sh,th,ach,ash,ath; 31 int tester; 32 int fail = 0; 33 34 mpfr_init2(t,200); 35 mpfr_init2(ch,200); 36 mpfr_init2(sh,200); 37 mpfr_init2(th,200); 38 mpfr_init2(ach,200); 39 mpfr_init2(ash,200); 40 mpfr_init2(ath,200); 41 42 MPFR_SET_NAN(t); 43 44 /******cosh********/ 45 46 tester=mpfr_cosh(ch,t,MPFR_RNDD); 47 if (!MPFR_IS_NAN(ch) || tester!=0) 48 { 49 printf("cosh NAN \n"); 50 fail = 1; 51 goto clean_up; 52 } 53 54 /******sinh********/ 55 56 tester=mpfr_sinh(sh,t,MPFR_RNDD); 57 if (!MPFR_IS_NAN(sh) || tester!=0) 58 { 59 printf("sinh NAN \n"); 60 fail = 1; 61 goto clean_up; 62 } 63 64 /******tanh********/ 65 66 tester=mpfr_tanh(th,t,MPFR_RNDD); 67 if (!MPFR_IS_NAN(th) || tester!=0) 68 { 69 printf("tanh NAN \n"); 70 fail = 1; 71 goto clean_up; 72 } 73 74 /******acosh********/ 75 76 tester=mpfr_acosh(ach,t,MPFR_RNDD); 77 if (!MPFR_IS_NAN(ach) || tester!=0) 78 { 79 printf("acosh NAN \n"); 80 fail = 1; 81 goto clean_up; 82 } 83 84 /******asinh********/ 85 86 tester=mpfr_asinh(ash,t,MPFR_RNDD); 87 if (!MPFR_IS_NAN(ash) || tester!=0) 88 { 89 printf("asinh NAN \n"); 90 fail = 1; 91 goto clean_up; 92 } 93 94 /******atanh********/ 95 96 tester=mpfr_atanh(ath,t,MPFR_RNDD); 97 if (!MPFR_IS_NAN(ath) || tester!=0) 98 { 99 printf("atanh NAN \n"); 100 fail = 1; 101 goto clean_up; 102 } 103 104 clean_up: 105 mpfr_clear(t); 106 mpfr_clear(ch); 107 mpfr_clear(sh); 108 mpfr_clear(th); 109 mpfr_clear(ach); 110 mpfr_clear(ash); 111 mpfr_clear(ath); 112 113 return fail; 114} 115 116static int 117check_zero (void) 118{ 119 mpfr_t t, ch,sh,th,ach,ash,ath; 120 int tester; 121 int fail = 0; 122 123 mpfr_init2(t,200); 124 mpfr_init2(ch,200); 125 mpfr_init2(sh,200); 126 mpfr_init2(th,200); 127 mpfr_init2(ach,200); 128 mpfr_init2(ash,200); 129 mpfr_init2(ath,200); 130 131 mpfr_set_ui(t,0,MPFR_RNDD); 132 133 /******cosh********/ 134 135 tester = mpfr_cosh (ch, t, MPFR_RNDD); 136 if (mpfr_cmp_ui(ch, 1) || tester) 137 { 138 printf("cosh(0) \n"); 139 fail = 1; 140 goto clean_up; 141 } 142 143 /******sinh********/ 144 145 tester = mpfr_sinh (sh, t, MPFR_RNDD); 146 if (!MPFR_IS_ZERO(sh) || tester) 147 { 148 printf("sinh(0) \n"); 149 fail = 1; 150 goto clean_up; 151 } 152 153 /******tanh********/ 154 155 tester = mpfr_tanh (th, t, MPFR_RNDD); 156 if (!MPFR_IS_ZERO(th) || tester) 157 { 158 printf("tanh(0) \n"); 159 fail = 1; 160 goto clean_up; 161 } 162 163 /******acosh********/ 164 165 tester=mpfr_acosh(ach,t,MPFR_RNDD); 166 if (!MPFR_IS_NAN(ach) || tester) 167 { 168 printf("acosh(0) \n"); 169 fail = 1; 170 goto clean_up; 171 } 172 173 /******asinh********/ 174 175 tester=mpfr_asinh(ash,t,MPFR_RNDD); 176 if (!MPFR_IS_ZERO(ash) || tester) 177 { 178 printf("asinh(0) \n"); 179 fail = 1; 180 goto clean_up; 181 } 182 183 /******atanh********/ 184 185 tester=mpfr_atanh(ath,t,MPFR_RNDD); 186 if (!MPFR_IS_ZERO(ath) || tester) 187 { 188 printf("atanh(0) \n"); 189 fail = 1; 190 goto clean_up; 191 } 192 193 clean_up: 194 mpfr_clear(t); 195 mpfr_clear(ch); 196 mpfr_clear(sh); 197 mpfr_clear(th); 198 mpfr_clear(ach); 199 mpfr_clear(ash); 200 mpfr_clear(ath); 201 202 return fail; 203} 204 205static int 206check_INF (void) 207{ 208 mpfr_t t, ch, sh, th, ach, ash, ath; 209 int tester; 210 int fail = 0; 211 212 mpfr_init2 (t, 200); 213 mpfr_init2 (ch, 200); 214 mpfr_init2 (sh, 200); 215 mpfr_init2 (th, 200); 216 mpfr_init2 (ach, 200); 217 mpfr_init2 (ash, 200); 218 mpfr_init2 (ath, 200); 219 220 MPFR_SET_INF(t); 221 222 if(MPFR_SIGN(t)<0) 223 MPFR_CHANGE_SIGN(t); 224 225 /******cosh********/ 226 227 tester = mpfr_cosh(ch,t,MPFR_RNDD); 228 if (!MPFR_IS_INF(ch) || MPFR_SIGN(ch) < 0 || tester!=0) 229 { 230 printf("cosh(INF) \n"); 231 fail = 1; 232 goto clean_up; 233 } 234 235 /******sinh********/ 236 237 tester=mpfr_sinh(sh,t,MPFR_RNDD); 238 if (!MPFR_IS_INF(sh) || MPFR_SIGN(sh) < 0 || tester!=0) 239 { 240 printf("sinh(INF) \n"); 241 fail = 1; 242 goto clean_up; 243 } 244 245 /******tanh********/ 246 247 tester=mpfr_tanh(th,t,MPFR_RNDD); 248 if (mpfr_cmp_ui(th,1) != 0 || tester!=0) 249 { 250 printf("tanh(INF) \n"); 251 fail = 1; 252 goto clean_up; 253 } 254 255 /******acosh********/ 256 257 tester=mpfr_acosh(ach,t,MPFR_RNDD); 258 if (!MPFR_IS_INF(ach) || MPFR_SIGN(ach) < 0 || tester!=0) 259 { 260 printf("acosh(INF) \n"); 261 fail = 1; 262 goto clean_up; 263 } 264 265 /******asinh********/ 266 267 tester=mpfr_asinh(ash,t,MPFR_RNDD); 268 if (!MPFR_IS_INF(ash) || MPFR_SIGN(ash) < 0 || tester!=0) 269 { 270 printf("asinh(INF) \n"); 271 fail = 1; 272 goto clean_up; 273 } 274 275 /******atanh********/ 276 277 tester = mpfr_atanh (ath, t, MPFR_RNDD); 278 if (!MPFR_IS_NAN(ath) || tester != 0) 279 { 280 printf("atanh(INF) \n"); 281 fail = 1; 282 goto clean_up; 283 } 284 285 MPFR_CHANGE_SIGN(t); 286 287 /******cosh********/ 288 289 tester=mpfr_cosh(ch,t,MPFR_RNDD); 290 if (!MPFR_IS_INF(ch) || MPFR_SIGN(ch) < 0 || tester!=0) 291 { 292 printf("cosh(-INF) \n"); 293 fail = 1; 294 goto clean_up; 295 } 296 297 /******sinh********/ 298 299 tester=mpfr_sinh(sh,t,MPFR_RNDD); 300 if (!MPFR_IS_INF(sh) || MPFR_SIGN(sh) > 0 || tester!=0) 301 { 302 printf("sinh(-INF) \n"); 303 fail = 1; 304 goto clean_up; 305 } 306 307 /******tanh********/ 308 309 tester=mpfr_tanh(th,t,MPFR_RNDD); 310 if (!mpfr_cmp_ui(th,-1) || tester!=0) 311 { 312 printf("tanh(-INF) \n"); 313 fail = 1; 314 goto clean_up; 315 } 316 317 /******acosh********/ 318 319 tester=mpfr_acosh(ach,t,MPFR_RNDD); 320 if (!MPFR_IS_NAN(ach) || tester!=0) 321 { 322 printf("acosh(-INF) \n"); 323 fail = 1; 324 goto clean_up; 325 } 326 327 /******asinh********/ 328 329 tester=mpfr_asinh(ash,t,MPFR_RNDD); 330 if (!MPFR_IS_INF(ash) || MPFR_SIGN(ash) > 0 || tester!=0) 331 { 332 printf("asinh(-INF) \n"); 333 fail = 1; 334 goto clean_up; 335 } 336 337 /******atanh********/ 338 339 tester = mpfr_atanh (ath, t, MPFR_RNDD); 340 if (!MPFR_IS_NAN(ath) || tester != 0) 341 { 342 printf("atanh(-INF) \n"); 343 fail = 1; 344 goto clean_up; 345 } 346 347 clean_up: 348 mpfr_clear(t); 349 mpfr_clear(ch); 350 mpfr_clear(sh); 351 mpfr_clear(th); 352 mpfr_clear(ach); 353 mpfr_clear(ash); 354 mpfr_clear(ath); 355 356 return fail; 357} 358 359int 360main(void) 361{ 362 tests_start_mpfr (); 363 364 if (check_zero ()) 365 { 366 printf ("Error in evaluation at 0\n"); 367 exit (1); 368 } 369 370 if (check_INF ()) 371 { 372 printf ("Error in evaluation of INF\n"); 373 exit (1); 374 } 375 376 if (check_NAN ()) 377 { 378 printf ("Error in evaluation of NAN\n"); 379 exit (1); 380 } 381 382 tests_end_mpfr (); 383 return 0; 384} 385