1 /* Test file for mpfr_ai. 2 3 Copyright 2010, 2011, 2012, 2013 Free Software Foundation, Inc. 4 Contributed by the AriC and Caramel 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 http://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 <stdio.h> 24 #include <stdlib.h> 25 #include <limits.h> 26 27 #include "mpfr-test.h" 28 29 #define TEST_FUNCTION mpfr_ai 30 #define TEST_RANDOM_EMIN -5 31 #define TEST_RANDOM_EMAX 5 32 #define REDUCE_EMAX 7 /* this is to avoid that test_generic() calls mpfr_ai 33 with too large inputs. FIXME: remove this once 34 mpfr_ai can handle large inputs */ 35 #include "tgeneric.c" 36 37 static void 38 check_large (void) 39 { 40 mpfr_t x, y, z; 41 42 mpfr_init2 (x, 38); 43 mpfr_init2 (y, 110); 44 mpfr_init2 (z, 110); 45 mpfr_set_str_binary (x, "-1E8"); 46 mpfr_ai (y, x, MPFR_RNDN); 47 mpfr_set_str_binary (z, "-10001110100001011111110001100011101100011100010000110100100101011111011100000101110101010010000000101110011111E-112"); 48 if (mpfr_equal_p (y, z) == 0) 49 { 50 printf ("Error in mpfr_ai for x=-2^8\n"); 51 exit (1); 52 } 53 #if 0 /* disabled since mpfr_ai does not currently handle large arguments */ 54 mpfr_set_str_binary (x, "-1E26"); 55 mpfr_ai (y, x, MPFR_RNDN); 56 mpfr_set_str_binary (z, "-110001111100000011001010010101001101001011001011101011001010100100001110001101101101000010000011001000001011E-118"); 57 if (mpfr_equal_p (y, z) == 0) 58 { 59 printf ("Error in mpfr_ai for x=-2^26\n"); 60 exit (1); 61 } 62 mpfr_set_str_binary (x, "-0.11111111111111111111111111111111111111E1073741823"); 63 mpfr_ai (y, x, MPFR_RNDN); 64 /* FIXME: compute the correctly rounded value we should get for Ai(x), 65 and check we get this value */ 66 #endif 67 mpfr_clear (x); 68 mpfr_clear (y); 69 mpfr_clear (z); 70 } 71 72 static void 73 check_zero (void) 74 { 75 mpfr_t x, y, r; 76 77 mpfr_init2 (x, 53); 78 mpfr_init2 (y, 53); 79 mpfr_init2 (r, 53); 80 81 mpfr_set_str_binary (r, "10110101110001100011110010110001001110001010110111E-51"); 82 83 mpfr_set_ui (x, 0, MPFR_RNDN); 84 mpfr_ai (y, x, MPFR_RNDN); 85 if (mpfr_equal_p (y, r) == 0) 86 { 87 printf ("Error in mpfr_ai for x=0\n"); 88 printf ("Expected "); mpfr_dump (r); 89 printf ("Got "); mpfr_dump (y); 90 exit (1); 91 } 92 mpfr_clear (x); 93 mpfr_clear (y); 94 mpfr_clear (r); 95 } 96 97 int 98 main (int argc, char *argv[]) 99 { 100 tests_start_mpfr (); 101 102 check_large (); 103 check_zero (); 104 105 test_generic (2, 100, 5); 106 107 tests_end_mpfr (); 108 return 0; 109 } 110