tsinh.c revision 1.1.1.5
1/* Test file for mpfr_sinh. 2 3Copyright 2001-2002, 2004, 2006-2020 Free Software Foundation, Inc. 4Contributed by the AriC and Caramba 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 by 10the Free Software Foundation; either version 3 of the License, or (at your 11option) 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 MERCHANTABILITY 15or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public 16License for more details. 17 18You should have received a copy of the GNU Lesser General Public License 19along with the GNU MPFR Library; see the file COPYING.LESSER. If not, see 20https://www.gnu.org/licenses/ or write to the Free Software Foundation, Inc., 2151 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. */ 22 23#include "mpfr-test.h" 24 25#define TEST_FUNCTION mpfr_sinh 26#define TEST_RANDOM_EMIN -36 27#define TEST_RANDOM_EMAX 36 28#include "tgeneric.c" 29 30static void 31special (void) 32{ 33 mpfr_t x; 34 int i; 35 36 mpfr_init (x); 37 38 mpfr_set_nan (x); 39 mpfr_sinh (x, x, MPFR_RNDN); 40 MPFR_ASSERTN(mpfr_nan_p (x)); 41 42 mpfr_set_inf (x, 1); 43 mpfr_sinh (x, x, MPFR_RNDN); 44 MPFR_ASSERTN(mpfr_inf_p (x) && mpfr_sgn (x) > 0); 45 mpfr_set_inf (x, -1); 46 mpfr_sinh (x, x, MPFR_RNDN); 47 MPFR_ASSERTN(mpfr_inf_p (x) && mpfr_sgn (x) < 0); 48 49 mpfr_set_prec (x, 10); 50 mpfr_set_str_binary (x, "-0.1001011001"); 51 mpfr_sinh (x, x, MPFR_RNDN); 52 MPFR_ASSERTN(mpfr_cmp_si_2exp (x, -159, -8) == 0); 53 54 /* corner case */ 55 mpfr_set_prec (x, 2); 56 mpfr_set_str_binary (x, "1E-6"); 57 mpfr_sinh (x, x, MPFR_RNDN); 58 MPFR_ASSERTN(mpfr_cmp_ui_2exp (x, 1, -6) == 0); 59 60 mpfr_clear_flags (); 61 mpfr_set_str_binary (x, "1E1000000000"); 62 i = mpfr_sinh (x, x, MPFR_RNDN); 63 MPFR_ASSERTN (MPFR_IS_INF (x) && MPFR_IS_POS (x)); 64 MPFR_ASSERTN (mpfr_overflow_p ()); 65 MPFR_ASSERTN (i == 1); 66 67 mpfr_clear_flags (); 68 mpfr_set_str_binary (x, "-1E1000000000"); 69 i = mpfr_sinh (x, x, MPFR_RNDN); 70 MPFR_ASSERTN (MPFR_IS_INF (x) && MPFR_IS_NEG (x)); 71 MPFR_ASSERTN (mpfr_overflow_p () && !mpfr_underflow_p ()); 72 MPFR_ASSERTN (i == -1); 73 74 mpfr_clear_flags (); 75 mpfr_set_str_binary (x, "-1E1000000000"); 76 i = mpfr_sinh (x, x, MPFR_RNDD); 77 MPFR_ASSERTN (MPFR_IS_INF (x) && MPFR_IS_NEG (x)); 78 MPFR_ASSERTN (mpfr_overflow_p () && !mpfr_underflow_p ()); 79 MPFR_ASSERTN (i == -1); 80 81 mpfr_clear_flags (); 82 mpfr_set_str_binary (x, "-1E1000000000"); 83 i = mpfr_sinh (x, x, MPFR_RNDU); 84 MPFR_ASSERTN (!MPFR_IS_INF (x) && MPFR_IS_NEG (x)); 85 MPFR_ASSERTN (mpfr_overflow_p () && !mpfr_underflow_p ()); 86 MPFR_ASSERTN (i == 1); 87 88 mpfr_clear (x); 89} 90 91/* exercise mpfr_sinh near the overflow limit */ 92static void 93coverage (void) 94{ 95#if _MPFR_EXP_FORMAT >= 3 && ULONG_MAX == 0xffffffffffffffff 96 mpfr_t x, y; 97 int inex; 98 mpfr_exp_t emax; 99 100 emax = mpfr_get_emax (); 101 mpfr_init2 (x, 64); 102 mpfr_init2 (y, 64); 103 104 MPFR_ASSERTN(mpfr_get_emax_max () == 4611686018427387903UL); /* 2^62-1 */ 105 mpfr_set_emax (mpfr_get_emax_max ()); 106 107 mpfr_set_ui (x, 3196577161300663915UL, MPFR_RNDN); 108 mpfr_clear_overflow (); 109 /* exp(x) overflows, cosh(x/2)*sinh(x/2) does not overflow, 110 but 2*cosh(x/2)*sinh(x/2) overflows */ 111 inex = mpfr_sinh (y, x, MPFR_RNDZ); 112 MPFR_ASSERTN(mpfr_cmp_ui_2exp (y, 18446744073709551615UL, 4611686018427387839UL) == 0); 113 MPFR_ASSERTN(inex < 0); 114 MPFR_ASSERTN(mpfr_overflow_p ()); 115 116 mpfr_set_prec (x, 65); 117 mpfr_set_str (x, "3196577161300663914.5", 10, MPFR_RNDN); 118 mpfr_clear_overflow (); 119 /* exp(x) overflows, cosh(x/2)*sinh(x/2) does not overflow, 120 and 2*cosh(x/2)*sinh(x/2) does not overflow */ 121 inex = mpfr_sinh (y, x, MPFR_RNDN); 122 MPFR_ASSERTN(mpfr_cmp_ui_2exp (y, 11795642775994293059UL, 4611686018427387839UL) == 0); 123 MPFR_ASSERTN(inex > 0); 124 MPFR_ASSERTN(!mpfr_overflow_p ()); 125 126 mpfr_clear (x); 127 mpfr_clear (y); 128 mpfr_set_emax (emax); 129#endif 130} 131 132int 133main (int argc, char *argv[]) 134{ 135 tests_start_mpfr (); 136 137 coverage (); 138 special (); 139 140 test_generic (MPFR_PREC_MIN, 100, 100); 141 142 data_check ("data/sinh", mpfr_sinh, "mpfr_sinh"); 143 bad_cases (mpfr_sinh, mpfr_asinh, "mpfr_sinh", 256, -256, 255, 144 4, 128, 800, 100); 145 146 tests_end_mpfr (); 147 return 0; 148} 149