1 /* Test file for mpfr_asinh. 2 3 Copyright 2001-2004, 2006-2023 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_asinh 26 #include "tgeneric.c" 27 28 static void 29 special (void) 30 { 31 mpfr_t x, y, z; 32 33 mpfr_init (x); 34 mpfr_init (y); 35 36 MPFR_SET_INF(x); 37 mpfr_set_ui (y, 1, MPFR_RNDN); 38 mpfr_asinh (x, y, MPFR_RNDN); 39 if (MPFR_IS_INF(x) || MPFR_IS_NAN(x) ) 40 { 41 printf ("Inf flag not clears in asinh!\n"); 42 exit (1); 43 } 44 45 MPFR_SET_NAN(x); 46 mpfr_asinh (x, y, MPFR_RNDN); 47 if (MPFR_IS_NAN(x) || MPFR_IS_INF(x)) 48 { 49 printf ("NAN flag not clears in asinh!\n"); 50 exit (1); 51 } 52 53 /* asinh(+0) = +0, asinh(-0) = -0 */ 54 mpfr_set_ui (x, 0, MPFR_RNDN); 55 mpfr_asinh (y, x, MPFR_RNDN); 56 if (MPFR_NOTZERO (y) || MPFR_IS_NEG (y)) 57 { 58 printf ("Error: mpfr_asinh(+0) <> +0\n"); 59 exit (1); 60 } 61 mpfr_neg (x, x, MPFR_RNDN); 62 mpfr_asinh (y, x, MPFR_RNDN); 63 if (MPFR_NOTZERO (y) || MPFR_IS_POS (y)) 64 { 65 printf ("Error: mpfr_asinh(-0) <> -0\n"); 66 exit (1); 67 } 68 69 MPFR_SET_NAN(x); 70 mpfr_asinh (y, x, MPFR_RNDN); 71 if (!mpfr_nan_p (y)) 72 { 73 printf ("Error: mpfr_asinh(NaN) <> NaN\n"); 74 exit (1); 75 } 76 77 mpfr_set_inf (x, 1); 78 mpfr_asinh (y, x, MPFR_RNDN); 79 if (!mpfr_inf_p (y) || mpfr_sgn (y) < 0) 80 { 81 printf ("Error: mpfr_asinh(+Inf) <> +Inf\n"); 82 exit (1); 83 } 84 85 mpfr_set_inf (x, -1); 86 mpfr_asinh (y, x, MPFR_RNDN); 87 if (!mpfr_inf_p (y) || mpfr_sgn (y) > 0) 88 { 89 printf ("Error: mpfr_asinh(-Inf) <> -Inf\n"); 90 exit (1); 91 } 92 93 mpfr_set_prec (x, 32); 94 mpfr_set_prec (y, 32); 95 96 mpfr_set_str_binary (x, "0.1010100100111011001111100101E-1"); 97 mpfr_asinh (x, x, MPFR_RNDN); 98 mpfr_set_str_binary (y, "0.10100110010010101101010011011101E-1"); 99 if (!mpfr_equal_p (x, y)) 100 { 101 printf ("Error: mpfr_asinh (1)\n"); 102 exit (1); 103 } 104 105 mpfr_set_str_binary (x, "-.10110011011010111110010001100001"); 106 mpfr_asinh (x, x, MPFR_RNDN); 107 mpfr_set_str_binary (y, "-.10100111010000111001011100110011"); 108 if (!mpfr_equal_p (x, y)) 109 { 110 printf ("Error: mpfr_asinh (2)\n"); 111 exit (1); 112 } 113 114 mpfr_set_prec (x, 33); 115 mpfr_set_prec (y, 43); 116 mpfr_set_str_binary (x, "0.111001101100000110011001010000101"); 117 mpfr_asinh (y, x, MPFR_RNDZ); 118 mpfr_init2 (z, 43); 119 mpfr_set_str_binary (z, "0.1100111101010101101010101110000001000111001"); 120 if (!mpfr_equal_p (y, z)) 121 { 122 printf ("Error: mpfr_asinh (3)\n"); 123 exit (1); 124 } 125 126 mpfr_set_prec (x, 53); 127 mpfr_set_prec (y, 2); 128 mpfr_set_str (x, "1.8000000000009@-6", 16, MPFR_RNDN); 129 mpfr_asinh (y, x, MPFR_RNDZ); 130 mpfr_set_prec (z, 2); 131 mpfr_set_str (z, "1.0@-6", 16, MPFR_RNDN); 132 if (!mpfr_equal_p (y, z)) 133 { 134 printf ("Error: mpfr_asinh (4)\n"); 135 exit (1); 136 } 137 138 mpfr_clear (x); 139 mpfr_clear (y); 140 mpfr_clear (z); 141 } 142 143 int 144 main (int argc, char *argv[]) 145 { 146 tests_start_mpfr (); 147 148 special (); 149 150 test_generic (MPFR_PREC_MIN, 100, 25); 151 152 data_check ("data/asinh", mpfr_asinh, "mpfr_asinh"); 153 bad_cases (mpfr_asinh, mpfr_sinh, "mpfr_asinh", 256, -128, 29, 154 4, 128, 800, 40); 155 156 tests_end_mpfr (); 157 return 0; 158 } 159