1/* Test file for mpfr_atanh. 2 3Copyright 2001, 2002, 2003, 2004, 2005, 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_atanh 29#define TEST_RANDOM_EMAX 7 30#include "tgeneric.c" 31 32static void 33special (void) 34{ 35 mpfr_t x, y, z; 36 int i; 37 38 mpfr_init (x); 39 mpfr_init (y); 40 41 MPFR_SET_INF(x); 42 mpfr_set_ui (y, 0, MPFR_RNDN); 43 mpfr_atanh (x, y, MPFR_RNDN); 44 if (MPFR_IS_INF(x) || MPFR_IS_NAN(x) ) 45 { 46 printf ("Inf flag not clears in atanh!\n"); 47 exit (1); 48 } 49 50 MPFR_SET_NAN(x); 51 mpfr_atanh (x, y, MPFR_RNDN); 52 if (MPFR_IS_NAN(x) || MPFR_IS_INF(x)) 53 { 54 printf ("NAN flag not clears in atanh!\n"); 55 exit (1); 56 } 57 58 /* atanh(+/-x) = NaN if x > 1 */ 59 for (i = 3; i <= 6; i++) 60 { 61 mpfr_set_si (x, i, MPFR_RNDN); 62 mpfr_div_2ui (x, x, 1, MPFR_RNDN); 63 mpfr_atanh (y, x, MPFR_RNDN); 64 if (!mpfr_nan_p (y)) 65 { 66 printf ("Error: mpfr_atanh(%d/2) <> NaN\n", i); 67 exit (1); 68 } 69 mpfr_neg (x, x, MPFR_RNDN); 70 mpfr_atanh (y, x, MPFR_RNDN); 71 if (!mpfr_nan_p (y)) 72 { 73 printf ("Error: mpfr_atanh(-%d/2) <> NaN\n", i); 74 exit (1); 75 } 76 } 77 78 /* atanh(+0) = +0, atanh(-0) = -0 */ 79 mpfr_set_ui (x, 0, MPFR_RNDN); 80 mpfr_atanh (y, x, MPFR_RNDN); 81 if (mpfr_cmp_ui (y, 0) || mpfr_sgn (y) < 0) 82 { 83 printf ("Error: mpfr_atanh(+0) <> +0\n"); 84 exit (1); 85 } 86 mpfr_neg (x, x, MPFR_RNDN); 87 mpfr_atanh (y, x, MPFR_RNDN); 88 if (mpfr_cmp_ui (y, 0) || mpfr_sgn (y) > 0) 89 { 90 printf ("Error: mpfr_atanh(-0) <> -0\n"); 91 exit (1); 92 } 93 94 MPFR_SET_NAN(x); 95 mpfr_atanh (y, x, MPFR_RNDN); 96 if (!mpfr_nan_p (y)) 97 { 98 printf ("Error: mpfr_atanh(NaN) <> NaN\n"); 99 exit (1); 100 } 101 102 mpfr_set_inf (x, 1); 103 mpfr_atanh (y, x, MPFR_RNDN); 104 if (!mpfr_nan_p (y)) 105 { 106 printf ("Error: mpfr_atanh(+Inf) <> NaN\n"); 107 mpfr_print_binary (y); printf ("\n"); 108 exit (1); 109 } 110 111 mpfr_set_inf (x, -1); 112 mpfr_atanh (y, x, MPFR_RNDN); 113 if (!mpfr_nan_p (y)) 114 { 115 printf ("Error: mpfr_atanh(-Inf) <> NaN\n"); 116 exit (1); 117 } 118 119 mpfr_set_ui (x, 1, MPFR_RNDN); 120 mpfr_atanh (y, x, MPFR_RNDN); 121 if (!mpfr_inf_p (y) || mpfr_sgn (y) < 0) 122 { 123 printf ("Error: mpfr_atanh(1) <> +Inf\n"); 124 exit (1); 125 } 126 127 mpfr_set_si (x, -1, MPFR_RNDN); 128 mpfr_atanh (y, x, MPFR_RNDN); 129 if (!mpfr_inf_p (y) || mpfr_sgn (y) > 0) 130 { 131 printf ("Error: mpfr_atanh(-1) <> -Inf\n"); 132 exit (1); 133 } 134 135 mpfr_set_prec (x, 32); 136 mpfr_set_prec (y, 32); 137 138 mpfr_set_str_binary (x, "0.10001000001001011000100001E-6"); 139 mpfr_atanh (x, x, MPFR_RNDN); 140 mpfr_set_str_binary (y, "0.10001000001001100101010110100001E-6"); 141 if (mpfr_cmp (x, y)) 142 { 143 printf ("Error: mpfr_atanh (1)\n"); 144 exit (1); 145 } 146 147 mpfr_set_str_binary (x, "-0.1101011110111100111010011001011E-1"); 148 mpfr_atanh (x, x, MPFR_RNDN); 149 mpfr_set_str_binary (y, "-0.11100110000100001111101100010111E-1"); 150 if (mpfr_cmp (x, y)) 151 { 152 printf ("Error: mpfr_atanh (2)\n"); 153 exit (1); 154 } 155 156 mpfr_set_prec (x, 33); 157 mpfr_set_prec (y, 43); 158 mpfr_set_str_binary (x, "0.111001101100000110011001010000101"); 159 mpfr_atanh (y, x, MPFR_RNDZ); 160 mpfr_init2 (z, 43); 161 mpfr_set_str_binary (z, "1.01111010110001101001000000101101011110101"); 162 if (mpfr_cmp (y, z)) 163 { 164 printf ("Error: mpfr_atanh (3)\n"); 165 mpfr_print_binary (y); printf ("\n"); 166 exit (1); 167 } 168 169 mpfr_clear (x); 170 mpfr_clear (y); 171 mpfr_clear (z); 172} 173 174int 175main (int argc, char *argv[]) 176{ 177 tests_start_mpfr (); 178 179 special (); 180 181 test_generic (2, 100, 25); 182 183 data_check ("data/atanh", mpfr_atanh, "mpfr_atanh"); 184 bad_cases (mpfr_atanh, mpfr_tanh, "mpfr_atanh", 256, -128, 9, 185 4, 128, 800, 100); 186 187 tests_end_mpfr (); 188 return 0; 189} 190