1 /* Test file for mpfr_acosh. 2 3 Copyright 2001-2004, 2006-2020 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 https://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 #define TEST_FUNCTION mpfr_acosh 26 #define TEST_RANDOM_POS 4 27 #define TEST_RANDOM_EMIN 1 28 #include "tgeneric.c" 29 30 #define TEST_FUNCTION mpfr_acosh 31 #define TEST_RANDOM_POS 1 32 #define TEST_RANDOM_EMIN MPFR_EMAX_MAX 33 #define TEST_RANDOM_EMAX MPFR_EMAX_MAX 34 #define test_generic test_generic_huge 35 #include "tgeneric.c" 36 37 static void 38 special (void) 39 { 40 mpfr_t x, y; 41 42 mpfr_init (x); 43 mpfr_init (y); 44 45 MPFR_SET_INF(x); 46 mpfr_set_ui (y, 1, MPFR_RNDN); 47 mpfr_acosh (x, y, MPFR_RNDN); 48 if (MPFR_IS_INF(x) || MPFR_IS_NAN(x) ) 49 { 50 printf ("Inf flag not clears in acosh!\n"); 51 exit (1); 52 } 53 if (mpfr_cmp_ui (x, 0)) 54 { 55 printf ("Error: mpfr_acosh(1) <> 0\n"); 56 exit (1); 57 } 58 59 MPFR_SET_NAN(x); 60 mpfr_acosh (x, y, MPFR_RNDN); 61 if (MPFR_IS_NAN(x) || MPFR_IS_INF(x) ) 62 { 63 printf ("NAN flag not clears in acosh!\n"); 64 exit (1); 65 } 66 67 mpfr_set_ui (x, 0, MPFR_RNDN); 68 mpfr_acosh (y, x, MPFR_RNDN); 69 if (!mpfr_nan_p (y)) 70 { 71 printf ("Error: mpfr_acosh(0) <> NaN\n"); 72 exit (1); 73 } 74 75 mpfr_set_si (x, -1, MPFR_RNDN); 76 mpfr_acosh (y, x, MPFR_RNDN); 77 if (!mpfr_nan_p (y)) 78 { 79 printf ("Error: mpfr_acosh(-1) <> NaN\n"); 80 exit (1); 81 } 82 83 MPFR_SET_NAN(x); 84 mpfr_acosh (y, x, MPFR_RNDN); 85 if (!mpfr_nan_p (y)) 86 { 87 printf ("Error: mpfr_acosh(NaN) <> NaN\n"); 88 exit (1); 89 } 90 91 mpfr_set_inf (x, 1); 92 mpfr_acosh (y, x, MPFR_RNDN); 93 if (!mpfr_inf_p (y) || mpfr_sgn (y) < 0) 94 { 95 printf ("Error: mpfr_acosh(+Inf) <> +Inf\n"); 96 exit (1); 97 } 98 99 mpfr_set_inf (x, -1); 100 mpfr_acosh (y, x, MPFR_RNDN); 101 if (!mpfr_nan_p (y)) 102 { 103 printf ("Error: mpfr_acosh(-Inf) <> NaN\n"); 104 exit (1); 105 } 106 107 mpfr_set_ui (x, 1, MPFR_RNDN); 108 mpfr_div_2ui (x, x, 1, MPFR_RNDN); 109 mpfr_acosh (y, x, MPFR_RNDN); 110 if (!mpfr_nan_p (y)) 111 { 112 printf ("Error: mpfr_acosh(1/2) <> NaN\n"); 113 exit (1); 114 } 115 116 mpfr_set_prec (x, 32); 117 mpfr_set_prec (y, 32); 118 mpfr_set_str_binary (x, "1.000001101011101111001011"); 119 mpfr_acosh (y, x, MPFR_RNDN); 120 mpfr_set_str_binary (x, "0.111010100101101001010001101001E-2"); 121 if (mpfr_cmp (x, y)) 122 { 123 printf ("Error: mpfr_acosh (1)\n"); 124 exit (1); 125 } 126 127 mpfr_clear (x); 128 mpfr_clear (y); 129 } 130 131 /* With MPFR 2.3.0, this yields an assertion failure in mpfr_acosh. */ 132 static void 133 bug20070831 (void) 134 { 135 mpfr_t x, y, z; 136 int inex; 137 138 mpfr_init2 (x, 256); 139 mpfr_init2 (y, 32); 140 mpfr_init2 (z, 32); 141 142 mpfr_set_ui (x, 1, MPFR_RNDN); 143 mpfr_nextabove (x); 144 inex = mpfr_acosh (y, x, MPFR_RNDZ); 145 mpfr_set_ui_2exp (z, 1, -127, MPFR_RNDN); 146 mpfr_nextbelow (z); 147 if (!mpfr_equal_p (y, z)) 148 { 149 printf ("Error in bug20070831 (1):\nexpected "); 150 mpfr_dump (z); 151 printf ("got "); 152 mpfr_dump (y); 153 exit (1); 154 } 155 MPFR_ASSERTN (inex < 0); 156 157 mpfr_nextabove (x); 158 mpfr_set_prec (y, 29); 159 inex = mpfr_acosh (y, x, MPFR_RNDN); 160 mpfr_set_str_binary (z, "1.011010100000100111100110011E-127"); 161 if (!mpfr_equal_p (y, z)) 162 { 163 printf ("Error in bug20070831 (2):\nexpected "); 164 mpfr_dump (z); 165 printf ("got "); 166 mpfr_dump (y); 167 exit (1); 168 } 169 MPFR_ASSERTN (inex < 0); 170 171 mpfr_clears (x, y, z, (mpfr_ptr) 0); 172 } 173 174 static void 175 huge (void) 176 { 177 mpfr_t x, y, z; 178 int inex; 179 180 /* TODO: extend the exponent range and use mpfr_get_emax (). */ 181 mpfr_inits2 (32, x, y, z, (mpfr_ptr) 0); 182 mpfr_set_ui_2exp (x, 1, 1073741822, MPFR_RNDN); 183 inex = mpfr_acosh (y, x, MPFR_RNDN); 184 mpfr_set_str_binary (z, "0.10110001011100100001011111110101E30"); 185 if (!mpfr_equal_p (y, z)) 186 { 187 printf ("Error in huge:\nexpected "); 188 mpfr_dump (z); 189 printf ("got "); 190 mpfr_dump (y); 191 exit (1); 192 } 193 MPFR_ASSERTN (inex < 0); 194 195 mpfr_clears (x, y, z, (mpfr_ptr) 0); 196 } 197 198 int 199 main (int argc, char *argv[]) 200 { 201 tests_start_mpfr (); 202 203 special (); 204 bug20070831 (); 205 huge (); 206 207 test_generic (MPFR_PREC_MIN, 100, 25); 208 test_generic_huge (MPFR_PREC_MIN, 100, 5); 209 210 data_check ("data/acosh", mpfr_acosh, "mpfr_acosh"); 211 bad_cases (mpfr_acosh, mpfr_cosh, "mpfr_acosh", 0, -128, 29, 212 4, 128, 800, 40); 213 214 tests_end_mpfr (); 215 return 0; 216 } 217