1/* Test file for internal debugging-out functions: 2 mpfr_print_rnd_mode, mpfr_dump, mpfr_print_mant_binary. 3 4Copyright 2004-2023 Free Software Foundation, Inc. 5Contributed by the AriC and Caramba projects, INRIA. 6 7This file is part of the GNU MPFR Library. 8 9The GNU MPFR Library is free software; you can redistribute it and/or modify 10it under the terms of the GNU Lesser General Public License as published by 11the Free Software Foundation; either version 3 of the License, or (at your 12option) any later version. 13 14The GNU MPFR Library is distributed in the hope that it will be useful, but 15WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 16or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public 17License for more details. 18 19You should have received a copy of the GNU Lesser General Public License 20along with the GNU MPFR Library; see the file COPYING.LESSER. If not, see 21https://www.gnu.org/licenses/ or write to the Free Software Foundation, Inc., 2251 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. */ 23 24#include "mpfr-test.h" 25 26#define FILE_NAME "toutimpl_out.txt" 27 28static const char Buffer[] = 29 "@NaN@\n" 30 "-@NaN@\n" 31 "@Inf@\n" 32 "-@Inf@\n" 33 "0\n" 34 "-0\n" 35 "0.10101010101011111001000110001100010000100000000000000E32\n" 36#if GMP_NUMB_BITS == 32 37 "x = 10101010101011111001000110001100.010000100000000000000[00000000000.]\n" 38 "0.01010101010101111100100011000110010000100000000000000[00000000001]E32!!!NT<!!!\n" 39 "0.01010101010101111100100011000110010000100000000000000[00000000001]E32!!!NT>!!!\n" 40#elif GMP_NUMB_BITS == 64 41 "x = 10101010101011111001000110001100010000100000000000000[00000000000.]\n" 42 "0.01010101010101111100100011000110001000010000000000000[00000000001]E32!!!NT<!!!\n" 43 "0.01010101010101111100100011000110001000010000000000000[00000000001]E32!!!NT>!!!\n" 44#endif 45 ; 46 47int 48main (void) 49{ 50 mpfr_exp_t e; 51 mpfr_t x; 52 FILE *f; 53 int i; 54 55 tests_start_mpfr (); 56 57 /* Check RND_MODE */ 58 if (strcmp (mpfr_print_rnd_mode (MPFR_RNDN), "MPFR_RNDN")) 59 { 60 printf ("Error for printing MPFR_RNDN\n"); 61 exit (1); 62 } 63 if (strcmp (mpfr_print_rnd_mode (MPFR_RNDU), "MPFR_RNDU")) 64 { 65 printf ("Error for printing MPFR_RNDU\n"); 66 exit (1); 67 } 68 if (strcmp (mpfr_print_rnd_mode (MPFR_RNDD), "MPFR_RNDD")) 69 { 70 printf ("Error for printing MPFR_RNDD\n"); 71 exit (1); 72 } 73 if (strcmp (mpfr_print_rnd_mode (MPFR_RNDZ), "MPFR_RNDZ")) 74 { 75 printf ("Error for printing MPFR_RNDZ\n"); 76 exit (1); 77 } 78 if (mpfr_print_rnd_mode ((mpfr_rnd_t) -1) != NULL || 79 mpfr_print_rnd_mode (MPFR_RND_MAX) != NULL) 80 { 81 printf ("Error for illegal rounding mode values.\n"); 82 exit (1); 83 } 84 85 /* Reopen stdout to a file. All errors will be put to stderr. */ 86 if (freopen (FILE_NAME, "w", stdout) == NULL) 87 { 88 printf ("Error can't redirect stdout\n"); 89 exit (1); 90 } 91 mpfr_init2 (x, 53); 92 mpfr_set_nan (x); 93 mpfr_dump (x); 94 MPFR_CHANGE_SIGN (x); 95 mpfr_dump (x); 96 mpfr_set_inf (x, +1); 97 mpfr_dump (x); 98 mpfr_set_inf (x, -1); 99 mpfr_dump (x); 100 mpfr_set_zero (x, +1); 101 mpfr_dump (x); 102 mpfr_set_zero (x, -1); 103 mpfr_dump (x); 104 mpfr_set_str_binary (x, "0.101010101010111110010001100011000100001E32"); 105 mpfr_dump (x); 106 mpfr_print_mant_binary ("x =", MPFR_MANT(x), MPFR_PREC(x)); 107 MPFR_MANT(x)[MPFR_LAST_LIMB(x)] >>= 1; 108 MPFR_MANT(x)[0] |= 1; 109 e = mpfr_get_emin (); 110 set_emin (33); 111 mpfr_dump (x); 112 set_emin (e); 113 e = mpfr_get_emax (); 114 set_emax (31); 115 mpfr_dump (x); 116 set_emax (e); 117 mpfr_clear (x); 118 fclose (stdout); 119 120 /* Open it and check for it */ 121 f = fopen (FILE_NAME, "r"); 122 if (f == NULL) 123 { 124 fprintf (stderr, "Can't reopen file!\n"); 125 exit (1); 126 } 127 for (i = 0 ; i < sizeof (Buffer) - 1 ; i++) 128 { 129 if (feof (f)) 130 { 131 fprintf (stderr, "Error EOF\n"); 132 exit (1); 133 } 134 if (Buffer[i] != fgetc (f)) 135 { 136 fprintf (stderr, "Character mismatch for i = %d / %lu\n", 137 i, (unsigned long) sizeof (Buffer)); 138 exit (1); 139 } 140 } 141 fclose (f); 142 143 remove (FILE_NAME); 144 tests_end_mpfr (); 145 return 0; 146} 147