1 /* Test file for mpfr_sinh_cosh. 2 3 Copyright 2007-2018 Free Software Foundation, Inc. 4 Contributed by the AriC and Caramba 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 "mpfr-test.h" 24 25 static void 26 failed (mpfr_t x, mpfr_t esh, mpfr_t gsh, mpfr_t ech, mpfr_t gch) 27 { 28 printf ("error : mpfr_sinh_cosh (x) x = "); 29 mpfr_out_str (stdout, 10, 0, x, MPFR_RNDD); 30 printf ("\nsinh(x) expected "); 31 mpfr_out_str (stdout, 10, 0, esh, MPFR_RNDD); 32 printf ("\n got "); 33 mpfr_out_str (stdout, 10, 0, gsh, MPFR_RNDD); 34 printf ("\ncosh(x) expected "); 35 mpfr_out_str (stdout, 10, 0, ech, MPFR_RNDD); 36 printf ("\n got "); 37 mpfr_out_str (stdout, 10, 0, gch, MPFR_RNDD); 38 putchar ('\n'); 39 40 mpfr_clears (x, esh, gsh, ech, gch, (mpfr_ptr) 0); 41 exit (1); 42 } 43 44 /* check against sinh, cosh */ 45 static void 46 check (mpfr_t x, mpfr_rnd_t rnd) 47 { 48 mpfr_t s, c, sx, cx; 49 int isc, is, ic; 50 51 mpfr_inits2 (MPFR_PREC(x), s, c, sx, cx, (mpfr_ptr) 0); 52 53 isc = mpfr_sinh_cosh (sx, cx, x, rnd); 54 is = mpfr_sinh (s, x, rnd); 55 ic = mpfr_cosh (c, x, rnd); 56 57 if (!mpfr_equal_p (s, sx) || !mpfr_equal_p (c, cx)) 58 failed (x, s, sx, c, cx); 59 MPFR_ASSERTN (isc = is || ic); 60 61 mpfr_clears (s, c, sx, cx, (mpfr_ptr) 0); 62 } 63 64 static void 65 check_nans (void) 66 { 67 mpfr_t x, sh, ch; 68 69 mpfr_init2 (x, 123); 70 mpfr_init2 (sh, 123); 71 mpfr_init2 (ch, 123); 72 73 /* nan */ 74 mpfr_set_nan (x); 75 mpfr_sinh_cosh (sh, ch, x, MPFR_RNDN); 76 MPFR_ASSERTN (mpfr_nan_p (sh)); 77 MPFR_ASSERTN (mpfr_nan_p (ch)); 78 79 /* +inf */ 80 mpfr_set_inf (x, 1); 81 mpfr_sinh_cosh (sh, ch, x, MPFR_RNDN); 82 MPFR_ASSERTN (mpfr_inf_p (sh)); 83 MPFR_ASSERTN (mpfr_sgn (sh) > 0); 84 MPFR_ASSERTN (mpfr_inf_p (ch)); 85 MPFR_ASSERTN (mpfr_sgn (ch) > 0); 86 87 /* -inf */ 88 mpfr_set_inf (x, -1); 89 mpfr_sinh_cosh (sh, ch, x, MPFR_RNDN); 90 MPFR_ASSERTN (mpfr_inf_p (sh)); 91 MPFR_ASSERTN (mpfr_sgn (sh) < 0); 92 MPFR_ASSERTN (mpfr_inf_p (ch)); 93 MPFR_ASSERTN (mpfr_sgn (ch) > 0); 94 95 mpfr_clear (x); 96 mpfr_clear (sh); 97 mpfr_clear (ch); 98 } 99 100 int 101 main (int argc, char *argv[]) 102 { 103 int i; 104 mpfr_t x; 105 106 tests_start_mpfr (); 107 108 check_nans (); 109 110 /* check against values given by sinh(x), cosh(x) */ 111 mpfr_init2 (x, 53); 112 mpfr_set_str (x, "FEDCBA987654321p-48", 16, MPFR_RNDN); 113 for (i = 0; i < 10; ++i) 114 { 115 /* x = i - x / 2 : boggle sign and bits */ 116 mpfr_ui_sub (x, i, x, MPFR_RNDD); 117 mpfr_div_2ui (x, x, 2, MPFR_RNDD); 118 119 check (x, MPFR_RNDN); 120 check (x, MPFR_RNDU); 121 check (x, MPFR_RNDD); 122 } 123 mpfr_clear (x); 124 125 tests_end_mpfr (); 126 return 0; 127 } 128