OLD | NEW |
1 // Copyright 2010 the V8 project authors. All rights reserved. | 1 // Copyright 2010 the V8 project authors. All rights reserved. |
2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
4 // met: | 4 // met: |
5 // | 5 // |
6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
47 bignum->AssignDecimalString(Vector<const char>(str, StrLength(str))); | 47 bignum->AssignDecimalString(Vector<const char>(str, StrLength(str))); |
48 } | 48 } |
49 | 49 |
50 | 50 |
51 TEST(Assign) { | 51 TEST(Assign) { |
52 char buffer[kBufferSize]; | 52 char buffer[kBufferSize]; |
53 Bignum bignum; | 53 Bignum bignum; |
54 Bignum bignum2; | 54 Bignum bignum2; |
55 bignum.AssignUInt16(0); | 55 bignum.AssignUInt16(0); |
56 CHECK(bignum.ToHexString(buffer, kBufferSize)); | 56 CHECK(bignum.ToHexString(buffer, kBufferSize)); |
57 CHECK_EQ("0", buffer); | 57 CHECK_EQ(0, strcmp("0", buffer)); |
58 bignum.AssignUInt16(0xA); | 58 bignum.AssignUInt16(0xA); |
59 CHECK(bignum.ToHexString(buffer, kBufferSize)); | 59 CHECK(bignum.ToHexString(buffer, kBufferSize)); |
60 CHECK_EQ("A", buffer); | 60 CHECK_EQ(0, strcmp("A", buffer)); |
61 bignum.AssignUInt16(0x20); | 61 bignum.AssignUInt16(0x20); |
62 CHECK(bignum.ToHexString(buffer, kBufferSize)); | 62 CHECK(bignum.ToHexString(buffer, kBufferSize)); |
63 CHECK_EQ("20", buffer); | 63 CHECK_EQ(0, strcmp("20", buffer)); |
64 | 64 |
65 | 65 |
66 bignum.AssignUInt64(0); | 66 bignum.AssignUInt64(0); |
67 CHECK(bignum.ToHexString(buffer, kBufferSize)); | 67 CHECK(bignum.ToHexString(buffer, kBufferSize)); |
68 CHECK_EQ("0", buffer); | 68 CHECK_EQ(0, strcmp("0", buffer)); |
69 bignum.AssignUInt64(0xA); | 69 bignum.AssignUInt64(0xA); |
70 CHECK(bignum.ToHexString(buffer, kBufferSize)); | 70 CHECK(bignum.ToHexString(buffer, kBufferSize)); |
71 CHECK_EQ("A", buffer); | 71 CHECK_EQ(0, strcmp("A", buffer)); |
72 bignum.AssignUInt64(0x20); | 72 bignum.AssignUInt64(0x20); |
73 CHECK(bignum.ToHexString(buffer, kBufferSize)); | 73 CHECK(bignum.ToHexString(buffer, kBufferSize)); |
74 CHECK_EQ("20", buffer); | 74 CHECK_EQ(0, strcmp("20", buffer)); |
75 bignum.AssignUInt64(0x100); | 75 bignum.AssignUInt64(0x100); |
76 CHECK(bignum.ToHexString(buffer, kBufferSize)); | 76 CHECK(bignum.ToHexString(buffer, kBufferSize)); |
77 CHECK_EQ("100", buffer); | 77 CHECK_EQ(0, strcmp("100", buffer)); |
78 | 78 |
79 // The first real test, since this will not fit into one bigit. | 79 // The first real test, since this will not fit into one bigit. |
80 bignum.AssignUInt64(0x12345678); | 80 bignum.AssignUInt64(0x12345678); |
81 CHECK(bignum.ToHexString(buffer, kBufferSize)); | 81 CHECK(bignum.ToHexString(buffer, kBufferSize)); |
82 CHECK_EQ("12345678", buffer); | 82 CHECK_EQ(0, strcmp("12345678", buffer)); |
83 | 83 |
84 uint64_t big = V8_2PART_UINT64_C(0xFFFFFFFF, FFFFFFFF); | 84 uint64_t big = V8_2PART_UINT64_C(0xFFFFFFFF, FFFFFFFF); |
85 bignum.AssignUInt64(big); | 85 bignum.AssignUInt64(big); |
86 CHECK(bignum.ToHexString(buffer, kBufferSize)); | 86 CHECK(bignum.ToHexString(buffer, kBufferSize)); |
87 CHECK_EQ("FFFFFFFFFFFFFFFF", buffer); | 87 CHECK_EQ(0, strcmp("FFFFFFFFFFFFFFFF", buffer)); |
88 | 88 |
89 big = V8_2PART_UINT64_C(0x12345678, 9ABCDEF0); | 89 big = V8_2PART_UINT64_C(0x12345678, 9ABCDEF0); |
90 bignum.AssignUInt64(big); | 90 bignum.AssignUInt64(big); |
91 CHECK(bignum.ToHexString(buffer, kBufferSize)); | 91 CHECK(bignum.ToHexString(buffer, kBufferSize)); |
92 CHECK_EQ("123456789ABCDEF0", buffer); | 92 CHECK_EQ(0, strcmp("123456789ABCDEF0", buffer)); |
93 | 93 |
94 bignum2.AssignBignum(bignum); | 94 bignum2.AssignBignum(bignum); |
95 CHECK(bignum2.ToHexString(buffer, kBufferSize)); | 95 CHECK(bignum2.ToHexString(buffer, kBufferSize)); |
96 CHECK_EQ("123456789ABCDEF0", buffer); | 96 CHECK_EQ(0, strcmp("123456789ABCDEF0", buffer)); |
97 | 97 |
98 AssignDecimalString(&bignum, "0"); | 98 AssignDecimalString(&bignum, "0"); |
99 CHECK(bignum.ToHexString(buffer, kBufferSize)); | 99 CHECK(bignum.ToHexString(buffer, kBufferSize)); |
100 CHECK_EQ("0", buffer); | 100 CHECK_EQ(0, strcmp("0", buffer)); |
101 | 101 |
102 AssignDecimalString(&bignum, "1"); | 102 AssignDecimalString(&bignum, "1"); |
103 CHECK(bignum.ToHexString(buffer, kBufferSize)); | 103 CHECK(bignum.ToHexString(buffer, kBufferSize)); |
104 CHECK_EQ("1", buffer); | 104 CHECK_EQ(0, strcmp("1", buffer)); |
105 | 105 |
106 AssignDecimalString(&bignum, "1234567890"); | 106 AssignDecimalString(&bignum, "1234567890"); |
107 CHECK(bignum.ToHexString(buffer, kBufferSize)); | 107 CHECK(bignum.ToHexString(buffer, kBufferSize)); |
108 CHECK_EQ("499602D2", buffer); | 108 CHECK_EQ(0, strcmp("499602D2", buffer)); |
109 | 109 |
110 AssignHexString(&bignum, "0"); | 110 AssignHexString(&bignum, "0"); |
111 CHECK(bignum.ToHexString(buffer, kBufferSize)); | 111 CHECK(bignum.ToHexString(buffer, kBufferSize)); |
112 CHECK_EQ("0", buffer); | 112 CHECK_EQ(0, strcmp("0", buffer)); |
113 | 113 |
114 AssignHexString(&bignum, "123456789ABCDEF0"); | 114 AssignHexString(&bignum, "123456789ABCDEF0"); |
115 CHECK(bignum.ToHexString(buffer, kBufferSize)); | 115 CHECK(bignum.ToHexString(buffer, kBufferSize)); |
116 CHECK_EQ("123456789ABCDEF0", buffer); | 116 CHECK_EQ(0, strcmp("123456789ABCDEF0", buffer)); |
117 } | 117 } |
118 | 118 |
119 | 119 |
120 TEST(ShiftLeft) { | 120 TEST(ShiftLeft) { |
121 char buffer[kBufferSize]; | 121 char buffer[kBufferSize]; |
122 Bignum bignum; | 122 Bignum bignum; |
123 AssignHexString(&bignum, "0"); | 123 AssignHexString(&bignum, "0"); |
124 bignum.ShiftLeft(100); | 124 bignum.ShiftLeft(100); |
125 CHECK(bignum.ToHexString(buffer, kBufferSize)); | 125 CHECK(bignum.ToHexString(buffer, kBufferSize)); |
126 CHECK_EQ("0", buffer); | 126 CHECK_EQ(0, strcmp("0", buffer)); |
127 | 127 |
128 AssignHexString(&bignum, "1"); | 128 AssignHexString(&bignum, "1"); |
129 bignum.ShiftLeft(1); | 129 bignum.ShiftLeft(1); |
130 CHECK(bignum.ToHexString(buffer, kBufferSize)); | 130 CHECK(bignum.ToHexString(buffer, kBufferSize)); |
131 CHECK_EQ("2", buffer); | 131 CHECK_EQ(0, strcmp("2", buffer)); |
132 | 132 |
133 AssignHexString(&bignum, "1"); | 133 AssignHexString(&bignum, "1"); |
134 bignum.ShiftLeft(4); | 134 bignum.ShiftLeft(4); |
135 CHECK(bignum.ToHexString(buffer, kBufferSize)); | 135 CHECK(bignum.ToHexString(buffer, kBufferSize)); |
136 CHECK_EQ("10", buffer); | 136 CHECK_EQ(0, strcmp("10", buffer)); |
137 | 137 |
138 AssignHexString(&bignum, "1"); | 138 AssignHexString(&bignum, "1"); |
139 bignum.ShiftLeft(32); | 139 bignum.ShiftLeft(32); |
140 CHECK(bignum.ToHexString(buffer, kBufferSize)); | 140 CHECK(bignum.ToHexString(buffer, kBufferSize)); |
141 CHECK_EQ("100000000", buffer); | 141 CHECK_EQ(0, strcmp("100000000", buffer)); |
142 | 142 |
143 AssignHexString(&bignum, "1"); | 143 AssignHexString(&bignum, "1"); |
144 bignum.ShiftLeft(64); | 144 bignum.ShiftLeft(64); |
145 CHECK(bignum.ToHexString(buffer, kBufferSize)); | 145 CHECK(bignum.ToHexString(buffer, kBufferSize)); |
146 CHECK_EQ("10000000000000000", buffer); | 146 CHECK_EQ(0, strcmp("10000000000000000", buffer)); |
147 | 147 |
148 AssignHexString(&bignum, "123456789ABCDEF"); | 148 AssignHexString(&bignum, "123456789ABCDEF"); |
149 bignum.ShiftLeft(64); | 149 bignum.ShiftLeft(64); |
150 CHECK(bignum.ToHexString(buffer, kBufferSize)); | 150 CHECK(bignum.ToHexString(buffer, kBufferSize)); |
151 CHECK_EQ("123456789ABCDEF0000000000000000", buffer); | 151 CHECK_EQ(0, strcmp("123456789ABCDEF0000000000000000", buffer)); |
152 bignum.ShiftLeft(1); | 152 bignum.ShiftLeft(1); |
153 CHECK(bignum.ToHexString(buffer, kBufferSize)); | 153 CHECK(bignum.ToHexString(buffer, kBufferSize)); |
154 CHECK_EQ("2468ACF13579BDE0000000000000000", buffer); | 154 CHECK_EQ(0, strcmp("2468ACF13579BDE0000000000000000", buffer)); |
155 } | 155 } |
156 | 156 |
157 | 157 |
158 TEST(AddUInt64) { | 158 TEST(AddUInt64) { |
159 char buffer[kBufferSize]; | 159 char buffer[kBufferSize]; |
160 Bignum bignum; | 160 Bignum bignum; |
161 AssignHexString(&bignum, "0"); | 161 AssignHexString(&bignum, "0"); |
162 bignum.AddUInt64(0xA); | 162 bignum.AddUInt64(0xA); |
163 CHECK(bignum.ToHexString(buffer, kBufferSize)); | 163 CHECK(bignum.ToHexString(buffer, kBufferSize)); |
164 CHECK_EQ("A", buffer); | 164 CHECK_EQ(0, strcmp("A", buffer)); |
165 | 165 |
166 AssignHexString(&bignum, "1"); | 166 AssignHexString(&bignum, "1"); |
167 bignum.AddUInt64(0xA); | 167 bignum.AddUInt64(0xA); |
168 CHECK(bignum.ToHexString(buffer, kBufferSize)); | 168 CHECK(bignum.ToHexString(buffer, kBufferSize)); |
169 CHECK_EQ("B", buffer); | 169 CHECK_EQ(0, strcmp("B", buffer)); |
170 | 170 |
171 AssignHexString(&bignum, "1"); | 171 AssignHexString(&bignum, "1"); |
172 bignum.AddUInt64(0x100); | 172 bignum.AddUInt64(0x100); |
173 CHECK(bignum.ToHexString(buffer, kBufferSize)); | 173 CHECK(bignum.ToHexString(buffer, kBufferSize)); |
174 CHECK_EQ("101", buffer); | 174 CHECK_EQ(0, strcmp("101", buffer)); |
175 | 175 |
176 AssignHexString(&bignum, "1"); | 176 AssignHexString(&bignum, "1"); |
177 bignum.AddUInt64(0xFFFF); | 177 bignum.AddUInt64(0xFFFF); |
178 CHECK(bignum.ToHexString(buffer, kBufferSize)); | 178 CHECK(bignum.ToHexString(buffer, kBufferSize)); |
179 CHECK_EQ("10000", buffer); | 179 CHECK_EQ(0, strcmp("10000", buffer)); |
180 | 180 |
181 AssignHexString(&bignum, "FFFFFFF"); | 181 AssignHexString(&bignum, "FFFFFFF"); |
182 bignum.AddUInt64(0x1); | 182 bignum.AddUInt64(0x1); |
183 CHECK(bignum.ToHexString(buffer, kBufferSize)); | 183 CHECK(bignum.ToHexString(buffer, kBufferSize)); |
184 CHECK_EQ("10000000", buffer); | 184 CHECK_EQ(0, strcmp("10000000", buffer)); |
185 | 185 |
186 AssignHexString(&bignum, "10000000000000000000000000000000000000000000"); | 186 AssignHexString(&bignum, "10000000000000000000000000000000000000000000"); |
187 bignum.AddUInt64(0xFFFF); | 187 bignum.AddUInt64(0xFFFF); |
188 CHECK(bignum.ToHexString(buffer, kBufferSize)); | 188 CHECK(bignum.ToHexString(buffer, kBufferSize)); |
189 CHECK_EQ("1000000000000000000000000000000000000000FFFF", buffer); | 189 CHECK_EQ(0, strcmp("1000000000000000000000000000000000000000FFFF", buffer)); |
190 | 190 |
191 AssignHexString(&bignum, "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF"); | 191 AssignHexString(&bignum, "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF"); |
192 bignum.AddUInt64(0x1); | 192 bignum.AddUInt64(0x1); |
193 CHECK(bignum.ToHexString(buffer, kBufferSize)); | 193 CHECK(bignum.ToHexString(buffer, kBufferSize)); |
194 CHECK_EQ("100000000000000000000000000000000000000000000", buffer); | 194 CHECK_EQ(0, strcmp("100000000000000000000000000000000000000000000", buffer)); |
195 | 195 |
196 bignum.AssignUInt16(0x1); | 196 bignum.AssignUInt16(0x1); |
197 bignum.ShiftLeft(100); | 197 bignum.ShiftLeft(100); |
198 bignum.AddUInt64(1); | 198 bignum.AddUInt64(1); |
199 CHECK(bignum.ToHexString(buffer, kBufferSize)); | 199 CHECK(bignum.ToHexString(buffer, kBufferSize)); |
200 CHECK_EQ("10000000000000000000000001", buffer); | 200 CHECK_EQ(0, strcmp("10000000000000000000000001", buffer)); |
201 | 201 |
202 bignum.AssignUInt16(0x1); | 202 bignum.AssignUInt16(0x1); |
203 bignum.ShiftLeft(100); | 203 bignum.ShiftLeft(100); |
204 bignum.AddUInt64(0xFFFF); | 204 bignum.AddUInt64(0xFFFF); |
205 CHECK(bignum.ToHexString(buffer, kBufferSize)); | 205 CHECK(bignum.ToHexString(buffer, kBufferSize)); |
206 CHECK_EQ("1000000000000000000000FFFF", buffer); | 206 CHECK_EQ(0, strcmp("1000000000000000000000FFFF", buffer)); |
207 | 207 |
208 AssignHexString(&bignum, "0"); | 208 AssignHexString(&bignum, "0"); |
209 bignum.AddUInt64(V8_2PART_UINT64_C(0xA, 00000000)); | 209 bignum.AddUInt64(V8_2PART_UINT64_C(0xA, 00000000)); |
210 CHECK(bignum.ToHexString(buffer, kBufferSize)); | 210 CHECK(bignum.ToHexString(buffer, kBufferSize)); |
211 CHECK_EQ("A00000000", buffer); | 211 CHECK_EQ(0, strcmp("A00000000", buffer)); |
212 | 212 |
213 AssignHexString(&bignum, "1"); | 213 AssignHexString(&bignum, "1"); |
214 bignum.AddUInt64(V8_2PART_UINT64_C(0xA, 00000000)); | 214 bignum.AddUInt64(V8_2PART_UINT64_C(0xA, 00000000)); |
215 CHECK(bignum.ToHexString(buffer, kBufferSize)); | 215 CHECK(bignum.ToHexString(buffer, kBufferSize)); |
216 CHECK_EQ("A00000001", buffer); | 216 CHECK_EQ(0, strcmp("A00000001", buffer)); |
217 | 217 |
218 AssignHexString(&bignum, "1"); | 218 AssignHexString(&bignum, "1"); |
219 bignum.AddUInt64(V8_2PART_UINT64_C(0x100, 00000000)); | 219 bignum.AddUInt64(V8_2PART_UINT64_C(0x100, 00000000)); |
220 CHECK(bignum.ToHexString(buffer, kBufferSize)); | 220 CHECK(bignum.ToHexString(buffer, kBufferSize)); |
221 CHECK_EQ("10000000001", buffer); | 221 CHECK_EQ(0, strcmp("10000000001", buffer)); |
222 | 222 |
223 AssignHexString(&bignum, "1"); | 223 AssignHexString(&bignum, "1"); |
224 bignum.AddUInt64(V8_2PART_UINT64_C(0xFFFF, 00000000)); | 224 bignum.AddUInt64(V8_2PART_UINT64_C(0xFFFF, 00000000)); |
225 CHECK(bignum.ToHexString(buffer, kBufferSize)); | 225 CHECK(bignum.ToHexString(buffer, kBufferSize)); |
226 CHECK_EQ("FFFF00000001", buffer); | 226 CHECK_EQ(0, strcmp("FFFF00000001", buffer)); |
227 | 227 |
228 AssignHexString(&bignum, "FFFFFFF"); | 228 AssignHexString(&bignum, "FFFFFFF"); |
229 bignum.AddUInt64(V8_2PART_UINT64_C(0x1, 00000000)); | 229 bignum.AddUInt64(V8_2PART_UINT64_C(0x1, 00000000)); |
230 CHECK(bignum.ToHexString(buffer, kBufferSize)); | 230 CHECK(bignum.ToHexString(buffer, kBufferSize)); |
231 CHECK_EQ("10FFFFFFF", buffer); | 231 CHECK_EQ(0, strcmp("10FFFFFFF", buffer)); |
232 | 232 |
233 AssignHexString(&bignum, "10000000000000000000000000000000000000000000"); | 233 AssignHexString(&bignum, "10000000000000000000000000000000000000000000"); |
234 bignum.AddUInt64(V8_2PART_UINT64_C(0xFFFF, 00000000)); | 234 bignum.AddUInt64(V8_2PART_UINT64_C(0xFFFF, 00000000)); |
235 CHECK(bignum.ToHexString(buffer, kBufferSize)); | 235 CHECK(bignum.ToHexString(buffer, kBufferSize)); |
236 CHECK_EQ("10000000000000000000000000000000FFFF00000000", buffer); | 236 CHECK_EQ(0, strcmp("10000000000000000000000000000000FFFF00000000", buffer)); |
237 | 237 |
238 AssignHexString(&bignum, "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF"); | 238 AssignHexString(&bignum, "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF"); |
239 bignum.AddUInt64(V8_2PART_UINT64_C(0x1, 00000000)); | 239 bignum.AddUInt64(V8_2PART_UINT64_C(0x1, 00000000)); |
240 CHECK(bignum.ToHexString(buffer, kBufferSize)); | 240 CHECK(bignum.ToHexString(buffer, kBufferSize)); |
241 CHECK_EQ("1000000000000000000000000000000000000FFFFFFFF", buffer); | 241 CHECK_EQ(0, strcmp("1000000000000000000000000000000000000FFFFFFFF", buffer)); |
242 | 242 |
243 bignum.AssignUInt16(0x1); | 243 bignum.AssignUInt16(0x1); |
244 bignum.ShiftLeft(100); | 244 bignum.ShiftLeft(100); |
245 bignum.AddUInt64(V8_2PART_UINT64_C(0x1, 00000000)); | 245 bignum.AddUInt64(V8_2PART_UINT64_C(0x1, 00000000)); |
246 CHECK(bignum.ToHexString(buffer, kBufferSize)); | 246 CHECK(bignum.ToHexString(buffer, kBufferSize)); |
247 CHECK_EQ("10000000000000000100000000", buffer); | 247 CHECK_EQ(0, strcmp("10000000000000000100000000", buffer)); |
248 | 248 |
249 bignum.AssignUInt16(0x1); | 249 bignum.AssignUInt16(0x1); |
250 bignum.ShiftLeft(100); | 250 bignum.ShiftLeft(100); |
251 bignum.AddUInt64(V8_2PART_UINT64_C(0xFFFF, 00000000)); | 251 bignum.AddUInt64(V8_2PART_UINT64_C(0xFFFF, 00000000)); |
252 CHECK(bignum.ToHexString(buffer, kBufferSize)); | 252 CHECK(bignum.ToHexString(buffer, kBufferSize)); |
253 CHECK_EQ("10000000000000FFFF00000000", buffer); | 253 CHECK_EQ(0, strcmp("10000000000000FFFF00000000", buffer)); |
254 } | 254 } |
255 | 255 |
256 | 256 |
257 TEST(AddBignum) { | 257 TEST(AddBignum) { |
258 char buffer[kBufferSize]; | 258 char buffer[kBufferSize]; |
259 Bignum bignum; | 259 Bignum bignum; |
260 Bignum other; | 260 Bignum other; |
261 | 261 |
262 AssignHexString(&other, "1"); | 262 AssignHexString(&other, "1"); |
263 AssignHexString(&bignum, "0"); | 263 AssignHexString(&bignum, "0"); |
264 bignum.AddBignum(other); | 264 bignum.AddBignum(other); |
265 CHECK(bignum.ToHexString(buffer, kBufferSize)); | 265 CHECK(bignum.ToHexString(buffer, kBufferSize)); |
266 CHECK_EQ("1", buffer); | 266 CHECK_EQ(0, strcmp("1", buffer)); |
267 | 267 |
268 AssignHexString(&bignum, "1"); | 268 AssignHexString(&bignum, "1"); |
269 bignum.AddBignum(other); | 269 bignum.AddBignum(other); |
270 CHECK(bignum.ToHexString(buffer, kBufferSize)); | 270 CHECK(bignum.ToHexString(buffer, kBufferSize)); |
271 CHECK_EQ("2", buffer); | 271 CHECK_EQ(0, strcmp("2", buffer)); |
272 | 272 |
273 AssignHexString(&bignum, "FFFFFFF"); | 273 AssignHexString(&bignum, "FFFFFFF"); |
274 bignum.AddBignum(other); | 274 bignum.AddBignum(other); |
275 CHECK(bignum.ToHexString(buffer, kBufferSize)); | 275 CHECK(bignum.ToHexString(buffer, kBufferSize)); |
276 CHECK_EQ("10000000", buffer); | 276 CHECK_EQ(0, strcmp("10000000", buffer)); |
277 | 277 |
278 AssignHexString(&bignum, "FFFFFFFFFFFFFF"); | 278 AssignHexString(&bignum, "FFFFFFFFFFFFFF"); |
279 bignum.AddBignum(other); | 279 bignum.AddBignum(other); |
280 CHECK(bignum.ToHexString(buffer, kBufferSize)); | 280 CHECK(bignum.ToHexString(buffer, kBufferSize)); |
281 CHECK_EQ("100000000000000", buffer); | 281 CHECK_EQ(0, strcmp("100000000000000", buffer)); |
282 | 282 |
283 AssignHexString(&bignum, "10000000000000000000000000000000000000000000"); | 283 AssignHexString(&bignum, "10000000000000000000000000000000000000000000"); |
284 bignum.AddBignum(other); | 284 bignum.AddBignum(other); |
285 CHECK(bignum.ToHexString(buffer, kBufferSize)); | 285 CHECK(bignum.ToHexString(buffer, kBufferSize)); |
286 CHECK_EQ("10000000000000000000000000000000000000000001", buffer); | 286 CHECK_EQ(0, strcmp("10000000000000000000000000000000000000000001", buffer)); |
287 | 287 |
288 AssignHexString(&other, "1000000000000"); | 288 AssignHexString(&other, "1000000000000"); |
289 | 289 |
290 AssignHexString(&bignum, "1"); | 290 AssignHexString(&bignum, "1"); |
291 bignum.AddBignum(other); | 291 bignum.AddBignum(other); |
292 CHECK(bignum.ToHexString(buffer, kBufferSize)); | 292 CHECK(bignum.ToHexString(buffer, kBufferSize)); |
293 CHECK_EQ("1000000000001", buffer); | 293 CHECK_EQ(0, strcmp("1000000000001", buffer)); |
294 | 294 |
295 AssignHexString(&bignum, "FFFFFFF"); | 295 AssignHexString(&bignum, "FFFFFFF"); |
296 bignum.AddBignum(other); | 296 bignum.AddBignum(other); |
297 CHECK(bignum.ToHexString(buffer, kBufferSize)); | 297 CHECK(bignum.ToHexString(buffer, kBufferSize)); |
298 CHECK_EQ("100000FFFFFFF", buffer); | 298 CHECK_EQ(0, strcmp("100000FFFFFFF", buffer)); |
299 | 299 |
300 AssignHexString(&bignum, "10000000000000000000000000000000000000000000"); | 300 AssignHexString(&bignum, "10000000000000000000000000000000000000000000"); |
301 bignum.AddBignum(other); | 301 bignum.AddBignum(other); |
302 CHECK(bignum.ToHexString(buffer, kBufferSize)); | 302 CHECK(bignum.ToHexString(buffer, kBufferSize)); |
303 CHECK_EQ("10000000000000000000000000000001000000000000", buffer); | 303 CHECK_EQ(0, strcmp("10000000000000000000000000000001000000000000", buffer)); |
304 | 304 |
305 AssignHexString(&bignum, "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF"); | 305 AssignHexString(&bignum, "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF"); |
306 bignum.AddBignum(other); | 306 bignum.AddBignum(other); |
307 CHECK(bignum.ToHexString(buffer, kBufferSize)); | 307 CHECK(bignum.ToHexString(buffer, kBufferSize)); |
308 CHECK_EQ("1000000000000000000000000000000FFFFFFFFFFFF", buffer); | 308 CHECK_EQ(0, strcmp("1000000000000000000000000000000FFFFFFFFFFFF", buffer)); |
309 | 309 |
310 bignum.AssignUInt16(0x1); | 310 bignum.AssignUInt16(0x1); |
311 bignum.ShiftLeft(100); | 311 bignum.ShiftLeft(100); |
312 bignum.AddBignum(other); | 312 bignum.AddBignum(other); |
313 CHECK(bignum.ToHexString(buffer, kBufferSize)); | 313 CHECK(bignum.ToHexString(buffer, kBufferSize)); |
314 CHECK_EQ("10000000000001000000000000", buffer); | 314 CHECK_EQ(0, strcmp("10000000000001000000000000", buffer)); |
315 | 315 |
316 other.ShiftLeft(64); | 316 other.ShiftLeft(64); |
317 // other == "10000000000000000000000000000" | 317 // other == "10000000000000000000000000000" |
318 | 318 |
319 bignum.AssignUInt16(0x1); | 319 bignum.AssignUInt16(0x1); |
320 bignum.AddBignum(other); | 320 bignum.AddBignum(other); |
321 CHECK(bignum.ToHexString(buffer, kBufferSize)); | 321 CHECK(bignum.ToHexString(buffer, kBufferSize)); |
322 CHECK_EQ("10000000000000000000000000001", buffer); | 322 CHECK_EQ(0, strcmp("10000000000000000000000000001", buffer)); |
323 | 323 |
324 AssignHexString(&bignum, "FFFFFFF"); | 324 AssignHexString(&bignum, "FFFFFFF"); |
325 bignum.AddBignum(other); | 325 bignum.AddBignum(other); |
326 CHECK(bignum.ToHexString(buffer, kBufferSize)); | 326 CHECK(bignum.ToHexString(buffer, kBufferSize)); |
327 CHECK_EQ("1000000000000000000000FFFFFFF", buffer); | 327 CHECK_EQ(0, strcmp("1000000000000000000000FFFFFFF", buffer)); |
328 | 328 |
329 AssignHexString(&bignum, "10000000000000000000000000000000000000000000"); | 329 AssignHexString(&bignum, "10000000000000000000000000000000000000000000"); |
330 bignum.AddBignum(other); | 330 bignum.AddBignum(other); |
331 CHECK(bignum.ToHexString(buffer, kBufferSize)); | 331 CHECK(bignum.ToHexString(buffer, kBufferSize)); |
332 CHECK_EQ("10000000000000010000000000000000000000000000", buffer); | 332 CHECK_EQ(0, strcmp("10000000000000010000000000000000000000000000", buffer)); |
333 | 333 |
334 AssignHexString(&bignum, "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF"); | 334 AssignHexString(&bignum, "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF"); |
335 bignum.AddBignum(other); | 335 bignum.AddBignum(other); |
336 CHECK(bignum.ToHexString(buffer, kBufferSize)); | 336 CHECK(bignum.ToHexString(buffer, kBufferSize)); |
337 CHECK_EQ("100000000000000FFFFFFFFFFFFFFFFFFFFFFFFFFFF", buffer); | 337 CHECK_EQ(0, strcmp("100000000000000FFFFFFFFFFFFFFFFFFFFFFFFFFFF", buffer)); |
338 | 338 |
339 bignum.AssignUInt16(0x1); | 339 bignum.AssignUInt16(0x1); |
340 bignum.ShiftLeft(100); | 340 bignum.ShiftLeft(100); |
341 bignum.AddBignum(other); | 341 bignum.AddBignum(other); |
342 CHECK(bignum.ToHexString(buffer, kBufferSize)); | 342 CHECK(bignum.ToHexString(buffer, kBufferSize)); |
343 CHECK_EQ("10010000000000000000000000000", buffer); | 343 CHECK_EQ(0, strcmp("10010000000000000000000000000", buffer)); |
344 } | 344 } |
345 | 345 |
346 | 346 |
347 TEST(SubtractBignum) { | 347 TEST(SubtractBignum) { |
348 char buffer[kBufferSize]; | 348 char buffer[kBufferSize]; |
349 Bignum bignum; | 349 Bignum bignum; |
350 Bignum other; | 350 Bignum other; |
351 | 351 |
352 AssignHexString(&bignum, "1"); | 352 AssignHexString(&bignum, "1"); |
353 AssignHexString(&other, "0"); | 353 AssignHexString(&other, "0"); |
354 bignum.SubtractBignum(other); | 354 bignum.SubtractBignum(other); |
355 CHECK(bignum.ToHexString(buffer, kBufferSize)); | 355 CHECK(bignum.ToHexString(buffer, kBufferSize)); |
356 CHECK_EQ("1", buffer); | 356 CHECK_EQ(0, strcmp("1", buffer)); |
357 | 357 |
358 AssignHexString(&bignum, "2"); | 358 AssignHexString(&bignum, "2"); |
359 AssignHexString(&other, "0"); | 359 AssignHexString(&other, "0"); |
360 bignum.SubtractBignum(other); | 360 bignum.SubtractBignum(other); |
361 CHECK(bignum.ToHexString(buffer, kBufferSize)); | 361 CHECK(bignum.ToHexString(buffer, kBufferSize)); |
362 CHECK_EQ("2", buffer); | 362 CHECK_EQ(0, strcmp("2", buffer)); |
363 | 363 |
364 AssignHexString(&bignum, "10000000"); | 364 AssignHexString(&bignum, "10000000"); |
365 AssignHexString(&other, "1"); | 365 AssignHexString(&other, "1"); |
366 bignum.SubtractBignum(other); | 366 bignum.SubtractBignum(other); |
367 CHECK(bignum.ToHexString(buffer, kBufferSize)); | 367 CHECK(bignum.ToHexString(buffer, kBufferSize)); |
368 CHECK_EQ("FFFFFFF", buffer); | 368 CHECK_EQ(0, strcmp("FFFFFFF", buffer)); |
369 | 369 |
370 AssignHexString(&bignum, "100000000000000"); | 370 AssignHexString(&bignum, "100000000000000"); |
371 AssignHexString(&other, "1"); | 371 AssignHexString(&other, "1"); |
372 bignum.SubtractBignum(other); | 372 bignum.SubtractBignum(other); |
373 CHECK(bignum.ToHexString(buffer, kBufferSize)); | 373 CHECK(bignum.ToHexString(buffer, kBufferSize)); |
374 CHECK_EQ("FFFFFFFFFFFFFF", buffer); | 374 CHECK_EQ(0, strcmp("FFFFFFFFFFFFFF", buffer)); |
375 | 375 |
376 AssignHexString(&bignum, "10000000000000000000000000000000000000000001"); | 376 AssignHexString(&bignum, "10000000000000000000000000000000000000000001"); |
377 AssignHexString(&other, "1"); | 377 AssignHexString(&other, "1"); |
378 bignum.SubtractBignum(other); | 378 bignum.SubtractBignum(other); |
379 CHECK(bignum.ToHexString(buffer, kBufferSize)); | 379 CHECK(bignum.ToHexString(buffer, kBufferSize)); |
380 CHECK_EQ("10000000000000000000000000000000000000000000", buffer); | 380 CHECK_EQ(0, strcmp("10000000000000000000000000000000000000000000", buffer)); |
381 | 381 |
382 AssignHexString(&bignum, "1000000000001"); | 382 AssignHexString(&bignum, "1000000000001"); |
383 AssignHexString(&other, "1000000000000"); | 383 AssignHexString(&other, "1000000000000"); |
384 bignum.SubtractBignum(other); | 384 bignum.SubtractBignum(other); |
385 CHECK(bignum.ToHexString(buffer, kBufferSize)); | 385 CHECK(bignum.ToHexString(buffer, kBufferSize)); |
386 CHECK_EQ("1", buffer); | 386 CHECK_EQ(0, strcmp("1", buffer)); |
387 | 387 |
388 AssignHexString(&bignum, "100000FFFFFFF"); | 388 AssignHexString(&bignum, "100000FFFFFFF"); |
389 AssignHexString(&other, "1000000000000"); | 389 AssignHexString(&other, "1000000000000"); |
390 bignum.SubtractBignum(other); | 390 bignum.SubtractBignum(other); |
391 CHECK(bignum.ToHexString(buffer, kBufferSize)); | 391 CHECK(bignum.ToHexString(buffer, kBufferSize)); |
392 CHECK_EQ("FFFFFFF", buffer); | 392 CHECK_EQ(0, strcmp("FFFFFFF", buffer)); |
393 | 393 |
394 AssignHexString(&bignum, "10000000000000000000000000000001000000000000"); | 394 AssignHexString(&bignum, "10000000000000000000000000000001000000000000"); |
395 AssignHexString(&other, "1000000000000"); | 395 AssignHexString(&other, "1000000000000"); |
396 bignum.SubtractBignum(other); | 396 bignum.SubtractBignum(other); |
397 CHECK(bignum.ToHexString(buffer, kBufferSize)); | 397 CHECK(bignum.ToHexString(buffer, kBufferSize)); |
398 CHECK_EQ("10000000000000000000000000000000000000000000", buffer); | 398 CHECK_EQ(0, strcmp("10000000000000000000000000000000000000000000", buffer)); |
399 | 399 |
400 AssignHexString(&bignum, "1000000000000000000000000000000FFFFFFFFFFFF"); | 400 AssignHexString(&bignum, "1000000000000000000000000000000FFFFFFFFFFFF"); |
401 AssignHexString(&other, "1000000000000"); | 401 AssignHexString(&other, "1000000000000"); |
402 bignum.SubtractBignum(other); | 402 bignum.SubtractBignum(other); |
403 CHECK(bignum.ToHexString(buffer, kBufferSize)); | 403 CHECK(bignum.ToHexString(buffer, kBufferSize)); |
404 CHECK_EQ("FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF", buffer); | 404 CHECK_EQ(0, strcmp("FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF", buffer)); |
405 | 405 |
406 bignum.AssignUInt16(0x1); | 406 bignum.AssignUInt16(0x1); |
407 bignum.ShiftLeft(100); | 407 bignum.ShiftLeft(100); |
408 // "10 0000 0000 0000 0000 0000 0000" | 408 // "10 0000 0000 0000 0000 0000 0000" |
409 AssignHexString(&other, "1000000000000"); | 409 AssignHexString(&other, "1000000000000"); |
410 bignum.SubtractBignum(other); | 410 bignum.SubtractBignum(other); |
411 CHECK(bignum.ToHexString(buffer, kBufferSize)); | 411 CHECK(bignum.ToHexString(buffer, kBufferSize)); |
412 CHECK_EQ("FFFFFFFFFFFFF000000000000", buffer); | 412 CHECK_EQ(0, strcmp("FFFFFFFFFFFFF000000000000", buffer)); |
413 | 413 |
414 AssignHexString(&other, "1000000000000"); | 414 AssignHexString(&other, "1000000000000"); |
415 other.ShiftLeft(48); | 415 other.ShiftLeft(48); |
416 // other == "1000000000000000000000000" | 416 // other == "1000000000000000000000000" |
417 | 417 |
418 bignum.AssignUInt16(0x1); | 418 bignum.AssignUInt16(0x1); |
419 bignum.ShiftLeft(100); | 419 bignum.ShiftLeft(100); |
420 // bignum == "10000000000000000000000000" | 420 // bignum == "10000000000000000000000000" |
421 bignum.SubtractBignum(other); | 421 bignum.SubtractBignum(other); |
422 CHECK(bignum.ToHexString(buffer, kBufferSize)); | 422 CHECK(bignum.ToHexString(buffer, kBufferSize)); |
423 CHECK_EQ("F000000000000000000000000", buffer); | 423 CHECK_EQ(0, strcmp("F000000000000000000000000", buffer)); |
424 | 424 |
425 other.AssignUInt16(0x1); | 425 other.AssignUInt16(0x1); |
426 other.ShiftLeft(35); | 426 other.ShiftLeft(35); |
427 // other == "800000000" | 427 // other == "800000000" |
428 AssignHexString(&bignum, "FFFFFFF"); | 428 AssignHexString(&bignum, "FFFFFFF"); |
429 bignum.ShiftLeft(60); | 429 bignum.ShiftLeft(60); |
430 // bignum = FFFFFFF000000000000000 | 430 // bignum = FFFFFFF000000000000000 |
431 bignum.SubtractBignum(other); | 431 bignum.SubtractBignum(other); |
432 CHECK(bignum.ToHexString(buffer, kBufferSize)); | 432 CHECK(bignum.ToHexString(buffer, kBufferSize)); |
433 CHECK_EQ("FFFFFFEFFFFFF800000000", buffer); | 433 CHECK_EQ(0, strcmp("FFFFFFEFFFFFF800000000", buffer)); |
434 | 434 |
435 AssignHexString(&bignum, "10000000000000000000000000000000000000000000"); | 435 AssignHexString(&bignum, "10000000000000000000000000000000000000000000"); |
436 bignum.SubtractBignum(other); | 436 bignum.SubtractBignum(other); |
437 CHECK(bignum.ToHexString(buffer, kBufferSize)); | 437 CHECK(bignum.ToHexString(buffer, kBufferSize)); |
438 CHECK_EQ("FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF800000000", buffer); | 438 CHECK_EQ(0, strcmp("FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF800000000", buffer)); |
439 | 439 |
440 AssignHexString(&bignum, "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF"); | 440 AssignHexString(&bignum, "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF"); |
441 bignum.SubtractBignum(other); | 441 bignum.SubtractBignum(other); |
442 CHECK(bignum.ToHexString(buffer, kBufferSize)); | 442 CHECK(bignum.ToHexString(buffer, kBufferSize)); |
443 CHECK_EQ("FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF7FFFFFFFF", buffer); | 443 CHECK_EQ(0, strcmp("FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF7FFFFFFFF", buffer)); |
444 } | 444 } |
445 | 445 |
446 | 446 |
447 TEST(MultiplyUInt32) { | 447 TEST(MultiplyUInt32) { |
448 char buffer[kBufferSize]; | 448 char buffer[kBufferSize]; |
449 Bignum bignum; | 449 Bignum bignum; |
450 | 450 |
451 AssignHexString(&bignum, "0"); | 451 AssignHexString(&bignum, "0"); |
452 bignum.MultiplyByUInt32(0x25); | 452 bignum.MultiplyByUInt32(0x25); |
453 CHECK(bignum.ToHexString(buffer, kBufferSize)); | 453 CHECK(bignum.ToHexString(buffer, kBufferSize)); |
454 CHECK_EQ("0", buffer); | 454 CHECK_EQ(0, strcmp("0", buffer)); |
455 | 455 |
456 AssignHexString(&bignum, "2"); | 456 AssignHexString(&bignum, "2"); |
457 bignum.MultiplyByUInt32(0x5); | 457 bignum.MultiplyByUInt32(0x5); |
458 CHECK(bignum.ToHexString(buffer, kBufferSize)); | 458 CHECK(bignum.ToHexString(buffer, kBufferSize)); |
459 CHECK_EQ("A", buffer); | 459 CHECK_EQ(0, strcmp("A", buffer)); |
460 | 460 |
461 AssignHexString(&bignum, "10000000"); | 461 AssignHexString(&bignum, "10000000"); |
462 bignum.MultiplyByUInt32(0x9); | 462 bignum.MultiplyByUInt32(0x9); |
463 CHECK(bignum.ToHexString(buffer, kBufferSize)); | 463 CHECK(bignum.ToHexString(buffer, kBufferSize)); |
464 CHECK_EQ("90000000", buffer); | 464 CHECK_EQ(0, strcmp("90000000", buffer)); |
465 | 465 |
466 AssignHexString(&bignum, "100000000000000"); | 466 AssignHexString(&bignum, "100000000000000"); |
467 bignum.MultiplyByUInt32(0xFFFF); | 467 bignum.MultiplyByUInt32(0xFFFF); |
468 CHECK(bignum.ToHexString(buffer, kBufferSize)); | 468 CHECK(bignum.ToHexString(buffer, kBufferSize)); |
469 CHECK_EQ("FFFF00000000000000", buffer); | 469 CHECK_EQ(0, strcmp("FFFF00000000000000", buffer)); |
470 | 470 |
471 AssignHexString(&bignum, "100000000000000"); | 471 AssignHexString(&bignum, "100000000000000"); |
472 bignum.MultiplyByUInt32(0xFFFFFFFF); | 472 bignum.MultiplyByUInt32(0xFFFFFFFF); |
473 CHECK(bignum.ToHexString(buffer, kBufferSize)); | 473 CHECK(bignum.ToHexString(buffer, kBufferSize)); |
474 CHECK_EQ("FFFFFFFF00000000000000", buffer); | 474 CHECK_EQ(0, strcmp("FFFFFFFF00000000000000", buffer)); |
475 | 475 |
476 AssignHexString(&bignum, "1234567ABCD"); | 476 AssignHexString(&bignum, "1234567ABCD"); |
477 bignum.MultiplyByUInt32(0xFFF); | 477 bignum.MultiplyByUInt32(0xFFF); |
478 CHECK(bignum.ToHexString(buffer, kBufferSize)); | 478 CHECK(bignum.ToHexString(buffer, kBufferSize)); |
479 CHECK_EQ("12333335552433", buffer); | 479 CHECK_EQ(0, strcmp("12333335552433", buffer)); |
480 | 480 |
481 AssignHexString(&bignum, "1234567ABCD"); | 481 AssignHexString(&bignum, "1234567ABCD"); |
482 bignum.MultiplyByUInt32(0xFFFFFFF); | 482 bignum.MultiplyByUInt32(0xFFFFFFF); |
483 CHECK(bignum.ToHexString(buffer, kBufferSize)); | 483 CHECK(bignum.ToHexString(buffer, kBufferSize)); |
484 CHECK_EQ("12345679998A985433", buffer); | 484 CHECK_EQ(0, strcmp("12345679998A985433", buffer)); |
485 | 485 |
486 AssignHexString(&bignum, "FFFFFFFFFFFFFFFF"); | 486 AssignHexString(&bignum, "FFFFFFFFFFFFFFFF"); |
487 bignum.MultiplyByUInt32(0x2); | 487 bignum.MultiplyByUInt32(0x2); |
488 CHECK(bignum.ToHexString(buffer, kBufferSize)); | 488 CHECK(bignum.ToHexString(buffer, kBufferSize)); |
489 CHECK_EQ("1FFFFFFFFFFFFFFFE", buffer); | 489 CHECK_EQ(0, strcmp("1FFFFFFFFFFFFFFFE", buffer)); |
490 | 490 |
491 AssignHexString(&bignum, "FFFFFFFFFFFFFFFF"); | 491 AssignHexString(&bignum, "FFFFFFFFFFFFFFFF"); |
492 bignum.MultiplyByUInt32(0x4); | 492 bignum.MultiplyByUInt32(0x4); |
493 CHECK(bignum.ToHexString(buffer, kBufferSize)); | 493 CHECK(bignum.ToHexString(buffer, kBufferSize)); |
494 CHECK_EQ("3FFFFFFFFFFFFFFFC", buffer); | 494 CHECK_EQ(0, strcmp("3FFFFFFFFFFFFFFFC", buffer)); |
495 | 495 |
496 AssignHexString(&bignum, "FFFFFFFFFFFFFFFF"); | 496 AssignHexString(&bignum, "FFFFFFFFFFFFFFFF"); |
497 bignum.MultiplyByUInt32(0xF); | 497 bignum.MultiplyByUInt32(0xF); |
498 CHECK(bignum.ToHexString(buffer, kBufferSize)); | 498 CHECK(bignum.ToHexString(buffer, kBufferSize)); |
499 CHECK_EQ("EFFFFFFFFFFFFFFF1", buffer); | 499 CHECK_EQ(0, strcmp("EFFFFFFFFFFFFFFF1", buffer)); |
500 | 500 |
501 AssignHexString(&bignum, "FFFFFFFFFFFFFFFF"); | 501 AssignHexString(&bignum, "FFFFFFFFFFFFFFFF"); |
502 bignum.MultiplyByUInt32(0xFFFFFF); | 502 bignum.MultiplyByUInt32(0xFFFFFF); |
503 CHECK(bignum.ToHexString(buffer, kBufferSize)); | 503 CHECK(bignum.ToHexString(buffer, kBufferSize)); |
504 CHECK_EQ("FFFFFEFFFFFFFFFF000001", buffer); | 504 CHECK_EQ(0, strcmp("FFFFFEFFFFFFFFFF000001", buffer)); |
505 | 505 |
506 bignum.AssignUInt16(0x1); | 506 bignum.AssignUInt16(0x1); |
507 bignum.ShiftLeft(100); | 507 bignum.ShiftLeft(100); |
508 // "10 0000 0000 0000 0000 0000 0000" | 508 // "10 0000 0000 0000 0000 0000 0000" |
509 bignum.MultiplyByUInt32(2); | 509 bignum.MultiplyByUInt32(2); |
510 CHECK(bignum.ToHexString(buffer, kBufferSize)); | 510 CHECK(bignum.ToHexString(buffer, kBufferSize)); |
511 CHECK_EQ("20000000000000000000000000", buffer); | 511 CHECK_EQ(0, strcmp("20000000000000000000000000", buffer)); |
512 | 512 |
513 bignum.AssignUInt16(0x1); | 513 bignum.AssignUInt16(0x1); |
514 bignum.ShiftLeft(100); | 514 bignum.ShiftLeft(100); |
515 // "10 0000 0000 0000 0000 0000 0000" | 515 // "10 0000 0000 0000 0000 0000 0000" |
516 bignum.MultiplyByUInt32(0xF); | 516 bignum.MultiplyByUInt32(0xF); |
517 CHECK(bignum.ToHexString(buffer, kBufferSize)); | 517 CHECK(bignum.ToHexString(buffer, kBufferSize)); |
518 CHECK_EQ("F0000000000000000000000000", buffer); | 518 CHECK_EQ(0, strcmp("F0000000000000000000000000", buffer)); |
519 | 519 |
520 bignum.AssignUInt16(0xFFFF); | 520 bignum.AssignUInt16(0xFFFF); |
521 bignum.ShiftLeft(100); | 521 bignum.ShiftLeft(100); |
522 // "FFFF0 0000 0000 0000 0000 0000 0000" | 522 // "FFFF0 0000 0000 0000 0000 0000 0000" |
523 bignum.MultiplyByUInt32(0xFFFF); | 523 bignum.MultiplyByUInt32(0xFFFF); |
524 CHECK(bignum.ToHexString(buffer, kBufferSize)); | 524 CHECK(bignum.ToHexString(buffer, kBufferSize)); |
525 CHECK_EQ("FFFE00010000000000000000000000000", buffer); | 525 CHECK_EQ(0, strcmp("FFFE00010000000000000000000000000", buffer)); |
526 | 526 |
527 bignum.AssignUInt16(0xFFFF); | 527 bignum.AssignUInt16(0xFFFF); |
528 bignum.ShiftLeft(100); | 528 bignum.ShiftLeft(100); |
529 // "FFFF0 0000 0000 0000 0000 0000 0000" | 529 // "FFFF0 0000 0000 0000 0000 0000 0000" |
530 bignum.MultiplyByUInt32(0xFFFFFFFF); | 530 bignum.MultiplyByUInt32(0xFFFFFFFF); |
531 CHECK(bignum.ToHexString(buffer, kBufferSize)); | 531 CHECK(bignum.ToHexString(buffer, kBufferSize)); |
532 CHECK_EQ("FFFEFFFF00010000000000000000000000000", buffer); | 532 CHECK_EQ(0, strcmp("FFFEFFFF00010000000000000000000000000", buffer)); |
533 | 533 |
534 bignum.AssignUInt16(0xFFFF); | 534 bignum.AssignUInt16(0xFFFF); |
535 bignum.ShiftLeft(100); | 535 bignum.ShiftLeft(100); |
536 // "FFFF0 0000 0000 0000 0000 0000 0000" | 536 // "FFFF0 0000 0000 0000 0000 0000 0000" |
537 bignum.MultiplyByUInt32(0xFFFFFFFF); | 537 bignum.MultiplyByUInt32(0xFFFFFFFF); |
538 CHECK(bignum.ToHexString(buffer, kBufferSize)); | 538 CHECK(bignum.ToHexString(buffer, kBufferSize)); |
539 CHECK_EQ("FFFEFFFF00010000000000000000000000000", buffer); | 539 CHECK_EQ(0, strcmp("FFFEFFFF00010000000000000000000000000", buffer)); |
540 | 540 |
541 AssignDecimalString(&bignum, "15611230384529777"); | 541 AssignDecimalString(&bignum, "15611230384529777"); |
542 bignum.MultiplyByUInt32(10000000); | 542 bignum.MultiplyByUInt32(10000000); |
543 CHECK(bignum.ToHexString(buffer, kBufferSize)); | 543 CHECK(bignum.ToHexString(buffer, kBufferSize)); |
544 CHECK_EQ("210EDD6D4CDD2580EE80", buffer); | 544 CHECK_EQ(0, strcmp("210EDD6D4CDD2580EE80", buffer)); |
545 } | 545 } |
546 | 546 |
547 | 547 |
548 TEST(MultiplyUInt64) { | 548 TEST(MultiplyUInt64) { |
549 char buffer[kBufferSize]; | 549 char buffer[kBufferSize]; |
550 Bignum bignum; | 550 Bignum bignum; |
551 | 551 |
552 AssignHexString(&bignum, "0"); | 552 AssignHexString(&bignum, "0"); |
553 bignum.MultiplyByUInt64(0x25); | 553 bignum.MultiplyByUInt64(0x25); |
554 CHECK(bignum.ToHexString(buffer, kBufferSize)); | 554 CHECK(bignum.ToHexString(buffer, kBufferSize)); |
555 CHECK_EQ("0", buffer); | 555 CHECK_EQ(0, strcmp("0", buffer)); |
556 | 556 |
557 AssignHexString(&bignum, "2"); | 557 AssignHexString(&bignum, "2"); |
558 bignum.MultiplyByUInt64(0x5); | 558 bignum.MultiplyByUInt64(0x5); |
559 CHECK(bignum.ToHexString(buffer, kBufferSize)); | 559 CHECK(bignum.ToHexString(buffer, kBufferSize)); |
560 CHECK_EQ("A", buffer); | 560 CHECK_EQ(0, strcmp("A", buffer)); |
561 | 561 |
562 AssignHexString(&bignum, "10000000"); | 562 AssignHexString(&bignum, "10000000"); |
563 bignum.MultiplyByUInt64(0x9); | 563 bignum.MultiplyByUInt64(0x9); |
564 CHECK(bignum.ToHexString(buffer, kBufferSize)); | 564 CHECK(bignum.ToHexString(buffer, kBufferSize)); |
565 CHECK_EQ("90000000", buffer); | 565 CHECK_EQ(0, strcmp("90000000", buffer)); |
566 | 566 |
567 AssignHexString(&bignum, "100000000000000"); | 567 AssignHexString(&bignum, "100000000000000"); |
568 bignum.MultiplyByUInt64(0xFFFF); | 568 bignum.MultiplyByUInt64(0xFFFF); |
569 CHECK(bignum.ToHexString(buffer, kBufferSize)); | 569 CHECK(bignum.ToHexString(buffer, kBufferSize)); |
570 CHECK_EQ("FFFF00000000000000", buffer); | 570 CHECK_EQ(0, strcmp("FFFF00000000000000", buffer)); |
571 | 571 |
572 AssignHexString(&bignum, "100000000000000"); | 572 AssignHexString(&bignum, "100000000000000"); |
573 bignum.MultiplyByUInt64(V8_2PART_UINT64_C(0xFFFFFFFF, FFFFFFFF)); | 573 bignum.MultiplyByUInt64(V8_2PART_UINT64_C(0xFFFFFFFF, FFFFFFFF)); |
574 CHECK(bignum.ToHexString(buffer, kBufferSize)); | 574 CHECK(bignum.ToHexString(buffer, kBufferSize)); |
575 CHECK_EQ("FFFFFFFFFFFFFFFF00000000000000", buffer); | 575 CHECK_EQ(0, strcmp("FFFFFFFFFFFFFFFF00000000000000", buffer)); |
576 | 576 |
577 AssignHexString(&bignum, "1234567ABCD"); | 577 AssignHexString(&bignum, "1234567ABCD"); |
578 bignum.MultiplyByUInt64(0xFFF); | 578 bignum.MultiplyByUInt64(0xFFF); |
579 CHECK(bignum.ToHexString(buffer, kBufferSize)); | 579 CHECK(bignum.ToHexString(buffer, kBufferSize)); |
580 CHECK_EQ("12333335552433", buffer); | 580 CHECK_EQ(0, strcmp("12333335552433", buffer)); |
581 | 581 |
582 AssignHexString(&bignum, "1234567ABCD"); | 582 AssignHexString(&bignum, "1234567ABCD"); |
583 bignum.MultiplyByUInt64(V8_2PART_UINT64_C(0xFF, FFFFFFFF)); | 583 bignum.MultiplyByUInt64(V8_2PART_UINT64_C(0xFF, FFFFFFFF)); |
584 CHECK(bignum.ToHexString(buffer, kBufferSize)); | 584 CHECK(bignum.ToHexString(buffer, kBufferSize)); |
585 CHECK_EQ("1234567ABCBDCBA985433", buffer); | 585 CHECK_EQ(0, strcmp("1234567ABCBDCBA985433", buffer)); |
586 | 586 |
587 AssignHexString(&bignum, "FFFFFFFFFFFFFFFF"); | 587 AssignHexString(&bignum, "FFFFFFFFFFFFFFFF"); |
588 bignum.MultiplyByUInt64(0x2); | 588 bignum.MultiplyByUInt64(0x2); |
589 CHECK(bignum.ToHexString(buffer, kBufferSize)); | 589 CHECK(bignum.ToHexString(buffer, kBufferSize)); |
590 CHECK_EQ("1FFFFFFFFFFFFFFFE", buffer); | 590 CHECK_EQ(0, strcmp("1FFFFFFFFFFFFFFFE", buffer)); |
591 | 591 |
592 AssignHexString(&bignum, "FFFFFFFFFFFFFFFF"); | 592 AssignHexString(&bignum, "FFFFFFFFFFFFFFFF"); |
593 bignum.MultiplyByUInt64(0x4); | 593 bignum.MultiplyByUInt64(0x4); |
594 CHECK(bignum.ToHexString(buffer, kBufferSize)); | 594 CHECK(bignum.ToHexString(buffer, kBufferSize)); |
595 CHECK_EQ("3FFFFFFFFFFFFFFFC", buffer); | 595 CHECK_EQ(0, strcmp("3FFFFFFFFFFFFFFFC", buffer)); |
596 | 596 |
597 AssignHexString(&bignum, "FFFFFFFFFFFFFFFF"); | 597 AssignHexString(&bignum, "FFFFFFFFFFFFFFFF"); |
598 bignum.MultiplyByUInt64(0xF); | 598 bignum.MultiplyByUInt64(0xF); |
599 CHECK(bignum.ToHexString(buffer, kBufferSize)); | 599 CHECK(bignum.ToHexString(buffer, kBufferSize)); |
600 CHECK_EQ("EFFFFFFFFFFFFFFF1", buffer); | 600 CHECK_EQ(0, strcmp("EFFFFFFFFFFFFFFF1", buffer)); |
601 | 601 |
602 AssignHexString(&bignum, "FFFFFFFFFFFFFFFF"); | 602 AssignHexString(&bignum, "FFFFFFFFFFFFFFFF"); |
603 bignum.MultiplyByUInt64(V8_2PART_UINT64_C(0xFFFFFFFF, FFFFFFFF)); | 603 bignum.MultiplyByUInt64(V8_2PART_UINT64_C(0xFFFFFFFF, FFFFFFFF)); |
604 CHECK(bignum.ToHexString(buffer, kBufferSize)); | 604 CHECK(bignum.ToHexString(buffer, kBufferSize)); |
605 CHECK_EQ("FFFFFFFFFFFFFFFE0000000000000001", buffer); | 605 CHECK_EQ(0, strcmp("FFFFFFFFFFFFFFFE0000000000000001", buffer)); |
606 | 606 |
607 bignum.AssignUInt16(0x1); | 607 bignum.AssignUInt16(0x1); |
608 bignum.ShiftLeft(100); | 608 bignum.ShiftLeft(100); |
609 // "10 0000 0000 0000 0000 0000 0000" | 609 // "10 0000 0000 0000 0000 0000 0000" |
610 bignum.MultiplyByUInt64(2); | 610 bignum.MultiplyByUInt64(2); |
611 CHECK(bignum.ToHexString(buffer, kBufferSize)); | 611 CHECK(bignum.ToHexString(buffer, kBufferSize)); |
612 CHECK_EQ("20000000000000000000000000", buffer); | 612 CHECK_EQ(0, strcmp("20000000000000000000000000", buffer)); |
613 | 613 |
614 bignum.AssignUInt16(0x1); | 614 bignum.AssignUInt16(0x1); |
615 bignum.ShiftLeft(100); | 615 bignum.ShiftLeft(100); |
616 // "10 0000 0000 0000 0000 0000 0000" | 616 // "10 0000 0000 0000 0000 0000 0000" |
617 bignum.MultiplyByUInt64(0xF); | 617 bignum.MultiplyByUInt64(0xF); |
618 CHECK(bignum.ToHexString(buffer, kBufferSize)); | 618 CHECK(bignum.ToHexString(buffer, kBufferSize)); |
619 CHECK_EQ("F0000000000000000000000000", buffer); | 619 CHECK_EQ(0, strcmp("F0000000000000000000000000", buffer)); |
620 | 620 |
621 bignum.AssignUInt16(0xFFFF); | 621 bignum.AssignUInt16(0xFFFF); |
622 bignum.ShiftLeft(100); | 622 bignum.ShiftLeft(100); |
623 // "FFFF0 0000 0000 0000 0000 0000 0000" | 623 // "FFFF0 0000 0000 0000 0000 0000 0000" |
624 bignum.MultiplyByUInt64(0xFFFF); | 624 bignum.MultiplyByUInt64(0xFFFF); |
625 CHECK(bignum.ToHexString(buffer, kBufferSize)); | 625 CHECK(bignum.ToHexString(buffer, kBufferSize)); |
626 CHECK_EQ("FFFE00010000000000000000000000000", buffer); | 626 CHECK_EQ(0, strcmp("FFFE00010000000000000000000000000", buffer)); |
627 | 627 |
628 bignum.AssignUInt16(0xFFFF); | 628 bignum.AssignUInt16(0xFFFF); |
629 bignum.ShiftLeft(100); | 629 bignum.ShiftLeft(100); |
630 // "FFFF0 0000 0000 0000 0000 0000 0000" | 630 // "FFFF0 0000 0000 0000 0000 0000 0000" |
631 bignum.MultiplyByUInt64(0xFFFFFFFF); | 631 bignum.MultiplyByUInt64(0xFFFFFFFF); |
632 CHECK(bignum.ToHexString(buffer, kBufferSize)); | 632 CHECK(bignum.ToHexString(buffer, kBufferSize)); |
633 CHECK_EQ("FFFEFFFF00010000000000000000000000000", buffer); | 633 CHECK_EQ(0, strcmp("FFFEFFFF00010000000000000000000000000", buffer)); |
634 | 634 |
635 bignum.AssignUInt16(0xFFFF); | 635 bignum.AssignUInt16(0xFFFF); |
636 bignum.ShiftLeft(100); | 636 bignum.ShiftLeft(100); |
637 // "FFFF0 0000 0000 0000 0000 0000 0000" | 637 // "FFFF0 0000 0000 0000 0000 0000 0000" |
638 bignum.MultiplyByUInt64(V8_2PART_UINT64_C(0xFFFFFFFF, FFFFFFFF)); | 638 bignum.MultiplyByUInt64(V8_2PART_UINT64_C(0xFFFFFFFF, FFFFFFFF)); |
639 CHECK(bignum.ToHexString(buffer, kBufferSize)); | 639 CHECK(bignum.ToHexString(buffer, kBufferSize)); |
640 CHECK_EQ("FFFEFFFFFFFFFFFF00010000000000000000000000000", buffer); | 640 CHECK_EQ(0, strcmp("FFFEFFFFFFFFFFFF00010000000000000000000000000", buffer)); |
641 | 641 |
642 AssignDecimalString(&bignum, "15611230384529777"); | 642 AssignDecimalString(&bignum, "15611230384529777"); |
643 bignum.MultiplyByUInt64(V8_2PART_UINT64_C(0x8ac72304, 89e80000)); | 643 bignum.MultiplyByUInt64(V8_2PART_UINT64_C(0x8ac72304, 89e80000)); |
644 CHECK(bignum.ToHexString(buffer, kBufferSize)); | 644 CHECK(bignum.ToHexString(buffer, kBufferSize)); |
645 CHECK_EQ("1E10EE4B11D15A7F3DE7F3C7680000", buffer); | 645 CHECK_EQ(0, strcmp("1E10EE4B11D15A7F3DE7F3C7680000", buffer)); |
646 } | 646 } |
647 | 647 |
648 | 648 |
649 TEST(MultiplyPowerOfTen) { | 649 TEST(MultiplyPowerOfTen) { |
650 char buffer[kBufferSize]; | 650 char buffer[kBufferSize]; |
651 Bignum bignum; | 651 Bignum bignum; |
652 | 652 |
653 AssignDecimalString(&bignum, "1234"); | 653 AssignDecimalString(&bignum, "1234"); |
654 bignum.MultiplyByPowerOfTen(1); | 654 bignum.MultiplyByPowerOfTen(1); |
655 CHECK(bignum.ToHexString(buffer, kBufferSize)); | 655 CHECK(bignum.ToHexString(buffer, kBufferSize)); |
656 CHECK_EQ("3034", buffer); | 656 CHECK_EQ(0, strcmp("3034", buffer)); |
657 | 657 |
658 AssignDecimalString(&bignum, "1234"); | 658 AssignDecimalString(&bignum, "1234"); |
659 bignum.MultiplyByPowerOfTen(2); | 659 bignum.MultiplyByPowerOfTen(2); |
660 CHECK(bignum.ToHexString(buffer, kBufferSize)); | 660 CHECK(bignum.ToHexString(buffer, kBufferSize)); |
661 CHECK_EQ("1E208", buffer); | 661 CHECK_EQ(0, strcmp("1E208", buffer)); |
662 | 662 |
663 AssignDecimalString(&bignum, "1234"); | 663 AssignDecimalString(&bignum, "1234"); |
664 bignum.MultiplyByPowerOfTen(3); | 664 bignum.MultiplyByPowerOfTen(3); |
665 CHECK(bignum.ToHexString(buffer, kBufferSize)); | 665 CHECK(bignum.ToHexString(buffer, kBufferSize)); |
666 CHECK_EQ("12D450", buffer); | 666 CHECK_EQ(0, strcmp("12D450", buffer)); |
667 | 667 |
668 AssignDecimalString(&bignum, "1234"); | 668 AssignDecimalString(&bignum, "1234"); |
669 bignum.MultiplyByPowerOfTen(4); | 669 bignum.MultiplyByPowerOfTen(4); |
670 CHECK(bignum.ToHexString(buffer, kBufferSize)); | 670 CHECK(bignum.ToHexString(buffer, kBufferSize)); |
671 CHECK_EQ("BC4B20", buffer); | 671 CHECK_EQ(0, strcmp("BC4B20", buffer)); |
672 | 672 |
673 AssignDecimalString(&bignum, "1234"); | 673 AssignDecimalString(&bignum, "1234"); |
674 bignum.MultiplyByPowerOfTen(5); | 674 bignum.MultiplyByPowerOfTen(5); |
675 CHECK(bignum.ToHexString(buffer, kBufferSize)); | 675 CHECK(bignum.ToHexString(buffer, kBufferSize)); |
676 CHECK_EQ("75AEF40", buffer); | 676 CHECK_EQ(0, strcmp("75AEF40", buffer)); |
677 | 677 |
678 AssignDecimalString(&bignum, "1234"); | 678 AssignDecimalString(&bignum, "1234"); |
679 bignum.MultiplyByPowerOfTen(6); | 679 bignum.MultiplyByPowerOfTen(6); |
680 CHECK(bignum.ToHexString(buffer, kBufferSize)); | 680 CHECK(bignum.ToHexString(buffer, kBufferSize)); |
681 CHECK_EQ("498D5880", buffer); | 681 CHECK_EQ(0, strcmp("498D5880", buffer)); |
682 | 682 |
683 AssignDecimalString(&bignum, "1234"); | 683 AssignDecimalString(&bignum, "1234"); |
684 bignum.MultiplyByPowerOfTen(7); | 684 bignum.MultiplyByPowerOfTen(7); |
685 CHECK(bignum.ToHexString(buffer, kBufferSize)); | 685 CHECK(bignum.ToHexString(buffer, kBufferSize)); |
686 CHECK_EQ("2DF857500", buffer); | 686 CHECK_EQ(0, strcmp("2DF857500", buffer)); |
687 | 687 |
688 AssignDecimalString(&bignum, "1234"); | 688 AssignDecimalString(&bignum, "1234"); |
689 bignum.MultiplyByPowerOfTen(8); | 689 bignum.MultiplyByPowerOfTen(8); |
690 CHECK(bignum.ToHexString(buffer, kBufferSize)); | 690 CHECK(bignum.ToHexString(buffer, kBufferSize)); |
691 CHECK_EQ("1CBB369200", buffer); | 691 CHECK_EQ(0, strcmp("1CBB369200", buffer)); |
692 | 692 |
693 AssignDecimalString(&bignum, "1234"); | 693 AssignDecimalString(&bignum, "1234"); |
694 bignum.MultiplyByPowerOfTen(9); | 694 bignum.MultiplyByPowerOfTen(9); |
695 CHECK(bignum.ToHexString(buffer, kBufferSize)); | 695 CHECK(bignum.ToHexString(buffer, kBufferSize)); |
696 CHECK_EQ("11F5021B400", buffer); | 696 CHECK_EQ(0, strcmp("11F5021B400", buffer)); |
697 | 697 |
698 AssignDecimalString(&bignum, "1234"); | 698 AssignDecimalString(&bignum, "1234"); |
699 bignum.MultiplyByPowerOfTen(10); | 699 bignum.MultiplyByPowerOfTen(10); |
700 CHECK(bignum.ToHexString(buffer, kBufferSize)); | 700 CHECK(bignum.ToHexString(buffer, kBufferSize)); |
701 CHECK_EQ("B3921510800", buffer); | 701 CHECK_EQ(0, strcmp("B3921510800", buffer)); |
702 | 702 |
703 AssignDecimalString(&bignum, "1234"); | 703 AssignDecimalString(&bignum, "1234"); |
704 bignum.MultiplyByPowerOfTen(11); | 704 bignum.MultiplyByPowerOfTen(11); |
705 CHECK(bignum.ToHexString(buffer, kBufferSize)); | 705 CHECK(bignum.ToHexString(buffer, kBufferSize)); |
706 CHECK_EQ("703B4D2A5000", buffer); | 706 CHECK_EQ(0, strcmp("703B4D2A5000", buffer)); |
707 | 707 |
708 AssignDecimalString(&bignum, "1234"); | 708 AssignDecimalString(&bignum, "1234"); |
709 bignum.MultiplyByPowerOfTen(12); | 709 bignum.MultiplyByPowerOfTen(12); |
710 CHECK(bignum.ToHexString(buffer, kBufferSize)); | 710 CHECK(bignum.ToHexString(buffer, kBufferSize)); |
711 CHECK_EQ("4625103A72000", buffer); | 711 CHECK_EQ(0, strcmp("4625103A72000", buffer)); |
712 | 712 |
713 AssignDecimalString(&bignum, "1234"); | 713 AssignDecimalString(&bignum, "1234"); |
714 bignum.MultiplyByPowerOfTen(13); | 714 bignum.MultiplyByPowerOfTen(13); |
715 CHECK(bignum.ToHexString(buffer, kBufferSize)); | 715 CHECK(bignum.ToHexString(buffer, kBufferSize)); |
716 CHECK_EQ("2BD72A24874000", buffer); | 716 CHECK_EQ(0, strcmp("2BD72A24874000", buffer)); |
717 | 717 |
718 AssignDecimalString(&bignum, "1234"); | 718 AssignDecimalString(&bignum, "1234"); |
719 bignum.MultiplyByPowerOfTen(14); | 719 bignum.MultiplyByPowerOfTen(14); |
720 CHECK(bignum.ToHexString(buffer, kBufferSize)); | 720 CHECK(bignum.ToHexString(buffer, kBufferSize)); |
721 CHECK_EQ("1B667A56D488000", buffer); | 721 CHECK_EQ(0, strcmp("1B667A56D488000", buffer)); |
722 | 722 |
723 AssignDecimalString(&bignum, "1234"); | 723 AssignDecimalString(&bignum, "1234"); |
724 bignum.MultiplyByPowerOfTen(15); | 724 bignum.MultiplyByPowerOfTen(15); |
725 CHECK(bignum.ToHexString(buffer, kBufferSize)); | 725 CHECK(bignum.ToHexString(buffer, kBufferSize)); |
726 CHECK_EQ("11200C7644D50000", buffer); | 726 CHECK_EQ(0, strcmp("11200C7644D50000", buffer)); |
727 | 727 |
728 AssignDecimalString(&bignum, "1234"); | 728 AssignDecimalString(&bignum, "1234"); |
729 bignum.MultiplyByPowerOfTen(16); | 729 bignum.MultiplyByPowerOfTen(16); |
730 CHECK(bignum.ToHexString(buffer, kBufferSize)); | 730 CHECK(bignum.ToHexString(buffer, kBufferSize)); |
731 CHECK_EQ("AB407C9EB0520000", buffer); | 731 CHECK_EQ(0, strcmp("AB407C9EB0520000", buffer)); |
732 | 732 |
733 AssignDecimalString(&bignum, "1234"); | 733 AssignDecimalString(&bignum, "1234"); |
734 bignum.MultiplyByPowerOfTen(17); | 734 bignum.MultiplyByPowerOfTen(17); |
735 CHECK(bignum.ToHexString(buffer, kBufferSize)); | 735 CHECK(bignum.ToHexString(buffer, kBufferSize)); |
736 CHECK_EQ("6B084DE32E3340000", buffer); | 736 CHECK_EQ(0, strcmp("6B084DE32E3340000", buffer)); |
737 | 737 |
738 AssignDecimalString(&bignum, "1234"); | 738 AssignDecimalString(&bignum, "1234"); |
739 bignum.MultiplyByPowerOfTen(18); | 739 bignum.MultiplyByPowerOfTen(18); |
740 CHECK(bignum.ToHexString(buffer, kBufferSize)); | 740 CHECK(bignum.ToHexString(buffer, kBufferSize)); |
741 CHECK_EQ("42E530ADFCE0080000", buffer); | 741 CHECK_EQ(0, strcmp("42E530ADFCE0080000", buffer)); |
742 | 742 |
743 AssignDecimalString(&bignum, "1234"); | 743 AssignDecimalString(&bignum, "1234"); |
744 bignum.MultiplyByPowerOfTen(19); | 744 bignum.MultiplyByPowerOfTen(19); |
745 CHECK(bignum.ToHexString(buffer, kBufferSize)); | 745 CHECK(bignum.ToHexString(buffer, kBufferSize)); |
746 CHECK_EQ("29CF3E6CBE0C0500000", buffer); | 746 CHECK_EQ(0, strcmp("29CF3E6CBE0C0500000", buffer)); |
747 | 747 |
748 AssignDecimalString(&bignum, "1234"); | 748 AssignDecimalString(&bignum, "1234"); |
749 bignum.MultiplyByPowerOfTen(20); | 749 bignum.MultiplyByPowerOfTen(20); |
750 CHECK(bignum.ToHexString(buffer, kBufferSize)); | 750 CHECK(bignum.ToHexString(buffer, kBufferSize)); |
751 CHECK_EQ("1A218703F6C783200000", buffer); | 751 CHECK_EQ(0, strcmp("1A218703F6C783200000", buffer)); |
752 | 752 |
753 AssignDecimalString(&bignum, "1234"); | 753 AssignDecimalString(&bignum, "1234"); |
754 bignum.MultiplyByPowerOfTen(21); | 754 bignum.MultiplyByPowerOfTen(21); |
755 CHECK(bignum.ToHexString(buffer, kBufferSize)); | 755 CHECK(bignum.ToHexString(buffer, kBufferSize)); |
756 CHECK_EQ("1054F4627A3CB1F400000", buffer); | 756 CHECK_EQ(0, strcmp("1054F4627A3CB1F400000", buffer)); |
757 | 757 |
758 AssignDecimalString(&bignum, "1234"); | 758 AssignDecimalString(&bignum, "1234"); |
759 bignum.MultiplyByPowerOfTen(22); | 759 bignum.MultiplyByPowerOfTen(22); |
760 CHECK(bignum.ToHexString(buffer, kBufferSize)); | 760 CHECK(bignum.ToHexString(buffer, kBufferSize)); |
761 CHECK_EQ("A3518BD8C65EF38800000", buffer); | 761 CHECK_EQ(0, strcmp("A3518BD8C65EF38800000", buffer)); |
762 | 762 |
763 AssignDecimalString(&bignum, "1234"); | 763 AssignDecimalString(&bignum, "1234"); |
764 bignum.MultiplyByPowerOfTen(23); | 764 bignum.MultiplyByPowerOfTen(23); |
765 CHECK(bignum.ToHexString(buffer, kBufferSize)); | 765 CHECK(bignum.ToHexString(buffer, kBufferSize)); |
766 CHECK_EQ("6612F7677BFB5835000000", buffer); | 766 CHECK_EQ(0, strcmp("6612F7677BFB5835000000", buffer)); |
767 | 767 |
768 AssignDecimalString(&bignum, "1234"); | 768 AssignDecimalString(&bignum, "1234"); |
769 bignum.MultiplyByPowerOfTen(24); | 769 bignum.MultiplyByPowerOfTen(24); |
770 CHECK(bignum.ToHexString(buffer, kBufferSize)); | 770 CHECK(bignum.ToHexString(buffer, kBufferSize)); |
771 CHECK_EQ("3FCBDAA0AD7D17212000000", buffer); | 771 CHECK_EQ(0, strcmp("3FCBDAA0AD7D17212000000", buffer)); |
772 | 772 |
773 AssignDecimalString(&bignum, "1234"); | 773 AssignDecimalString(&bignum, "1234"); |
774 bignum.MultiplyByPowerOfTen(25); | 774 bignum.MultiplyByPowerOfTen(25); |
775 CHECK(bignum.ToHexString(buffer, kBufferSize)); | 775 CHECK(bignum.ToHexString(buffer, kBufferSize)); |
776 CHECK_EQ("27DF68A46C6E2E74B4000000", buffer); | 776 CHECK_EQ(0, strcmp("27DF68A46C6E2E74B4000000", buffer)); |
777 | 777 |
778 AssignDecimalString(&bignum, "1234"); | 778 AssignDecimalString(&bignum, "1234"); |
779 bignum.MultiplyByPowerOfTen(26); | 779 bignum.MultiplyByPowerOfTen(26); |
780 CHECK(bignum.ToHexString(buffer, kBufferSize)); | 780 CHECK(bignum.ToHexString(buffer, kBufferSize)); |
781 CHECK_EQ("18EBA166C3C4DD08F08000000", buffer); | 781 CHECK_EQ(0, strcmp("18EBA166C3C4DD08F08000000", buffer)); |
782 | 782 |
783 AssignDecimalString(&bignum, "1234"); | 783 AssignDecimalString(&bignum, "1234"); |
784 bignum.MultiplyByPowerOfTen(27); | 784 bignum.MultiplyByPowerOfTen(27); |
785 CHECK(bignum.ToHexString(buffer, kBufferSize)); | 785 CHECK(bignum.ToHexString(buffer, kBufferSize)); |
786 CHECK_EQ("F9344E03A5B0A259650000000", buffer); | 786 CHECK_EQ(0, strcmp("F9344E03A5B0A259650000000", buffer)); |
787 | 787 |
788 AssignDecimalString(&bignum, "1234"); | 788 AssignDecimalString(&bignum, "1234"); |
789 bignum.MultiplyByPowerOfTen(28); | 789 bignum.MultiplyByPowerOfTen(28); |
790 CHECK(bignum.ToHexString(buffer, kBufferSize)); | 790 CHECK(bignum.ToHexString(buffer, kBufferSize)); |
791 CHECK_EQ("9BC0B0C2478E6577DF20000000", buffer); | 791 CHECK_EQ(0, strcmp("9BC0B0C2478E6577DF20000000", buffer)); |
792 | 792 |
793 AssignDecimalString(&bignum, "1234"); | 793 AssignDecimalString(&bignum, "1234"); |
794 bignum.MultiplyByPowerOfTen(29); | 794 bignum.MultiplyByPowerOfTen(29); |
795 CHECK(bignum.ToHexString(buffer, kBufferSize)); | 795 CHECK(bignum.ToHexString(buffer, kBufferSize)); |
796 CHECK_EQ("61586E796CB8FF6AEB740000000", buffer); | 796 CHECK_EQ(0, strcmp("61586E796CB8FF6AEB740000000", buffer)); |
797 | 797 |
798 AssignDecimalString(&bignum, "1234"); | 798 AssignDecimalString(&bignum, "1234"); |
799 bignum.MultiplyByPowerOfTen(30); | 799 bignum.MultiplyByPowerOfTen(30); |
800 CHECK(bignum.ToHexString(buffer, kBufferSize)); | 800 CHECK(bignum.ToHexString(buffer, kBufferSize)); |
801 CHECK_EQ("3CD7450BE3F39FA2D32880000000", buffer); | 801 CHECK_EQ(0, strcmp("3CD7450BE3F39FA2D32880000000", buffer)); |
802 | 802 |
803 AssignDecimalString(&bignum, "1234"); | 803 AssignDecimalString(&bignum, "1234"); |
804 bignum.MultiplyByPowerOfTen(31); | 804 bignum.MultiplyByPowerOfTen(31); |
805 CHECK(bignum.ToHexString(buffer, kBufferSize)); | 805 CHECK(bignum.ToHexString(buffer, kBufferSize)); |
806 CHECK_EQ("26068B276E7843C5C3F9500000000", buffer); | 806 CHECK_EQ(0, strcmp("26068B276E7843C5C3F9500000000", buffer)); |
807 | 807 |
808 AssignDecimalString(&bignum, "1234"); | 808 AssignDecimalString(&bignum, "1234"); |
809 bignum.MultiplyByPowerOfTen(50); | 809 bignum.MultiplyByPowerOfTen(50); |
810 CHECK(bignum.ToHexString(buffer, kBufferSize)); | 810 CHECK(bignum.ToHexString(buffer, kBufferSize)); |
811 CHECK_EQ("149D1B4CFED03B23AB5F4E1196EF45C08000000000000", buffer); | 811 CHECK_EQ(0, strcmp("149D1B4CFED03B23AB5F4E1196EF45C08000000000000", buffer)); |
812 | 812 |
813 AssignDecimalString(&bignum, "1234"); | 813 AssignDecimalString(&bignum, "1234"); |
814 bignum.MultiplyByPowerOfTen(100); | 814 bignum.MultiplyByPowerOfTen(100); |
815 CHECK(bignum.ToHexString(buffer, kBufferSize)); | 815 CHECK(bignum.ToHexString(buffer, kBufferSize)); |
816 CHECK_EQ("5827249F27165024FBC47DFCA9359BF316332D1B91ACEECF471FBAB06D9B2" | 816 CHECK_EQ(0, |
817 "0000000000000000000000000", buffer); | 817 strcmp( |
| 818 "5827249F27165024FBC47DFCA9359BF316332D1B91ACEECF471FBAB06D9B2" |
| 819 "0000000000000000000000000", |
| 820 buffer)); |
818 | 821 |
819 AssignDecimalString(&bignum, "1234"); | 822 AssignDecimalString(&bignum, "1234"); |
820 bignum.MultiplyByPowerOfTen(200); | 823 bignum.MultiplyByPowerOfTen(200); |
821 CHECK(bignum.ToHexString(buffer, kBufferSize)); | 824 CHECK(bignum.ToHexString(buffer, kBufferSize)); |
822 CHECK_EQ("64C1F5C06C3816AFBF8DAFD5A3D756365BB0FD020E6F084E759C1F7C99E4F" | 825 CHECK_EQ(0, |
823 "55B9ACC667CEC477EB958C2AEEB3C6C19BA35A1AD30B35C51EB72040920000" | 826 strcmp( |
824 "0000000000000000000000000000000000000000000000", buffer); | 827 "64C1F5C06C3816AFBF8DAFD5A3D756365BB0FD020E6F084E759C1F7C99E4F" |
| 828 "55B9ACC667CEC477EB958C2AEEB3C6C19BA35A1AD30B35C51EB72040920000" |
| 829 "0000000000000000000000000000000000000000000000", |
| 830 buffer)); |
825 | 831 |
826 AssignDecimalString(&bignum, "1234"); | 832 AssignDecimalString(&bignum, "1234"); |
827 bignum.MultiplyByPowerOfTen(500); | 833 bignum.MultiplyByPowerOfTen(500); |
828 CHECK(bignum.ToHexString(buffer, kBufferSize)); | 834 CHECK(bignum.ToHexString(buffer, kBufferSize)); |
829 CHECK_EQ("96741A625EB5D7C91039FEB5C5ACD6D9831EDA5B083D800E6019442C8C8223" | 835 CHECK_EQ(0, |
830 "3EAFB3501FE2058062221E15121334928880827DEE1EC337A8B26489F3A40A" | 836 strcmp( |
831 "CB440A2423734472D10BFCE886F41B3AF9F9503013D86D088929CA86EEB4D8" | 837 "96741A625EB5D7C91039FEB5C5ACD6D9831EDA5B083D800E6019442C8C8223" |
832 "B9C831D0BD53327B994A0326227CFD0ECBF2EB48B02387AAE2D4CCCDF1F1A1" | 838 "3EAFB3501FE2058062221E15121334928880827DEE1EC337A8B26489F3A40A" |
833 "B8CC4F1FA2C56AD40D0E4DAA9C28CDBF0A549098EA13200000000000000000" | 839 "CB440A2423734472D10BFCE886F41B3AF9F9503013D86D088929CA86EEB4D8" |
834 "00000000000000000000000000000000000000000000000000000000000000" | 840 "B9C831D0BD53327B994A0326227CFD0ECBF2EB48B02387AAE2D4CCCDF1F1A1" |
835 "0000000000000000000000000000000000000000000000", buffer); | 841 "B8CC4F1FA2C56AD40D0E4DAA9C28CDBF0A549098EA13200000000000000000" |
| 842 "00000000000000000000000000000000000000000000000000000000000000" |
| 843 "0000000000000000000000000000000000000000000000", |
| 844 buffer)); |
836 | 845 |
837 AssignDecimalString(&bignum, "1234"); | 846 AssignDecimalString(&bignum, "1234"); |
838 bignum.MultiplyByPowerOfTen(1000); | 847 bignum.MultiplyByPowerOfTen(1000); |
839 CHECK(bignum.ToHexString(buffer, kBufferSize)); | 848 CHECK(bignum.ToHexString(buffer, kBufferSize)); |
840 CHECK_EQ("1258040F99B1CD1CC9819C676D413EA50E4A6A8F114BB0C65418C62D399B81" | 849 CHECK_EQ(0, |
841 "6361466CA8E095193E1EE97173553597C96673AF67FAFE27A66E7EF2E5EF2E" | 850 strcmp( |
842 "E3F5F5070CC17FE83BA53D40A66A666A02F9E00B0E11328D2224B8694C7372" | 851 "1258040F99B1CD1CC9819C676D413EA50E4A6A8F114BB0C65418C62D399B81" |
843 "F3D536A0AD1985911BD361496F268E8B23112500EAF9B88A9BC67B2AB04D38" | 852 "6361466CA8E095193E1EE97173553597C96673AF67FAFE27A66E7EF2E5EF2E" |
844 "7FEFACD00F5AF4F764F9ABC3ABCDE54612DE38CD90CB6647CA389EA0E86B16" | 853 "E3F5F5070CC17FE83BA53D40A66A666A02F9E00B0E11328D2224B8694C7372" |
845 "BF7A1F34086E05ADBE00BD1673BE00FAC4B34AF1091E8AD50BA675E0381440" | 854 "F3D536A0AD1985911BD361496F268E8B23112500EAF9B88A9BC67B2AB04D38" |
846 "EA8E9D93E75D816BAB37C9844B1441C38FC65CF30ABB71B36433AF26DD97BD" | 855 "7FEFACD00F5AF4F764F9ABC3ABCDE54612DE38CD90CB6647CA389EA0E86B16" |
847 "ABBA96C03B4919B8F3515B92826B85462833380DC193D79F69D20DD6038C99" | 856 "BF7A1F34086E05ADBE00BD1673BE00FAC4B34AF1091E8AD50BA675E0381440" |
848 "6114EF6C446F0BA28CC772ACBA58B81C04F8FFDE7B18C4E5A3ABC51E637FDF" | 857 "EA8E9D93E75D816BAB37C9844B1441C38FC65CF30ABB71B36433AF26DD97BD" |
849 "6E37FDFF04C940919390F4FF92000000000000000000000000000000000000" | 858 "ABBA96C03B4919B8F3515B92826B85462833380DC193D79F69D20DD6038C99" |
850 "00000000000000000000000000000000000000000000000000000000000000" | 859 "6114EF6C446F0BA28CC772ACBA58B81C04F8FFDE7B18C4E5A3ABC51E637FDF" |
851 "00000000000000000000000000000000000000000000000000000000000000" | 860 "6E37FDFF04C940919390F4FF92000000000000000000000000000000000000" |
852 "00000000000000000000000000000000000000000000000000000000000000" | 861 "00000000000000000000000000000000000000000000000000000000000000" |
853 "0000000000000000000000000000", buffer); | 862 "00000000000000000000000000000000000000000000000000000000000000" |
| 863 "00000000000000000000000000000000000000000000000000000000000000" |
| 864 "0000000000000000000000000000", |
| 865 buffer)); |
854 | 866 |
855 Bignum bignum2; | 867 Bignum bignum2; |
856 AssignHexString(&bignum2, "3DA774C07FB5DF54284D09C675A492165B830D5DAAEB2A7501" | 868 AssignHexString(&bignum2, "3DA774C07FB5DF54284D09C675A492165B830D5DAAEB2A7501" |
857 "DA17CF9DFA1CA2282269F92A25A97314296B717E3DCBB9FE17" | 869 "DA17CF9DFA1CA2282269F92A25A97314296B717E3DCBB9FE17" |
858 "41A842FE2913F540F40796F2381155763502C58B15AF7A7F88" | 870 "41A842FE2913F540F40796F2381155763502C58B15AF7A7F88" |
859 "6F744C9164FF409A28F7FA0C41F89ED79C1BE9F322C8578B97" | 871 "6F744C9164FF409A28F7FA0C41F89ED79C1BE9F322C8578B97" |
860 "841F1CBAA17D901BE1230E3C00E1C643AF32638B5674E01FEA" | 872 "841F1CBAA17D901BE1230E3C00E1C643AF32638B5674E01FEA" |
861 "96FC90864E621B856A9E1CE56E6EB545B9C2F8F0CC10DDA88D" | 873 "96FC90864E621B856A9E1CE56E6EB545B9C2F8F0CC10DDA88D" |
862 "CC6D282605F8DB67044F2DFD3695E7BA63877AE16701536AE6" | 874 "CC6D282605F8DB67044F2DFD3695E7BA63877AE16701536AE6" |
863 "567C794D0BFE338DFBB42D92D4215AF3BB22BF0A8B283FDDC2" | 875 "567C794D0BFE338DFBB42D92D4215AF3BB22BF0A8B283FDDC2" |
864 "C667A10958EA6D2"); | 876 "C667A10958EA6D2"); |
865 CHECK(bignum2.ToHexString(buffer, kBufferSize)); | 877 CHECK(bignum2.ToHexString(buffer, kBufferSize)); |
866 CHECK_EQ("3DA774C07FB5DF54284D09C675A492165B830D5DAAEB2A7501" | 878 CHECK_EQ(0, strcmp( |
867 "DA17CF9DFA1CA2282269F92A25A97314296B717E3DCBB9FE17" | 879 "3DA774C07FB5DF54284D09C675A492165B830D5DAAEB2A7501" |
868 "41A842FE2913F540F40796F2381155763502C58B15AF7A7F88" | 880 "DA17CF9DFA1CA2282269F92A25A97314296B717E3DCBB9FE17" |
869 "6F744C9164FF409A28F7FA0C41F89ED79C1BE9F322C8578B97" | 881 "41A842FE2913F540F40796F2381155763502C58B15AF7A7F88" |
870 "841F1CBAA17D901BE1230E3C00E1C643AF32638B5674E01FEA" | 882 "6F744C9164FF409A28F7FA0C41F89ED79C1BE9F322C8578B97" |
871 "96FC90864E621B856A9E1CE56E6EB545B9C2F8F0CC10DDA88D" | 883 "841F1CBAA17D901BE1230E3C00E1C643AF32638B5674E01FEA" |
872 "CC6D282605F8DB67044F2DFD3695E7BA63877AE16701536AE6" | 884 "96FC90864E621B856A9E1CE56E6EB545B9C2F8F0CC10DDA88D" |
873 "567C794D0BFE338DFBB42D92D4215AF3BB22BF0A8B283FDDC2" | 885 "CC6D282605F8DB67044F2DFD3695E7BA63877AE16701536AE6" |
874 "C667A10958EA6D2", buffer); | 886 "567C794D0BFE338DFBB42D92D4215AF3BB22BF0A8B283FDDC2" |
| 887 "C667A10958EA6D2", |
| 888 buffer)); |
875 | 889 |
876 bignum.AssignBignum(bignum2); | 890 bignum.AssignBignum(bignum2); |
877 bignum.MultiplyByPowerOfTen(1); | 891 bignum.MultiplyByPowerOfTen(1); |
878 CHECK(bignum.ToHexString(buffer, kBufferSize)); | 892 CHECK(bignum.ToHexString(buffer, kBufferSize)); |
879 CHECK_EQ("2688A8F84FD1AB949930261C0986DB4DF931E85A8AD2FA8921284EE1C2BC51" | 893 CHECK_EQ(0, |
880 "E55915823BBA5789E7EC99E326EEE69F543ECE890929DED9AC79489884BE57" | 894 strcmp( |
881 "630AD569E121BB76ED8DAC8FB545A8AFDADF1F8860599AFC47A93B6346C191" | 895 "2688A8F84FD1AB949930261C0986DB4DF931E85A8AD2FA8921284EE1C2BC51" |
882 "7237F5BD36B73EB29371F4A4EE7A116CB5E8E5808D1BEA4D7F7E3716090C13" | 896 "E55915823BBA5789E7EC99E326EEE69F543ECE890929DED9AC79489884BE57" |
883 "F29E5DDA53F0FD513362A2D20F6505314B9419DB967F8A8A89589FC43917C3" | 897 "630AD569E121BB76ED8DAC8FB545A8AFDADF1F8860599AFC47A93B6346C191" |
884 "BB892062B17CBE421DB0D47E34ACCCE060D422CFF60DCBD0277EE038BD509C" | 898 "7237F5BD36B73EB29371F4A4EE7A116CB5E8E5808D1BEA4D7F7E3716090C13" |
885 "7BC494D8D854F5B76696F927EA99BC00C4A5D7928434", buffer); | 899 "F29E5DDA53F0FD513362A2D20F6505314B9419DB967F8A8A89589FC43917C3" |
| 900 "BB892062B17CBE421DB0D47E34ACCCE060D422CFF60DCBD0277EE038BD509C" |
| 901 "7BC494D8D854F5B76696F927EA99BC00C4A5D7928434", |
| 902 buffer)); |
886 | 903 |
887 bignum.AssignBignum(bignum2); | 904 bignum.AssignBignum(bignum2); |
888 bignum.MultiplyByPowerOfTen(2); | 905 bignum.MultiplyByPowerOfTen(2); |
889 CHECK(bignum.ToHexString(buffer, kBufferSize)); | 906 CHECK(bignum.ToHexString(buffer, kBufferSize)); |
890 CHECK_EQ("1815699B31E30B3CDFBE17D185F44910BBBF313896C3DC95B4B9314D19B5B32" | 907 CHECK_EQ(0, |
891 "F57AD71655476B630F3E02DF855502394A74115A5BA2B480BCBCD5F52F6F69D" | 908 strcmp( |
892 "E6C5622CB5152A54788BD9D14B896DE8CB73B53C3800DDACC9C51E0C38FAE76" | 909 "1815699B31E30B3CDFBE17D185F44910BBBF313896C3DC95B4B9314D19B5B32" |
893 "2F9964232872F9C2738E7150C4AE3F1B18F70583172706FAEE26DC5A78C77A2" | 910 "F57AD71655476B630F3E02DF855502394A74115A5BA2B480BCBCD5F52F6F69D" |
894 "FAA874769E52C01DA5C3499F233ECF3C90293E0FB69695D763DAA3AEDA5535B" | 911 "E6C5622CB5152A54788BD9D14B896DE8CB73B53C3800DDACC9C51E0C38FAE76" |
895 "43DAEEDF6E9528E84CEE0EC000C3C8495C1F9C89F6218AF4C23765261CD5ADD" | 912 "2F9964232872F9C2738E7150C4AE3F1B18F70583172706FAEE26DC5A78C77A2" |
896 "0787351992A01E5BB8F2A015807AE7A6BB92A08", buffer); | 913 "FAA874769E52C01DA5C3499F233ECF3C90293E0FB69695D763DAA3AEDA5535B" |
| 914 "43DAEEDF6E9528E84CEE0EC000C3C8495C1F9C89F6218AF4C23765261CD5ADD" |
| 915 "0787351992A01E5BB8F2A015807AE7A6BB92A08", |
| 916 buffer)); |
897 | 917 |
898 bignum.AssignBignum(bignum2); | 918 bignum.AssignBignum(bignum2); |
899 bignum.MultiplyByPowerOfTen(5); | 919 bignum.MultiplyByPowerOfTen(5); |
900 CHECK(bignum.ToHexString(buffer, kBufferSize)); | 920 CHECK(bignum.ToHexString(buffer, kBufferSize)); |
901 CHECK_EQ("5E13A4863ADEE3E5C9FE8D0A73423D695D62D8450CED15A8C9F368952C6DC3" | 921 CHECK_EQ(0, |
902 "F0EE7D82F3D1EFB7AF38A3B3920D410AFCAD563C8F5F39116E141A3C5C14B3" | 922 strcmp( |
903 "58CD73077EA35AAD59F6E24AD98F10D5555ABBFBF33AC361EAF429FD5FBE94" | 923 "5E13A4863ADEE3E5C9FE8D0A73423D695D62D8450CED15A8C9F368952C6DC3" |
904 "17DA9EF2F2956011F9F93646AA38048A681D984ED88127073443247CCC167C" | 924 "F0EE7D82F3D1EFB7AF38A3B3920D410AFCAD563C8F5F39116E141A3C5C14B3" |
905 "B354A32206EF5A733E73CF82D795A1AD598493211A6D613C39515E0E0F6304" | 925 "58CD73077EA35AAD59F6E24AD98F10D5555ABBFBF33AC361EAF429FD5FBE94" |
906 "DCD9C810F3518C7F6A7CB6C81E99E02FCC65E8FDB7B7AE97306CC16A8631CE" | 926 "17DA9EF2F2956011F9F93646AA38048A681D984ED88127073443247CCC167C" |
907 "0A2AEF6568276BE4C176964A73C153FDE018E34CB4C2F40", buffer); | 927 "B354A32206EF5A733E73CF82D795A1AD598493211A6D613C39515E0E0F6304" |
| 928 "DCD9C810F3518C7F6A7CB6C81E99E02FCC65E8FDB7B7AE97306CC16A8631CE" |
| 929 "0A2AEF6568276BE4C176964A73C153FDE018E34CB4C2F40", |
| 930 buffer)); |
908 | 931 |
909 bignum.AssignBignum(bignum2); | 932 bignum.AssignBignum(bignum2); |
910 bignum.MultiplyByPowerOfTen(10); | 933 bignum.MultiplyByPowerOfTen(10); |
911 CHECK(bignum.ToHexString(buffer, kBufferSize)); | 934 CHECK(bignum.ToHexString(buffer, kBufferSize)); |
912 CHECK_EQ("8F8CB8EB51945A7E815809F6121EF2F4E61EF3405CD9432CAD2709749EEAFD" | 935 CHECK_EQ(0, |
913 "1B81E843F14A3667A7BDCCC9E0BB795F63CDFDB62844AC7438976C885A0116" | 936 strcmp( |
914 "29607DA54F9C023CC366570B7637ED0F855D931752038A614922D0923E382C" | 937 "8F8CB8EB51945A7E815809F6121EF2F4E61EF3405CD9432CAD2709749EEAFD" |
915 "B8E5F6C975672DB76E0DE471937BB9EDB11E28874F1C122D5E1EF38CECE9D0" | 938 "1B81E843F14A3667A7BDCCC9E0BB795F63CDFDB62844AC7438976C885A0116" |
916 "0723056BCBD4F964192B76830634B1D322B7EB0062F3267E84F5C824343A77" | 939 "29607DA54F9C023CC366570B7637ED0F855D931752038A614922D0923E382C" |
917 "4B7DCEE6DD464F01EBDC8C671BB18BB4EF4300A42474A6C77243F2A12B03BF" | 940 "B8E5F6C975672DB76E0DE471937BB9EDB11E28874F1C122D5E1EF38CECE9D0" |
918 "0443C38A1C0D2701EDB393135AE0DEC94211F9D4EB51F990800", buffer); | 941 "0723056BCBD4F964192B76830634B1D322B7EB0062F3267E84F5C824343A77" |
| 942 "4B7DCEE6DD464F01EBDC8C671BB18BB4EF4300A42474A6C77243F2A12B03BF" |
| 943 "0443C38A1C0D2701EDB393135AE0DEC94211F9D4EB51F990800", |
| 944 buffer)); |
919 | 945 |
920 bignum.AssignBignum(bignum2); | 946 bignum.AssignBignum(bignum2); |
921 bignum.MultiplyByPowerOfTen(50); | 947 bignum.MultiplyByPowerOfTen(50); |
922 CHECK(bignum.ToHexString(buffer, kBufferSize)); | 948 CHECK(bignum.ToHexString(buffer, kBufferSize)); |
923 CHECK_EQ("107A8BE345E24407372FC1DE442CBA696BC23C4FFD5B4BDFD9E5C39559815" | 949 CHECK_EQ(0, |
924 "86628CF8472D2D589F2FC2BAD6E0816EC72CBF85CCA663D8A1EC6C51076D8" | 950 strcmp( |
925 "2D247E6C26811B7EC4D4300FB1F91028DCB7B2C4E7A60C151161AA7E65E79" | 951 "107A8BE345E24407372FC1DE442CBA696BC23C4FFD5B4BDFD9E5C39559815" |
926 "B40917B12B2B5FBE7745984D4E8EFA31F9AE6062427B068B144A9CB155873" | 952 "86628CF8472D2D589F2FC2BAD6E0816EC72CBF85CCA663D8A1EC6C51076D8" |
927 "E7C0C9F0115E5AC72DC5A73C4796DB970BF9205AB8C77A6996EB1B417F9D1" | 953 "2D247E6C26811B7EC4D4300FB1F91028DCB7B2C4E7A60C151161AA7E65E79" |
928 "6232431E6313C392203601B9C22CC10DDA88DCC6D282605F8DB67044F2DFD" | 954 "B40917B12B2B5FBE7745984D4E8EFA31F9AE6062427B068B144A9CB155873" |
929 "3695E7BA63877AE16701536AE6567C794D0BFE338DFBB42D924CF964BD2C0" | 955 "E7C0C9F0115E5AC72DC5A73C4796DB970BF9205AB8C77A6996EB1B417F9D1" |
930 "F586E03A2FCD35A408000000000000", buffer); | 956 "6232431E6313C392203601B9C22CC10DDA88DCC6D282605F8DB67044F2DFD" |
| 957 "3695E7BA63877AE16701536AE6567C794D0BFE338DFBB42D924CF964BD2C0" |
| 958 "F586E03A2FCD35A408000000000000", |
| 959 buffer)); |
931 | 960 |
932 bignum.AssignBignum(bignum2); | 961 bignum.AssignBignum(bignum2); |
933 bignum.MultiplyByPowerOfTen(100); | 962 bignum.MultiplyByPowerOfTen(100); |
934 CHECK(bignum.ToHexString(buffer, kBufferSize)); | 963 CHECK(bignum.ToHexString(buffer, kBufferSize)); |
935 CHECK_EQ("46784A90ACD0ED3E7759CC585FB32D36EB6034A6F78D92604E3BAA5ED3D8B" | 964 CHECK_EQ(0, |
936 "6E60E854439BE448897FB4B7EA5A3D873AA0FCB3CFFD80D0530880E45F511" | 965 strcmp( |
937 "722A50CE7E058B5A6F5464DB7500E34984EE3202A9441F44FA1554C0CEA96" | 966 "46784A90ACD0ED3E7759CC585FB32D36EB6034A6F78D92604E3BAA5ED3D8B" |
938 "B438A36F25E7C9D56D71AE2CD313EC37534DA299AC0854FC48591A7CF3171" | 967 "6E60E854439BE448897FB4B7EA5A3D873AA0FCB3CFFD80D0530880E45F511" |
939 "31265AA4AE62DE32344CE7BEEEF894AE686A2DAAFE5D6D9A10971FFD9C064" | 968 "722A50CE7E058B5A6F5464DB7500E34984EE3202A9441F44FA1554C0CEA96" |
940 "5079B209E1048F58B5192D41D84336AC4C8C489EEF00939CFC9D55C122036" | 969 "B438A36F25E7C9D56D71AE2CD313EC37534DA299AC0854FC48591A7CF3171" |
941 "01B9C22CC10DDA88DCC6D282605F8DB67044F2DFD3695E7BA3F67B96D3A32" | 970 "31265AA4AE62DE32344CE7BEEEF894AE686A2DAAFE5D6D9A10971FFD9C064" |
942 "E11FB5561B68744C4035B0800DC166D49D98E3FD1D5BB2000000000000000" | 971 "5079B209E1048F58B5192D41D84336AC4C8C489EEF00939CFC9D55C122036" |
943 "0000000000", buffer); | 972 "01B9C22CC10DDA88DCC6D282605F8DB67044F2DFD3695E7BA3F67B96D3A32" |
| 973 "E11FB5561B68744C4035B0800DC166D49D98E3FD1D5BB2000000000000000" |
| 974 "0000000000", |
| 975 buffer)); |
944 | 976 |
945 bignum.AssignBignum(bignum2); | 977 bignum.AssignBignum(bignum2); |
946 bignum.MultiplyByPowerOfTen(200); | 978 bignum.MultiplyByPowerOfTen(200); |
947 CHECK(bignum.ToHexString(buffer, kBufferSize)); | 979 CHECK(bignum.ToHexString(buffer, kBufferSize)); |
948 CHECK_EQ("508BD351221DF139D72D88CDC0416845A53EE2D0E6B98352509A9AC312F8C" | 980 CHECK_EQ(0, |
949 "6CB1A144889416201E0B6CE66EA3EBE259B5FD79ECFC1FD77963CE516CC7E" | 981 strcmp( |
950 "2FE73D4B5B710C19F6BCB092C7A2FD76286543B8DBD2C596DFF2C896720BA" | 982 "508BD351221DF139D72D88CDC0416845A53EE2D0E6B98352509A9AC312F8C" |
951 "DFF7BC9C366ACEA3A880AEC287C5E6207DF2739B5326FC19D773BD830B109" | 983 "6CB1A144889416201E0B6CE66EA3EBE259B5FD79ECFC1FD77963CE516CC7E" |
952 "ED36C7086544BF8FDB9D4B73719C2B5BC2F571A5937EC46876CD428281F6B" | 984 "2FE73D4B5B710C19F6BCB092C7A2FD76286543B8DBD2C596DFF2C896720BA" |
953 "F287E1E07F25C1B1D46BC37324FF657A8B2E0071DB83B86123CA34004F406" | 985 "DFF7BC9C366ACEA3A880AEC287C5E6207DF2739B5326FC19D773BD830B109" |
954 "001082D7945E90C6E8C9A9FEC2B44BE0DDA46E9F52B152E4D1336D2FCFBC9" | 986 "ED36C7086544BF8FDB9D4B73719C2B5BC2F571A5937EC46876CD428281F6B" |
955 "96E30CA0082256737365158FE36482AA7EB9DAF2AB128F10E7551A3CD5BE6" | 987 "F287E1E07F25C1B1D46BC37324FF657A8B2E0071DB83B86123CA34004F406" |
956 "0A922F3A7D5EED38B634A7EC95BCF7021BA6820A292000000000000000000" | 988 "001082D7945E90C6E8C9A9FEC2B44BE0DDA46E9F52B152E4D1336D2FCFBC9" |
957 "00000000000000000000000000000000", buffer); | 989 "96E30CA0082256737365158FE36482AA7EB9DAF2AB128F10E7551A3CD5BE6" |
| 990 "0A922F3A7D5EED38B634A7EC95BCF7021BA6820A292000000000000000000" |
| 991 "00000000000000000000000000000000", |
| 992 buffer)); |
958 | 993 |
959 bignum.AssignBignum(bignum2); | 994 bignum.AssignBignum(bignum2); |
960 bignum.MultiplyByPowerOfTen(500); | 995 bignum.MultiplyByPowerOfTen(500); |
961 CHECK(bignum.ToHexString(buffer, kBufferSize)); | 996 CHECK(bignum.ToHexString(buffer, kBufferSize)); |
962 CHECK_EQ("7845F900E475B5086885BAAAE67C8E85185ACFE4633727F82A4B06B5582AC" | 997 CHECK_EQ(0, |
963 "BE933C53357DA0C98C20C5AC900C4D76A97247DF52B79F48F9E35840FB715" | 998 strcmp( |
964 "D392CE303E22622B0CF82D9471B398457DD3196F639CEE8BBD2C146873841" | 999 "7845F900E475B5086885BAAAE67C8E85185ACFE4633727F82A4B06B5582AC" |
965 "F0699E6C41F04FC7A54B48CEB995BEB6F50FE81DE9D87A8D7F849CC523553" | 1000 "BE933C53357DA0C98C20C5AC900C4D76A97247DF52B79F48F9E35840FB715" |
966 "7B7BBBC1C7CAAFF6E9650BE03B308C6D31012AEF9580F70D3EE2083ADE126" | 1001 "D392CE303E22622B0CF82D9471B398457DD3196F639CEE8BBD2C146873841" |
967 "8940FA7D6308E239775DFD2F8C97FF7EBD525DAFA6512216F7047A62A93DC" | 1002 "F0699E6C41F04FC7A54B48CEB995BEB6F50FE81DE9D87A8D7F849CC523553" |
968 "38A0165BDC67E250DCC96A0181DE935A70B38704DC71819F02FC5261FF7E1" | 1003 "7B7BBBC1C7CAAFF6E9650BE03B308C6D31012AEF9580F70D3EE2083ADE126" |
969 "E5F11907678B0A3E519FF4C10A867B0C26CE02BE6960BA8621A87303C101C" | 1004 "8940FA7D6308E239775DFD2F8C97FF7EBD525DAFA6512216F7047A62A93DC" |
970 "3F88798BB9F7739655946F8B5744E6B1EAF10B0C5621330F0079209033C69" | 1005 "38A0165BDC67E250DCC96A0181DE935A70B38704DC71819F02FC5261FF7E1" |
971 "20DE2E2C8D324F0624463735D482BF291926C22A910F5B80FA25170B6B57D" | 1006 "E5F11907678B0A3E519FF4C10A867B0C26CE02BE6960BA8621A87303C101C" |
972 "8D5928C7BCA3FE87461275F69BD5A1B83181DAAF43E05FC3C72C4E93111B6" | 1007 "3F88798BB9F7739655946F8B5744E6B1EAF10B0C5621330F0079209033C69" |
973 "6205EBF49B28FEDFB7E7526CBDA658A332000000000000000000000000000" | 1008 "20DE2E2C8D324F0624463735D482BF291926C22A910F5B80FA25170B6B57D" |
974 "0000000000000000000000000000000000000000000000000000000000000" | 1009 "8D5928C7BCA3FE87461275F69BD5A1B83181DAAF43E05FC3C72C4E93111B6" |
975 "0000000000000000000000000000000000000", buffer); | 1010 "6205EBF49B28FEDFB7E7526CBDA658A332000000000000000000000000000" |
| 1011 "0000000000000000000000000000000000000000000000000000000000000" |
| 1012 "0000000000000000000000000000000000000", |
| 1013 buffer)); |
976 } | 1014 } |
977 | 1015 |
978 | 1016 |
979 TEST(DivideModuloIntBignum) { | 1017 TEST(DivideModuloIntBignum) { |
980 char buffer[kBufferSize]; | 1018 char buffer[kBufferSize]; |
981 Bignum bignum; | 1019 Bignum bignum; |
982 Bignum other; | 1020 Bignum other; |
983 Bignum third; | 1021 Bignum third; |
984 | 1022 |
985 bignum.AssignUInt16(10); | 1023 bignum.AssignUInt16(10); |
986 other.AssignUInt16(2); | 1024 other.AssignUInt16(2); |
987 CHECK_EQ(5, bignum.DivideModuloIntBignum(other)); | 1025 CHECK_EQ(5, bignum.DivideModuloIntBignum(other)); |
988 CHECK(bignum.ToHexString(buffer, kBufferSize)); | 1026 CHECK(bignum.ToHexString(buffer, kBufferSize)); |
989 CHECK_EQ("0", buffer); | 1027 CHECK_EQ(0, strcmp("0", buffer)); |
990 | 1028 |
991 bignum.AssignUInt16(10); | 1029 bignum.AssignUInt16(10); |
992 bignum.ShiftLeft(500); | 1030 bignum.ShiftLeft(500); |
993 other.AssignUInt16(2); | 1031 other.AssignUInt16(2); |
994 other.ShiftLeft(500); | 1032 other.ShiftLeft(500); |
995 CHECK_EQ(5, bignum.DivideModuloIntBignum(other)); | 1033 CHECK_EQ(5, bignum.DivideModuloIntBignum(other)); |
996 CHECK_EQ("0", buffer); | 1034 CHECK_EQ(0, strcmp("0", buffer)); |
997 | 1035 |
998 bignum.AssignUInt16(11); | 1036 bignum.AssignUInt16(11); |
999 other.AssignUInt16(2); | 1037 other.AssignUInt16(2); |
1000 CHECK_EQ(5, bignum.DivideModuloIntBignum(other)); | 1038 CHECK_EQ(5, bignum.DivideModuloIntBignum(other)); |
1001 CHECK(bignum.ToHexString(buffer, kBufferSize)); | 1039 CHECK(bignum.ToHexString(buffer, kBufferSize)); |
1002 CHECK_EQ("1", buffer); | 1040 CHECK_EQ(0, strcmp("1", buffer)); |
1003 | 1041 |
1004 bignum.AssignUInt16(10); | 1042 bignum.AssignUInt16(10); |
1005 bignum.ShiftLeft(500); | 1043 bignum.ShiftLeft(500); |
1006 other.AssignUInt16(1); | 1044 other.AssignUInt16(1); |
1007 bignum.AddBignum(other); | 1045 bignum.AddBignum(other); |
1008 other.AssignUInt16(2); | 1046 other.AssignUInt16(2); |
1009 other.ShiftLeft(500); | 1047 other.ShiftLeft(500); |
1010 CHECK_EQ(5, bignum.DivideModuloIntBignum(other)); | 1048 CHECK_EQ(5, bignum.DivideModuloIntBignum(other)); |
1011 CHECK(bignum.ToHexString(buffer, kBufferSize)); | 1049 CHECK(bignum.ToHexString(buffer, kBufferSize)); |
1012 CHECK_EQ("1", buffer); | 1050 CHECK_EQ(0, strcmp("1", buffer)); |
1013 | 1051 |
1014 bignum.AssignUInt16(10); | 1052 bignum.AssignUInt16(10); |
1015 bignum.ShiftLeft(500); | 1053 bignum.ShiftLeft(500); |
1016 other.AssignBignum(bignum); | 1054 other.AssignBignum(bignum); |
1017 bignum.MultiplyByUInt32(0x1234); | 1055 bignum.MultiplyByUInt32(0x1234); |
1018 third.AssignUInt16(0xFFF); | 1056 third.AssignUInt16(0xFFF); |
1019 bignum.AddBignum(third); | 1057 bignum.AddBignum(third); |
1020 CHECK_EQ(0x1234, bignum.DivideModuloIntBignum(other)); | 1058 CHECK_EQ(0x1234, bignum.DivideModuloIntBignum(other)); |
1021 CHECK(bignum.ToHexString(buffer, kBufferSize)); | 1059 CHECK(bignum.ToHexString(buffer, kBufferSize)); |
1022 CHECK_EQ("FFF", buffer); | 1060 CHECK_EQ(0, strcmp("FFF", buffer)); |
1023 | 1061 |
1024 bignum.AssignUInt16(10); | 1062 bignum.AssignUInt16(10); |
1025 AssignHexString(&other, "1234567890"); | 1063 AssignHexString(&other, "1234567890"); |
1026 CHECK_EQ(0, bignum.DivideModuloIntBignum(other)); | 1064 CHECK_EQ(0, bignum.DivideModuloIntBignum(other)); |
1027 CHECK(bignum.ToHexString(buffer, kBufferSize)); | 1065 CHECK(bignum.ToHexString(buffer, kBufferSize)); |
1028 CHECK_EQ("A", buffer); | 1066 CHECK_EQ(0, strcmp("A", buffer)); |
1029 | 1067 |
1030 AssignHexString(&bignum, "12345678"); | 1068 AssignHexString(&bignum, "12345678"); |
1031 AssignHexString(&other, "3789012"); | 1069 AssignHexString(&other, "3789012"); |
1032 CHECK_EQ(5, bignum.DivideModuloIntBignum(other)); | 1070 CHECK_EQ(5, bignum.DivideModuloIntBignum(other)); |
1033 CHECK(bignum.ToHexString(buffer, kBufferSize)); | 1071 CHECK(bignum.ToHexString(buffer, kBufferSize)); |
1034 CHECK_EQ("D9861E", buffer); | 1072 CHECK_EQ(0, strcmp("D9861E", buffer)); |
1035 | 1073 |
1036 AssignHexString(&bignum, "70000001"); | 1074 AssignHexString(&bignum, "70000001"); |
1037 AssignHexString(&other, "1FFFFFFF"); | 1075 AssignHexString(&other, "1FFFFFFF"); |
1038 CHECK_EQ(3, bignum.DivideModuloIntBignum(other)); | 1076 CHECK_EQ(3, bignum.DivideModuloIntBignum(other)); |
1039 CHECK(bignum.ToHexString(buffer, kBufferSize)); | 1077 CHECK(bignum.ToHexString(buffer, kBufferSize)); |
1040 CHECK_EQ("10000004", buffer); | 1078 CHECK_EQ(0, strcmp("10000004", buffer)); |
1041 | 1079 |
1042 AssignHexString(&bignum, "28000000"); | 1080 AssignHexString(&bignum, "28000000"); |
1043 AssignHexString(&other, "12A05F20"); | 1081 AssignHexString(&other, "12A05F20"); |
1044 CHECK_EQ(2, bignum.DivideModuloIntBignum(other)); | 1082 CHECK_EQ(2, bignum.DivideModuloIntBignum(other)); |
1045 CHECK(bignum.ToHexString(buffer, kBufferSize)); | 1083 CHECK(bignum.ToHexString(buffer, kBufferSize)); |
1046 CHECK_EQ("2BF41C0", buffer); | 1084 CHECK_EQ(0, strcmp("2BF41C0", buffer)); |
1047 | 1085 |
1048 bignum.AssignUInt16(10); | 1086 bignum.AssignUInt16(10); |
1049 bignum.ShiftLeft(500); | 1087 bignum.ShiftLeft(500); |
1050 other.AssignBignum(bignum); | 1088 other.AssignBignum(bignum); |
1051 bignum.MultiplyByUInt32(0x1234); | 1089 bignum.MultiplyByUInt32(0x1234); |
1052 third.AssignUInt16(0xFFF); | 1090 third.AssignUInt16(0xFFF); |
1053 other.SubtractBignum(third); | 1091 other.SubtractBignum(third); |
1054 CHECK_EQ(0x1234, bignum.DivideModuloIntBignum(other)); | 1092 CHECK_EQ(0x1234, bignum.DivideModuloIntBignum(other)); |
1055 CHECK(bignum.ToHexString(buffer, kBufferSize)); | 1093 CHECK(bignum.ToHexString(buffer, kBufferSize)); |
1056 CHECK_EQ("1232DCC", buffer); | 1094 CHECK_EQ(0, strcmp("1232DCC", buffer)); |
1057 CHECK_EQ(0, bignum.DivideModuloIntBignum(other)); | 1095 CHECK_EQ(0, bignum.DivideModuloIntBignum(other)); |
1058 CHECK(bignum.ToHexString(buffer, kBufferSize)); | 1096 CHECK(bignum.ToHexString(buffer, kBufferSize)); |
1059 CHECK_EQ("1232DCC", buffer); | 1097 CHECK_EQ(0, strcmp("1232DCC", buffer)); |
1060 } | 1098 } |
1061 | 1099 |
1062 | 1100 |
1063 TEST(Compare) { | 1101 TEST(Compare) { |
1064 Bignum bignum1; | 1102 Bignum bignum1; |
1065 Bignum bignum2; | 1103 Bignum bignum2; |
1066 bignum1.AssignUInt16(1); | 1104 bignum1.AssignUInt16(1); |
1067 bignum2.AssignUInt16(1); | 1105 bignum2.AssignUInt16(1); |
1068 CHECK_EQ(0, Bignum::Compare(bignum1, bignum2)); | 1106 CHECK_EQ(0, Bignum::Compare(bignum1, bignum2)); |
1069 CHECK(Bignum::Equal(bignum1, bignum2)); | 1107 CHECK(Bignum::Equal(bignum1, bignum2)); |
(...skipping 286 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1356 } | 1394 } |
1357 | 1395 |
1358 | 1396 |
1359 TEST(Square) { | 1397 TEST(Square) { |
1360 Bignum bignum; | 1398 Bignum bignum; |
1361 char buffer[kBufferSize]; | 1399 char buffer[kBufferSize]; |
1362 | 1400 |
1363 bignum.AssignUInt16(1); | 1401 bignum.AssignUInt16(1); |
1364 bignum.Square(); | 1402 bignum.Square(); |
1365 CHECK(bignum.ToHexString(buffer, kBufferSize)); | 1403 CHECK(bignum.ToHexString(buffer, kBufferSize)); |
1366 CHECK_EQ("1", buffer); | 1404 CHECK_EQ(0, strcmp("1", buffer)); |
1367 | 1405 |
1368 bignum.AssignUInt16(2); | 1406 bignum.AssignUInt16(2); |
1369 bignum.Square(); | 1407 bignum.Square(); |
1370 CHECK(bignum.ToHexString(buffer, kBufferSize)); | 1408 CHECK(bignum.ToHexString(buffer, kBufferSize)); |
1371 CHECK_EQ("4", buffer); | 1409 CHECK_EQ(0, strcmp("4", buffer)); |
1372 | 1410 |
1373 bignum.AssignUInt16(10); | 1411 bignum.AssignUInt16(10); |
1374 bignum.Square(); | 1412 bignum.Square(); |
1375 CHECK(bignum.ToHexString(buffer, kBufferSize)); | 1413 CHECK(bignum.ToHexString(buffer, kBufferSize)); |
1376 CHECK_EQ("64", buffer); | 1414 CHECK_EQ(0, strcmp("64", buffer)); |
1377 | 1415 |
1378 AssignHexString(&bignum, "FFFFFFF"); | 1416 AssignHexString(&bignum, "FFFFFFF"); |
1379 bignum.Square(); | 1417 bignum.Square(); |
1380 CHECK(bignum.ToHexString(buffer, kBufferSize)); | 1418 CHECK(bignum.ToHexString(buffer, kBufferSize)); |
1381 CHECK_EQ("FFFFFFE0000001", buffer); | 1419 CHECK_EQ(0, strcmp("FFFFFFE0000001", buffer)); |
1382 | 1420 |
1383 AssignHexString(&bignum, "FFFFFFFFFFFFFF"); | 1421 AssignHexString(&bignum, "FFFFFFFFFFFFFF"); |
1384 bignum.Square(); | 1422 bignum.Square(); |
1385 CHECK(bignum.ToHexString(buffer, kBufferSize)); | 1423 CHECK(bignum.ToHexString(buffer, kBufferSize)); |
1386 CHECK_EQ("FFFFFFFFFFFFFE00000000000001", buffer); | 1424 CHECK_EQ(0, strcmp("FFFFFFFFFFFFFE00000000000001", buffer)); |
1387 } | 1425 } |
1388 | 1426 |
1389 | 1427 |
1390 TEST(AssignPowerUInt16) { | 1428 TEST(AssignPowerUInt16) { |
1391 Bignum bignum; | 1429 Bignum bignum; |
1392 char buffer[kBufferSize]; | 1430 char buffer[kBufferSize]; |
1393 | 1431 |
1394 bignum.AssignPowerUInt16(1, 0); | 1432 bignum.AssignPowerUInt16(1, 0); |
1395 CHECK(bignum.ToHexString(buffer, kBufferSize)); | 1433 CHECK(bignum.ToHexString(buffer, kBufferSize)); |
1396 CHECK_EQ("1", buffer); | 1434 CHECK_EQ(0, strcmp("1", buffer)); |
1397 | 1435 |
1398 bignum.AssignPowerUInt16(1, 1); | 1436 bignum.AssignPowerUInt16(1, 1); |
1399 CHECK(bignum.ToHexString(buffer, kBufferSize)); | 1437 CHECK(bignum.ToHexString(buffer, kBufferSize)); |
1400 CHECK_EQ("1", buffer); | 1438 CHECK_EQ(0, strcmp("1", buffer)); |
1401 | 1439 |
1402 bignum.AssignPowerUInt16(1, 2); | 1440 bignum.AssignPowerUInt16(1, 2); |
1403 CHECK(bignum.ToHexString(buffer, kBufferSize)); | 1441 CHECK(bignum.ToHexString(buffer, kBufferSize)); |
1404 CHECK_EQ("1", buffer); | 1442 CHECK_EQ(0, strcmp("1", buffer)); |
1405 | 1443 |
1406 bignum.AssignPowerUInt16(2, 0); | 1444 bignum.AssignPowerUInt16(2, 0); |
1407 CHECK(bignum.ToHexString(buffer, kBufferSize)); | 1445 CHECK(bignum.ToHexString(buffer, kBufferSize)); |
1408 CHECK_EQ("1", buffer); | 1446 CHECK_EQ(0, strcmp("1", buffer)); |
1409 | 1447 |
1410 bignum.AssignPowerUInt16(2, 1); | 1448 bignum.AssignPowerUInt16(2, 1); |
1411 CHECK(bignum.ToHexString(buffer, kBufferSize)); | 1449 CHECK(bignum.ToHexString(buffer, kBufferSize)); |
1412 CHECK_EQ("2", buffer); | 1450 CHECK_EQ(0, strcmp("2", buffer)); |
1413 | 1451 |
1414 bignum.AssignPowerUInt16(2, 2); | 1452 bignum.AssignPowerUInt16(2, 2); |
1415 CHECK(bignum.ToHexString(buffer, kBufferSize)); | 1453 CHECK(bignum.ToHexString(buffer, kBufferSize)); |
1416 CHECK_EQ("4", buffer); | 1454 CHECK_EQ(0, strcmp("4", buffer)); |
1417 | 1455 |
1418 bignum.AssignPowerUInt16(16, 1); | 1456 bignum.AssignPowerUInt16(16, 1); |
1419 CHECK(bignum.ToHexString(buffer, kBufferSize)); | 1457 CHECK(bignum.ToHexString(buffer, kBufferSize)); |
1420 CHECK_EQ("10", buffer); | 1458 CHECK_EQ(0, strcmp("10", buffer)); |
1421 | 1459 |
1422 bignum.AssignPowerUInt16(16, 2); | 1460 bignum.AssignPowerUInt16(16, 2); |
1423 CHECK(bignum.ToHexString(buffer, kBufferSize)); | 1461 CHECK(bignum.ToHexString(buffer, kBufferSize)); |
1424 CHECK_EQ("100", buffer); | 1462 CHECK_EQ(0, strcmp("100", buffer)); |
1425 | 1463 |
1426 bignum.AssignPowerUInt16(16, 5); | 1464 bignum.AssignPowerUInt16(16, 5); |
1427 CHECK(bignum.ToHexString(buffer, kBufferSize)); | 1465 CHECK(bignum.ToHexString(buffer, kBufferSize)); |
1428 CHECK_EQ("100000", buffer); | 1466 CHECK_EQ(0, strcmp("100000", buffer)); |
1429 | 1467 |
1430 bignum.AssignPowerUInt16(16, 8); | 1468 bignum.AssignPowerUInt16(16, 8); |
1431 CHECK(bignum.ToHexString(buffer, kBufferSize)); | 1469 CHECK(bignum.ToHexString(buffer, kBufferSize)); |
1432 CHECK_EQ("100000000", buffer); | 1470 CHECK_EQ(0, strcmp("100000000", buffer)); |
1433 | 1471 |
1434 bignum.AssignPowerUInt16(16, 16); | 1472 bignum.AssignPowerUInt16(16, 16); |
1435 CHECK(bignum.ToHexString(buffer, kBufferSize)); | 1473 CHECK(bignum.ToHexString(buffer, kBufferSize)); |
1436 CHECK_EQ("10000000000000000", buffer); | 1474 CHECK_EQ(0, strcmp("10000000000000000", buffer)); |
1437 | 1475 |
1438 bignum.AssignPowerUInt16(16, 30); | 1476 bignum.AssignPowerUInt16(16, 30); |
1439 CHECK(bignum.ToHexString(buffer, kBufferSize)); | 1477 CHECK(bignum.ToHexString(buffer, kBufferSize)); |
1440 CHECK_EQ("1000000000000000000000000000000", buffer); | 1478 CHECK_EQ(0, strcmp("1000000000000000000000000000000", buffer)); |
1441 | 1479 |
1442 bignum.AssignPowerUInt16(10, 0); | 1480 bignum.AssignPowerUInt16(10, 0); |
1443 CHECK(bignum.ToHexString(buffer, kBufferSize)); | 1481 CHECK(bignum.ToHexString(buffer, kBufferSize)); |
1444 CHECK_EQ("1", buffer); | 1482 CHECK_EQ(0, strcmp("1", buffer)); |
1445 | 1483 |
1446 bignum.AssignPowerUInt16(10, 1); | 1484 bignum.AssignPowerUInt16(10, 1); |
1447 CHECK(bignum.ToHexString(buffer, kBufferSize)); | 1485 CHECK(bignum.ToHexString(buffer, kBufferSize)); |
1448 CHECK_EQ("A", buffer); | 1486 CHECK_EQ(0, strcmp("A", buffer)); |
1449 | 1487 |
1450 bignum.AssignPowerUInt16(10, 2); | 1488 bignum.AssignPowerUInt16(10, 2); |
1451 CHECK(bignum.ToHexString(buffer, kBufferSize)); | 1489 CHECK(bignum.ToHexString(buffer, kBufferSize)); |
1452 CHECK_EQ("64", buffer); | 1490 CHECK_EQ(0, strcmp("64", buffer)); |
1453 | 1491 |
1454 bignum.AssignPowerUInt16(10, 5); | 1492 bignum.AssignPowerUInt16(10, 5); |
1455 CHECK(bignum.ToHexString(buffer, kBufferSize)); | 1493 CHECK(bignum.ToHexString(buffer, kBufferSize)); |
1456 CHECK_EQ("186A0", buffer); | 1494 CHECK_EQ(0, strcmp("186A0", buffer)); |
1457 | 1495 |
1458 bignum.AssignPowerUInt16(10, 8); | 1496 bignum.AssignPowerUInt16(10, 8); |
1459 CHECK(bignum.ToHexString(buffer, kBufferSize)); | 1497 CHECK(bignum.ToHexString(buffer, kBufferSize)); |
1460 CHECK_EQ("5F5E100", buffer); | 1498 CHECK_EQ(0, strcmp("5F5E100", buffer)); |
1461 | 1499 |
1462 bignum.AssignPowerUInt16(10, 16); | 1500 bignum.AssignPowerUInt16(10, 16); |
1463 CHECK(bignum.ToHexString(buffer, kBufferSize)); | 1501 CHECK(bignum.ToHexString(buffer, kBufferSize)); |
1464 CHECK_EQ("2386F26FC10000", buffer); | 1502 CHECK_EQ(0, strcmp("2386F26FC10000", buffer)); |
1465 | 1503 |
1466 bignum.AssignPowerUInt16(10, 30); | 1504 bignum.AssignPowerUInt16(10, 30); |
1467 CHECK(bignum.ToHexString(buffer, kBufferSize)); | 1505 CHECK(bignum.ToHexString(buffer, kBufferSize)); |
1468 CHECK_EQ("C9F2C9CD04674EDEA40000000", buffer); | 1506 CHECK_EQ(0, strcmp("C9F2C9CD04674EDEA40000000", buffer)); |
1469 | 1507 |
1470 bignum.AssignPowerUInt16(10, 31); | 1508 bignum.AssignPowerUInt16(10, 31); |
1471 CHECK(bignum.ToHexString(buffer, kBufferSize)); | 1509 CHECK(bignum.ToHexString(buffer, kBufferSize)); |
1472 CHECK_EQ("7E37BE2022C0914B2680000000", buffer); | 1510 CHECK_EQ(0, strcmp("7E37BE2022C0914B2680000000", buffer)); |
1473 | 1511 |
1474 bignum.AssignPowerUInt16(2, 0); | 1512 bignum.AssignPowerUInt16(2, 0); |
1475 CHECK(bignum.ToHexString(buffer, kBufferSize)); | 1513 CHECK(bignum.ToHexString(buffer, kBufferSize)); |
1476 CHECK_EQ("1", buffer); | 1514 CHECK_EQ(0, strcmp("1", buffer)); |
1477 | 1515 |
1478 bignum.AssignPowerUInt16(2, 100); | 1516 bignum.AssignPowerUInt16(2, 100); |
1479 CHECK(bignum.ToHexString(buffer, kBufferSize)); | 1517 CHECK(bignum.ToHexString(buffer, kBufferSize)); |
1480 CHECK_EQ("10000000000000000000000000", buffer); | 1518 CHECK_EQ(0, strcmp("10000000000000000000000000", buffer)); |
1481 | 1519 |
1482 bignum.AssignPowerUInt16(17, 0); | 1520 bignum.AssignPowerUInt16(17, 0); |
1483 CHECK(bignum.ToHexString(buffer, kBufferSize)); | 1521 CHECK(bignum.ToHexString(buffer, kBufferSize)); |
1484 CHECK_EQ("1", buffer); | 1522 CHECK_EQ(0, strcmp("1", buffer)); |
1485 | 1523 |
1486 bignum.AssignPowerUInt16(17, 99); | 1524 bignum.AssignPowerUInt16(17, 99); |
1487 CHECK(bignum.ToHexString(buffer, kBufferSize)); | 1525 CHECK(bignum.ToHexString(buffer, kBufferSize)); |
1488 CHECK_EQ("1942BB9853FAD924A3D4DD92B89B940E0207BEF05DB9C26BC1B757" | 1526 CHECK_EQ(0, strcmp( |
1489 "80BE0C5A2C2990E02A681224F34ED68558CE4C6E33760931", | 1527 "1942BB9853FAD924A3D4DD92B89B940E0207BEF05DB9C26BC1B757" |
1490 buffer); | 1528 "80BE0C5A2C2990E02A681224F34ED68558CE4C6E33760931", |
| 1529 buffer)); |
1491 | 1530 |
1492 bignum.AssignPowerUInt16(0xFFFF, 99); | 1531 bignum.AssignPowerUInt16(0xFFFF, 99); |
1493 CHECK(bignum.ToHexString(buffer, kBufferSize)); | 1532 CHECK(bignum.ToHexString(buffer, kBufferSize)); |
1494 CHECK_EQ("FF9D12F09B886C54E77E7439C7D2DED2D34F669654C0C2B6B8C288250" | 1533 CHECK_EQ(0, strcmp( |
1495 "5A2211D0E3DC9A61831349EAE674B11D56E3049D7BD79DAAD6C9FA2BA" | 1534 "FF9D12F09B886C54E77E7439C7D2DED2D34F669654C0C2B6B8C288250" |
1496 "528E3A794299F2EE9146A324DAFE3E88967A0358233B543E233E575B9" | 1535 "5A2211D0E3DC9A61831349EAE674B11D56E3049D7BD79DAAD6C9FA2BA" |
1497 "DD4E3AA7942146426C328FF55BFD5C45E0901B1629260AF9AE2F310C5" | 1536 "528E3A794299F2EE9146A324DAFE3E88967A0358233B543E233E575B9" |
1498 "50959FAF305C30116D537D80CF6EBDBC15C5694062AF1AC3D956D0A41" | 1537 "DD4E3AA7942146426C328FF55BFD5C45E0901B1629260AF9AE2F310C5" |
1499 "B7E1B79FF11E21D83387A1CE1F5882B31E4B5D8DE415BDBE6854466DF" | 1538 "50959FAF305C30116D537D80CF6EBDBC15C5694062AF1AC3D956D0A41" |
1500 "343362267A7E8833119D31D02E18DB5B0E8F6A64B0ED0D0062FFFF", | 1539 "B7E1B79FF11E21D83387A1CE1F5882B31E4B5D8DE415BDBE6854466DF" |
1501 buffer); | 1540 "343362267A7E8833119D31D02E18DB5B0E8F6A64B0ED0D0062FFFF", |
| 1541 buffer)); |
1502 } | 1542 } |
OLD | NEW |