-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMPTest.cs
More file actions
148 lines (119 loc) · 3.96 KB
/
MPTest.cs
File metadata and controls
148 lines (119 loc) · 3.96 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
using System;
using System.Collections;
using System.Text;
using System.Diagnostics;
using MPMath;
public class MPIntTest
{
static void Main(string[] args)
{
Console.WriteLine(DateTime.Now);
Console.WriteLine("Simple clone test");
// Clone test
MPInt r1 = (long)(25*65536+15);
r1.DisplayBase = DisplayBases.Dec;
MPInt r2 = (MPInt)r1.Clone();
Console.WriteLine("These should be the same {0}, {1}",r1.ToString(), r2.ToString());
r2+= 12<<1;
Console.WriteLine("R1 should be unchanged: {0}, but R2=R1+24: {1}",r1.ToString(), r2.ToString());
Console.WriteLine("Simple addition test");
MPInt mpu1 = new MPInt();
mpu1 += 65535;
Console.WriteLine("mpu1 should be 65535: is {0}",mpu1);
MPInt mpu2 = new MPInt();
mpu2++;
Console.WriteLine("mpu2 should be 1: is {0}",mpu2);
int i;
for( i = 0; i<20; i++)
{
mpu1 += mpu2;
}
Console.WriteLine("mpu1 should be : {0}, is {1}",65535+20,mpu1);
Console.WriteLine("Simple subtraction test");
Console.WriteLine("i: {0}, mpu1: {1}",i, mpu1);
for(i=1; i<21; i++)
{
mpu1 -= mpu2;
Console.WriteLine("i: {0}, mpu1: {1}",i, mpu1);
}
Console.WriteLine("Simple addition test");
for(i=1; i<21; i++)
{
mpu1 += mpu2;
Console.WriteLine("i: {0}, mpu1: {1}",i, mpu1);
}
MPInt mpu3 = (long)(65536);
Console.WriteLine("Simple multiplication test, start with {0}",mpu3.ToString());
mpu3.DisplayBase = DisplayBases.Hex;
MPInt mpu4 = (long)1;
for(i=0; i<20; i++)
{
Console.WriteLine("mpu3 {0} :: mpu4 {1}",mpu3, mpu4);
mpu4++;
mpu3 *= mpu4;
}
Console.WriteLine("Simple division test");
for(i=0; i<21; i++)
{
mpu3.DisplayBase = DisplayBases.Hex;
Console.WriteLine("mpu3 {0} :: mpu4 {1}",mpu3, mpu4);
mpu3 /= mpu4;
mpu4--;
}
Console.WriteLine("Simple square test");
Console.WriteLine("'Fast'? square test");
MPInt mpuToSqr=0;
long start1 = DateTime.Now.Ticks;
for(int j=0; j<50; j++)
{
mpuToSqr = (long)625;
for(i=0; i<5; i++)
{
mpuToSqr = MPInt.Sqr(mpuToSqr);
}
}
TimeSpan ts = new TimeSpan(DateTime.Now.Ticks - start1);
Console.WriteLine("Square Time: {0}:{1}",ts.Seconds,ts.Milliseconds);
Console.WriteLine(mpuToSqr);
#if SLOW
Console.WriteLine("'Slow'? square test");
start1 = DateTime.Now.Ticks;
for(int j=0; j<50; j++){
mpuToSqr = (long)625;
for(i=0; i<5; i++){
mpuToSqr = MPInt.SlowSqr(mpuToSqr);
}
}
Console.WriteLine((DateTime.Now.Ticks - start1).ToString());
Console.WriteLine(mpuToSqr);
#endif
Console.WriteLine("Mod2 test");
MPInt mpuToMod = (long)65535;
mpuToMod = MPInt.Sqr(mpuToMod);
Console.WriteLine("65535 squared is: {0}",mpuToMod);
MPInt modded = MPInt.Mod2(mpuToMod,20);
Console.WriteLine("{0} mod 2^20 is {1}",mpuToMod,modded);
Console.WriteLine("Mod test");
mpuToMod = (long)65535;
mpuToMod = MPInt.Sqr(mpuToMod);
Console.WriteLine("65535 squared is: {0}",mpuToMod);
mpuToMod = MPInt.Sqr(mpuToMod);
Console.WriteLine("and that squared is: {0}",mpuToMod);
Console.WriteLine("and mod 65535, which should be 0 is {0}",MPInt.Mod(mpuToMod,65535));
Console.WriteLine("FactPair test");
TwoFact tf = new TwoFact();
for(int ipow=0; ipow< 64; ipow++)
{
Console.WriteLine("Two Power: {0}, Odd Power: {1}",tf[ipow].twofact,tf[ipow].oddfact);
}
Console.WriteLine("Number of binary and base K digit test");
MPInt digTest = (long)6670019976;
Console.WriteLine(digTest);
Console.WriteLine("Number of base 16 digits: {0}", digTest.Length);
Console.WriteLine("Number of binary digits: {0}", digTest.NumBinaryDigits);
digTest.DisplayBase = DisplayBases.Hex;
Console.WriteLine(digTest);
Console.WriteLine("Number of base K digits: {0}", digTest.Num5Digits);
Console.WriteLine(DateTime.Now);
}
}