[BACK]Return to spect.c CVS log [TXT][DIR] Up to [local] / OpenXM_contrib / gmp / tests / rand

Annotation of OpenXM_contrib/gmp/tests/rand/spect.c, Revision 1.1.1.1

1.1       maekawa     1: /* spect.c -- the spectral test */
                      2:
                      3: /*
                      4: Copyright (C) 1999 Free Software Foundation, Inc.
                      5:
                      6: This file is part of the GNU MP Library.
                      7:
                      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.
                     12:
                     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.
                     17:
                     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,
                     21: MA 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:
                     38: int g_debug = 0;
                     39:
                     40: int
                     41: main (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:
                    132: void
                    133: debug_foo()
                    134: {
                    135:   if (0)
                    136:     {
                    137:       mpz_dump (0);
                    138:       mpf_dump (0);
                    139:     }
                    140: }

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>