~ubuntu-branches/ubuntu/intrepid/ecl/intrepid

« back to all changes in this revision

Viewing changes to src/gmp/tests/mpn/t-scan.c

  • Committer: Bazaar Package Importer
  • Author(s): Peter Van Eynde
  • Date: 2006-05-17 02:46:26 UTC
  • Revision ID: james.westby@ubuntu.com-20060517024626-lljr08ftv9g9vefl
Tags: upstream-0.9h-20060510
ImportĀ upstreamĀ versionĀ 0.9h-20060510

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* Test mpn_scan0 and mpn_scan1.
 
2
 
 
3
Copyright 2002 Free Software Foundation, Inc.
 
4
 
 
5
This file is part of the GNU MP Library.
 
6
 
 
7
The GNU MP Library is free software; you can redistribute it and/or modify
 
8
it under the terms of the GNU Lesser General Public License as published by
 
9
the Free Software Foundation; either version 2.1 of the License, or (at your
 
10
option) any later version.
 
11
 
 
12
The GNU MP Library is distributed in the hope that it will be useful, but
 
13
WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
 
14
or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public
 
15
License for more details.
 
16
 
 
17
You should have received a copy of the GNU Lesser General Public License
 
18
along with the GNU MP Library; see the file COPYING.LIB.  If not, write to
 
19
the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
 
20
MA 02111-1307, USA. */
 
21
 
 
22
#include <stdio.h>
 
23
#include <stdlib.h>
 
24
 
 
25
#include "gmp.h"
 
26
#include "gmp-impl.h"
 
27
 
 
28
#include "tests.h"
 
29
 
 
30
 
 
31
#define SIZE  3
 
32
mp_limb_t  x[SIZE+1];
 
33
 
 
34
void
 
35
check (void)
 
36
{
 
37
  unsigned long  i, got, want;
 
38
 
 
39
  x[SIZE] = 1;
 
40
  for (i = 0; i < SIZE*GMP_NUMB_BITS; i++)
 
41
    {
 
42
      got = refmpn_scan1 (x, i);
 
43
      want = mpn_scan1 (x, i);
 
44
      if (got != want)
 
45
        {
 
46
          printf ("mpn_scan1\n");
 
47
          printf ("  i     %lu\n", i);
 
48
          printf ("  got   %lu\n", got);
 
49
          printf ("  want  %lu\n", want);
 
50
          mpn_trace ("  x    ", x, SIZE);
 
51
          abort ();
 
52
        }
 
53
    }
 
54
 
 
55
  x[SIZE] = 0;
 
56
  for (i = 0; i < SIZE*GMP_NUMB_BITS; i++)
 
57
    {
 
58
      got = refmpn_scan0 (x, i);
 
59
      want = mpn_scan0 (x, i);
 
60
      if (got != want)
 
61
        {
 
62
          printf ("mpn_scan0\n");
 
63
          printf ("  i     %lu\n", i);
 
64
          printf ("  got   %lu\n", got);
 
65
          printf ("  want  %lu\n", want);
 
66
          mpn_trace ("  x    ", x, SIZE);
 
67
          abort ();
 
68
        }
 
69
    }
 
70
}
 
71
 
 
72
void
 
73
check_twobits (void)
 
74
{
 
75
  unsigned long  i, j;
 
76
 
 
77
  for (i = 0; i < GMP_NUMB_BITS * SIZE; i++)
 
78
    {
 
79
      for (j = 0; j < GMP_NUMB_BITS * SIZE; j++)
 
80
        {
 
81
          refmpn_zero (x, SIZE);
 
82
          refmpn_setbit (x, i);
 
83
          refmpn_setbit (x, j);
 
84
          check ();
 
85
        }
 
86
    }
 
87
}
 
88
 
 
89
void
 
90
check_rand (void)
 
91
{
 
92
  int  i;
 
93
 
 
94
  for (i = 0; i < 100; i++)
 
95
    {
 
96
      refmpn_random2 (x, SIZE);
 
97
      check ();
 
98
    }
 
99
}
 
100
 
 
101
int
 
102
main (void)
 
103
{
 
104
  mp_trace_base = -16;
 
105
  tests_start ();
 
106
 
 
107
  check_twobits ();
 
108
  check_rand ();
 
109
 
 
110
  tests_end ();
 
111
  exit (0);
 
112
}