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