1
/* trace.c -- Support for diagnostic traces. */
4
Copyright (C) 1999, 2000 Free Software Foundation, Inc.
6
This file is part of the GNU MP Library.
8
The GNU MP 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 2.1 of the License, or (at your
11
option) any later version.
13
The GNU MP 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.
18
You should have received a copy of the GNU Lesser General Public License
19
along with the GNU MP Library; see the file COPYING.LIB. If not, write to
20
the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
30
/* Number base for the various trace printing routines.
31
Set this in main() or with the debugger.
32
If hexadecimal is going to be fed into GNU bc, remember to use -16
33
because bc requires upper case. */
35
int mp_trace_base = 10;
38
/* Print "name=value\n" to stdout for an mpq_t value. */
40
mpq_trace (const char *name, mpq_srcptr q)
42
if (name != NULL && name[0] != '\0')
45
switch (ABS (mp_trace_base)) {
46
case 8: printf ("oct"); break;
48
case 16: printf ("0x"); break;
49
default: printf ("base%d:", ABS (mp_trace_base)); break;
52
mpq_out_str (stdout, mp_trace_base, q);
54
/* It's not very interesting to know when numbers are unnormalized.
55
mpz's should always be and ought to be checked with ASSERT() if in doubt.
56
mpn's can often be unnormalized without affecting anything. */
57
/* if (!mpq_normalized_p (z)) printf (" (unnorm)"); */
63
/* Print "name=value\n" to stdout for an mpz_t value. */
65
mpz_trace (const char *name, mpz_srcptr z)
82
/* Print "namenum=value\n" to stdout for an mpz_t value.
83
"name" should have a "%d" to get the number. */
85
mpz_tracen (const char *name, int num, mpz_srcptr z)
87
if (name != NULL && name[0] != '\0')
96
/* Print "name=value\n" to stdout for an mpn style ptr,size. */
98
mpn_trace (const char *name, mp_srcptr ptr, mp_size_t size)
101
MPN_NORMALIZE (ptr, size);
102
PTR(z) = (mp_ptr) ptr;
108
/* Print "namenum=value\n" to stdout for an mpn style ptr,size.
109
"name" should have a "%d" to get the number. */
111
mpn_tracen (const char *name, int num, mp_srcptr ptr, mp_size_t size)
113
if (name != NULL && name[0] != '\0')
118
mpn_trace (NULL, ptr, size);
122
/* Print "namenum=value\n" to stdout for an array of mpn style ptr,size.
124
"a" is an array of pointers, each a[i] is a pointer to "size" many limbs.
125
The formal parameter isn't mp_srcptr because that causes compiler
126
warnings, but the values aren't modified.
128
"name" should have a printf style "%d" to get the array index. */
131
mpn_tracea (const char *name, const mp_ptr *a, int count, mp_size_t size)
134
for (i = 0; i < count; i++)
135
mpn_tracen (name, i, a[i], size);
139
/* Print "value\n" to a file for an mpz_t value. Any previous contents of
140
the file are overwritten, so you need different file names each time this
143
Overwriting the file is a feature, it means you get old data replaced
144
when you run a test program repeatedly. */
147
mpn_trace_file (const char *filename, mp_srcptr ptr, mp_size_t size)
152
fp = fopen (filename, "w");
159
MPN_NORMALIZE (ptr, size);
160
PTR(z) = (mp_ptr) ptr;
163
mpz_out_str (fp, mp_trace_base, z);
166
if (ferror (fp) || fclose (fp) != 0)
168
printf ("error writing %s\n", filename);
174
/* Print "value\n" to a set of files, one file for each element of the given
175
array of mpn style ptr,size. Any previous contents of the files are
176
overwritten, so you need different file names each time this is called.
177
Each file is "filenameN" where N is 0 to count-1.
179
"a" is an array of pointers, each a[i] is a pointer to "size" many limbs.
180
The formal parameter isn't mp_srcptr because that causes compiler
181
warnings, but the values aren't modified.
183
Overwriting the files is a feature, it means you get old data replaced
184
when you run a test program repeatedly. The output style isn't
185
particularly pretty, but at least it gets something out, and you can cat
186
the files into bc, or whatever. */
189
mpn_tracea_file (const char *filename,
190
const mp_ptr *a, int count, mp_size_t size)
197
s = (char *) TMP_ALLOC (strlen (filename) + 50);
199
for (i = 0; i < count; i++)
201
sprintf (s, "%s%d", filename, i);
202
mpn_trace_file (s, a[i], size);