1 /* Test file for mpfr_inp_str. 2 3 Copyright 2004, 2006-2018 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 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 "mpfr-test.h" 24 25 int 26 main (int argc, char *argv[]) 27 { 28 mpfr_t x; 29 mpfr_t y; 30 FILE *f; 31 int i, n; 32 33 tests_start_mpfr (); 34 35 mpfr_init (x); 36 mpfr_init (y); 37 38 mpfr_set_prec (x, 15); 39 f = src_fopen ("inp_str.dat", "r"); 40 if (f == NULL) 41 { 42 printf ("Error, can't open inp_str.dat\n"); 43 exit (1); 44 } 45 i = mpfr_inp_str (x, f, 10, MPFR_RNDN); 46 if (i == 0 || mpfr_cmp_si (x, -1700)) 47 { 48 printf ("Error in reading 1st line from file inp_str.dat (%d)\n", i); 49 mpfr_dump (x); 50 exit (1); 51 } 52 i = mpfr_inp_str (x, f, 10, MPFR_RNDN); 53 if (i == 0 || mpfr_cmp_ui (x, 31415)) 54 { 55 printf ("Error in reading 2nd line from file inp_str.dat (%d)\n", i); 56 mpfr_dump (x); 57 exit (1); 58 } 59 getc (f); 60 i = mpfr_inp_str (x, f, 10, MPFR_RNDN); 61 if (i == 0 || mpfr_cmp_ui (x, 31416)) 62 { 63 printf ("Error in reading 3rd line from file inp_str.dat (%d)\n", i); 64 mpfr_dump (x); 65 exit (1); 66 } 67 getc (f); 68 i = mpfr_inp_str (x, f, 10, MPFR_RNDN); 69 if (i != 0) 70 { 71 printf ("Error in reading 4th line from file inp_str.dat (%d)\n", i); 72 mpfr_dump (x); 73 exit (1); 74 } 75 76 mpfr_set_prec (x, 53); 77 mpfr_set_prec (y, 53); 78 mpfr_set_str (y, "1.0010010100001110100101001110011010111011100001110010e226", 79 2, MPFR_RNDN); 80 for (n = 2; n < 63; n++) 81 { 82 getc (f); 83 i = mpfr_inp_str (x, f, n, MPFR_RNDN); 84 if (i == 0 || !mpfr_equal_p (x, y)) 85 { 86 printf ("Error in reading %dth line from file inp_str.dat (%d)\n", 87 n+3, i); 88 mpfr_dump (x); 89 exit (1); 90 } 91 mpfr_set_ui (x, 0, MPFR_RNDN); 92 } 93 94 fclose (f); 95 96 mpfr_clear (x); 97 mpfr_clear (y); 98 99 tests_end_mpfr (); 100 return 0; 101 } 102