source: trunk/third/gmp/tests/rand/spect.c @ 18191

Revision 18191, 3.2 KB checked in by ghudson, 22 years ago (diff)
This commit was generated by cvs2svn to compensate for changes in r18190, which included commits to RCS files with non-trunk default branches.
Line 
1/* spect.c -- the spectral test */
2
3/*
4Copyright 1999 Free Software Foundation, Inc.
5
6This file is part of the GNU MP Library.
7
8The GNU MP 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 2.1 of the License, or (at your
11option) any later version.
12
13The GNU MP 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 MP Library; see the file COPYING.LIB.  If not, write to
20the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
21MA 02111-1307, USA.
22*/
23
24/* T is upper dimension.  Z_A is the LC multiplier, which is
25   relatively prime to Z_M, the LC modulus.  The result is put in
26   rop[] with v[t] in rop[t-2]. */
27
28/* BUGS: Due to lazy allocation scheme, maximum T is hard coded to MAXT. */
29
30#include <stdio.h>
31#include <stdlib.h>
32#include <unistd.h>
33#include <math.h>
34#include "gmp.h"
35
36#include "gmpstat.h"
37
38int g_debug = 0;
39
40int
41main (int argc, char *argv[])
42{
43  const char usage[] = "usage: spect [-d] a m n\n";
44  int c;
45  unsigned int n;
46  mpz_t a, m;
47  mpf_t res[GMP_SPECT_MAXT], res_min[GMP_SPECT_MAXT], f_tmp;
48  register int f;
49
50
51  mpz_init (a);
52  mpz_init (m);
53  for (f = 0; f < GMP_SPECT_MAXT; f++)
54    {
55      mpf_init (res[f]);
56      mpf_init (res_min[f]);
57    }
58  mpf_init (f_tmp);
59  mpf_set_ui (res_min[0], 32768); /* 2^15 */
60  mpf_set_ui (res_min[1], 1024); /* 2^10 */
61  mpf_set_ui (res_min[2], 256); /* 2^8 */
62  mpf_set_ui (res_min[3], 64); /* 2^6 */
63  mpf_set_ui (res_min[4], 32); /* 2^5 */
64
65  while ((c = getopt (argc, argv, "dh")) != -1)
66    switch (c)
67      {
68      case 'd':                 /* debug */
69        g_debug++;
70        break;
71      case 'h':
72      default:
73        fputs (usage, stderr);
74        exit (1);
75      }
76  argc -= optind;
77  argv += optind;
78
79  if (argc < 3)
80    {
81      fputs (usage, stderr);
82      exit (1);
83    }
84
85  mpz_set_str (a, argv[0], 0);
86  mpz_set_str (m, argv[1], 0);
87  n = (unsigned int) atoi (argv[2]);
88  if (n + 1 > GMP_SPECT_MAXT)
89    n = GMP_SPECT_MAXT + 1;
90
91  spectral_test (res, n, a, m);
92
93  for (f = 0; f < n - 1; f++)
94    {
95      /* print v */
96      printf ("%d: v = ", f + 2);
97      mpf_out_str (stdout, 10, 4, res[f]);
98
99#ifdef PRINT_RAISED_BY_TWO_AS_WELL
100      printf (" (^2 = ");
101      mpf_mul (f_tmp, res[f], res[f]);
102      mpf_out_str (stdout, 10, 4, f_tmp);
103      printf (")");
104#endif /* PRINT_RAISED_BY_TWO_AS_WELL */
105
106      /* print merit */
107      printf (" m = ");
108      merit (f_tmp, f + 2, res[f], m);
109      mpf_out_str (stdout, 10, 4, f_tmp);
110
111      if (mpf_cmp (res[f], res_min[f]) < 0)
112        printf ("\t*** v too low ***");
113      if (mpf_get_d (f_tmp) < .1)
114        printf ("\t*** merit too low ***");
115
116      puts ("");
117    }
118
119  mpz_clear (a);
120  mpz_clear (m);
121  for (f = 0; f < GMP_SPECT_MAXT; f++)
122    {
123      mpf_clear (res[f]);
124      mpf_clear (res_min[f]);
125    }
126  mpf_clear (f_tmp);
127
128  return 0;
129}
130
131
132void
133debug_foo()
134{
135  if (0)
136    {
137      mpz_dump (0);
138      mpf_dump (0);
139    }
140}
Note: See TracBrowser for help on using the repository browser.