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