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