|
1 // Copyright (c) 1995-2009 Nokia Corporation and/or its subsidiary(-ies). |
|
2 // All rights reserved. |
|
3 // This component and the accompanying materials are made available |
|
4 // under the terms of the License "Eclipse Public License v1.0" |
|
5 // which accompanies this distribution, and is available |
|
6 // at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
7 // |
|
8 // Initial Contributors: |
|
9 // Nokia Corporation - initial contribution. |
|
10 // |
|
11 // Contributors: |
|
12 // |
|
13 // Description: |
|
14 // e32test\math\t_i64.cpp |
|
15 // Tests TInt64 |
|
16 // Overview: |
|
17 // Test 64-bit integer functionality. |
|
18 // API Information: |
|
19 // TInt64. |
|
20 // Details: |
|
21 // - Construct TInt64 with specified range of integer, real, high |
|
22 // and low values and check constructor, copy constructor are as expected. |
|
23 // - Test all the operators for range of values and check it is as expected. |
|
24 // - Check the logical shift of specified number of bits is as expected. |
|
25 // - Check multiplication of 64 bit integer by the specified 64 bit integer |
|
26 // using MulTop, fast multiplication of 64 bit integer by 10. |
|
27 // - Verify the 64 bit integer divide and mod results are as expected. |
|
28 // Platforms/Drives/Compatibility: |
|
29 // All. |
|
30 // Assumptions/Requirement/Pre-requisites: |
|
31 // Failures and causes: |
|
32 // Base Port information: |
|
33 // |
|
34 // |
|
35 |
|
36 #include <e32test.h> |
|
37 #include <e32math.h> |
|
38 |
|
39 inline TInt __i64multop(TInt64& aX, TInt64& aValue) |
|
40 { Uint64 __lowResult; \ |
|
41 Uint64 __highResult; \ |
|
42 Math::UMul64(aX, aValue, __highResult, __lowResult); \ |
|
43 aX = static_cast<TInt64>(__highResult); \ |
|
44 return (__lowResult == UI64LIT(0x0000000000000000)) ? -2 : \ |
|
45 (__lowResult < UI64LIT(0x8000000000000000)) ? -1 : \ |
|
46 (__lowResult == UI64LIT(0x8000000000000000)) ? 0 : \ |
|
47 /*__lowResult > UI64LIT(0x8000000000000000)*/ 1; \ |
|
48 } |
|
49 |
|
50 #define I64MULTOP(x, value) __i64multop(x, (value)) |
|
51 |
|
52 |
|
53 TInt HexMulAdd(TUint8 a1,TUint8 a2,TUint8& answer,TUint8& carry) |
|
54 { |
|
55 TUint x1= a1>'9' ? a1-'a'+10 : a1-'0'; |
|
56 TUint x2= a2>'9' ? a2-'a'+10 : a2-'0'; |
|
57 TUint a= answer>'9' ? answer-'a'+10 : answer-'0'; |
|
58 TUint c= carry>'9' ? carry-'a'+10 : carry-'0'; |
|
59 if (x1>15) return (KErrArgument); |
|
60 if (x2>15) return (KErrArgument); |
|
61 if (a>15) return (KErrArgument); |
|
62 if (c>15) return (KErrArgument); |
|
63 a+=(x1*x2)+c; |
|
64 c=a/16; |
|
65 a=a%16; |
|
66 a= a>9 ? a-10+'a' : a+'0'; |
|
67 c= c>9 ? c-10+'a' : c+'0'; |
|
68 answer=(TUint8)a; |
|
69 carry=(TUint8)c; |
|
70 return(KErrNone); |
|
71 } |
|
72 |
|
73 TInt HexMul(TDesC8& a1,TDesC8& a2,TDes8& a3) |
|
74 // |
|
75 // Infinite precision hex multiplier |
|
76 // |
|
77 { |
|
78 TInt l1=a1.Length(); |
|
79 TInt l2=a2.Length(); |
|
80 TInt l3=l1+l2; |
|
81 if (a3.MaxLength()<l3) |
|
82 return(KErrArgument); |
|
83 a3.Zero(); |
|
84 TInt x; |
|
85 TInt y; |
|
86 TInt z; |
|
87 for (x=0;x<l3;x++) |
|
88 a3.Append('0'); |
|
89 for (y=0;y<l2;y++) |
|
90 { |
|
91 TUint8 carry='0'; |
|
92 for (z=0;z<l1;z++) |
|
93 { |
|
94 if(HexMulAdd(a2[l2-y-1],a1[l1-z-1],a3[l3-y-z-1],carry)!=KErrNone) |
|
95 return(KErrArgument); |
|
96 } |
|
97 if(HexMulAdd('0','0',a3[l3-y-l1-1],carry)!=KErrNone) |
|
98 return(KErrArgument); |
|
99 } |
|
100 return(KErrNone); |
|
101 } |
|
102 |
|
103 |
|
104 LOCAL_D RTest test(_L("T_I64")); |
|
105 |
|
106 LOCAL_C void SlowDivMod(const TInt64& aA, const TInt64& aB, TInt64& aDiv, TInt64& aMod) |
|
107 // |
|
108 // Calculate Division/Remainder using repeated subtraction |
|
109 // |
|
110 { |
|
111 TInt negative=0; |
|
112 TInt64 t=0; |
|
113 |
|
114 if (aA<0) |
|
115 { |
|
116 negative=1; |
|
117 aMod=-aA; |
|
118 } |
|
119 else |
|
120 { |
|
121 aMod=aA; |
|
122 } |
|
123 if (aB<0) |
|
124 { |
|
125 if (negative) |
|
126 negative=0; |
|
127 else |
|
128 negative=1; |
|
129 t=-aB; |
|
130 } |
|
131 else |
|
132 { |
|
133 t=aB; |
|
134 } |
|
135 aDiv=0; |
|
136 |
|
137 if ((t & UI64LIT(0xffffffff00000000)) == 0) |
|
138 { |
|
139 while (aMod >= (t << 31)) |
|
140 { |
|
141 aDiv += static_cast<TUint32>(1 << 31); |
|
142 aMod -= t << 31; |
|
143 } |
|
144 } |
|
145 if ((t & UI64LIT(0xffffff0000000000)) == 0) |
|
146 { |
|
147 while (aMod >= (t << 23)) |
|
148 { |
|
149 aDiv += 1 << 23; |
|
150 aMod -= t << 23; |
|
151 } |
|
152 } |
|
153 if ((t & UI64LIT(0xffff000000000000)) == 0) |
|
154 { |
|
155 while (aMod >= (t << 15)) |
|
156 { |
|
157 aDiv += 1 << 15; |
|
158 aMod -= t << 15; |
|
159 } |
|
160 } |
|
161 if ((t & UI64LIT(0xff00000000000000)) == 0) |
|
162 { |
|
163 while (aMod >= (t << 7)) |
|
164 { |
|
165 aDiv += 1 << 7; |
|
166 aMod -= t << 7; |
|
167 } |
|
168 } |
|
169 if ((t & UI64LIT(0xf000000000000000)) == 0) |
|
170 { |
|
171 while (aMod >= (t << 3)) |
|
172 { |
|
173 aDiv += 1 << 3; |
|
174 aMod -= t << 3; |
|
175 } |
|
176 } |
|
177 while (aMod >= t) |
|
178 { |
|
179 ++aDiv; |
|
180 aMod -= t; |
|
181 } |
|
182 |
|
183 if (negative) |
|
184 { |
|
185 aDiv=-aDiv; |
|
186 } |
|
187 |
|
188 if (aA < 0) |
|
189 { |
|
190 aMod =- aMod; |
|
191 } |
|
192 } |
|
193 |
|
194 LOCAL_C void DivModTest(const TInt64& aA, const TInt64& aB) |
|
195 // |
|
196 // Test DivMod against SlowDivMod |
|
197 // |
|
198 { |
|
199 |
|
200 if (aB!=0) |
|
201 { |
|
202 TInt64 n(aA),d(aB); |
|
203 TInt64 div=0,mod=0,res=0; |
|
204 |
|
205 SlowDivMod(n,d,div,mod); |
|
206 |
|
207 res = n % d; |
|
208 n /= d; |
|
209 |
|
210 test(n==div); |
|
211 test(res==mod); |
|
212 } |
|
213 } |
|
214 |
|
215 |
|
216 LOCAL_C void Test1() |
|
217 { |
|
218 // Test the constructors |
|
219 |
|
220 // TInt64() |
|
221 test.Start(_L("Default constructor")); |
|
222 TInt64 t1; |
|
223 t1 = 0; // to prevent uninitialised warnings |
|
224 (void)(t1 > 0); // to prevent unused warnings |
|
225 |
|
226 // TInt64(TInt aVal) |
|
227 test.Next(_L("TInt64(TInt aVal)")); |
|
228 TInt64 t2(0); |
|
229 test(I64LOW(t2)==0 && I64HIGH(t2)==0); |
|
230 TInt64 t3(1); |
|
231 test(I64LOW(t3)==1 && I64HIGH(t3)==0); |
|
232 TInt64 t4(KMaxTInt32); |
|
233 test(I64LOW(t4)==(TUint)KMaxTInt32 && I64HIGH(t4)==0); |
|
234 TInt64 t5(-1); |
|
235 test(I64INT(t5)==-1); |
|
236 test(I64LOW(t5)==KMaxTUint32 && I64HIGH(t5)==KMaxTUint32); |
|
237 TInt64 t6(KMinTInt32); |
|
238 test(I64INT(t6)==KMinTInt32); |
|
239 |
|
240 // TInt64(TUint aVal) |
|
241 test.Next(_L("TInt64(TUint aVal)")); |
|
242 TInt64 t7((TUint)0); |
|
243 test(I64LOW(t7)==0 && I64HIGH(t7)==0); |
|
244 TInt64 t8((TUint)1); |
|
245 test(I64LOW(t8)==1 && I64HIGH(t8)==0); |
|
246 TInt64 t9(KMaxTUint32); |
|
247 test(I64LOW(t9)==KMaxTUint32 && I64HIGH(t9)==0); |
|
248 |
|
249 // TInt64(TUint aHigh,TUint aLow) |
|
250 test.Next(_L("TInt64(TUint aHigh,TUint aLow)")); |
|
251 TInt64 t10 = MAKE_TINT64(0,0); |
|
252 test(I64LOW(t10)==0 && I64HIGH(t10)==0); |
|
253 TInt64 t11 = MAKE_TINT64(KMaxTUint32,KMaxTUint32); // highest value stored === (2**64)-1 |
|
254 test(I64LOW(t11)==KMaxTUint32 && I64HIGH(t11)==KMaxTUint32); |
|
255 |
|
256 // TInt64(TReal aVal) |
|
257 test.Next(_L("TInt64(TReal aVal)")); |
|
258 TInt64 t12((TInt64)1.0); |
|
259 test(I64LOW(t12)==1 && I64HIGH(t12)==0); |
|
260 TInt64 t15((TInt64)4.99); |
|
261 test(I64LOW(t15)==4 && I64HIGH(t15)==0); |
|
262 |
|
263 TReal x; |
|
264 |
|
265 x = -9.223372036854776831e18; // -2^63 - 2^10 (to ensure rounding outside of TInt64 range) |
|
266 TInt64 t16((TInt64)x); |
|
267 test(t16==KMinTInt64); |
|
268 TInt64 t17((TInt64)0.5); |
|
269 test(I64LOW(t17)==0 && I64HIGH(t17)==0); |
|
270 TInt64 t18((TInt64)0.0); |
|
271 test(I64LOW(t18)==0 && I64HIGH(t18)==0); |
|
272 TInt64 t19((TInt64)-123325.23411412); |
|
273 test(I64LOW(t19)==(TUint)(-123325) && I64HIGH(t19)==0xffffffff); |
|
274 TInt64 t20((TInt64)1.0E-1); |
|
275 test(I64LOW(t20)==0 && I64HIGH(t20)==0); |
|
276 |
|
277 x = 9.223372036854776831e18; // 2^63 + 2^10 (to ensure rounding outside of TInt64 range) |
|
278 TInt64 t21((TInt64)x); |
|
279 |
|
280 // IEEE 754 does not specify the value to be returned when a conversion |
|
281 // is performed on a value that is outside the range of the target, only |
|
282 // that an invalid operation exception be raised if the io fp exception |
|
283 // is not masked. |
|
284 #if defined(__WINS__) || defined(__X86__) |
|
285 // The x86 FPU returns KMin... as the "indefinite number" |
|
286 test(t21 == KMinTInt64); |
|
287 #else |
|
288 // The target compiler support libraries return KMax... |
|
289 test(t21 == KMaxTInt64); |
|
290 #endif |
|
291 |
|
292 TReal limit=1048576.0*1048576.0*8192.0; // integers <2^53 in modulus can be represented exactly |
|
293 TInt64 t22((TInt64)limit); |
|
294 test(I64LOW(t22)==0 && I64HIGH(t22)==0x00200000); |
|
295 TInt64 t23((TInt64)(limit-1.0)); |
|
296 test(I64LOW(t23)==0xffffffff && I64HIGH(t23)==0x001fffff); |
|
297 TReal i64limit=limit*1024.0; // 2^63 |
|
298 TInt64 t24((TInt64)i64limit); |
|
299 |
|
300 // IEEE 754 does not specify the value to be returned when a conversion |
|
301 // is performed on a value that is outside the range of the target, only |
|
302 // that an invalid operation exception be raised if the io fp exception |
|
303 // is not masked. |
|
304 #if defined(__WINS__) || defined(__X86__) |
|
305 // The x86 FPU returns KMin... as the "indefinite number" |
|
306 test(t24 == KMinTInt64); |
|
307 #else |
|
308 // The target compiler support libraries return KMax... |
|
309 test(t24 == KMaxTInt64); |
|
310 #endif |
|
311 |
|
312 TInt64 t25((TInt64)(i64limit-1024.0)); |
|
313 test(I64LOW(t25)==0xfffffc00 && I64HIGH(t25)==0x7fffffff); |
|
314 TInt64 t26((TInt64)-i64limit); |
|
315 test(I64LOW(t26)==0x00000000 && I64HIGH(t26)==0x80000000); |
|
316 TInt64 t27((TInt64)(1024.0-i64limit)); |
|
317 test(I64LOW(t27)==0x00000400 && I64HIGH(t27)==0x80000000); |
|
318 |
|
319 |
|
320 TInt i; |
|
321 TInt64 l; |
|
322 for (i=-99; i<100; i++) |
|
323 { |
|
324 x=1; |
|
325 l=1; |
|
326 TReal a(i); |
|
327 TInt64 b(i); |
|
328 while (Abs(x)<limit) |
|
329 { |
|
330 // test.Printf(_L("Testing %g\n"),x); |
|
331 TInt64 ll((TInt64)x); |
|
332 test(ll==l); |
|
333 ll=0; |
|
334 ll = (TInt64)x; |
|
335 test(ll==l); |
|
336 x*=a; |
|
337 l*=b; |
|
338 if (i==1 || i==0 || (i==-1 && l==TInt64(1))) |
|
339 break; |
|
340 } |
|
341 } |
|
342 |
|
343 // TInt64::GetTReal |
|
344 test.Next(_L("TInt64::GetTReal")); |
|
345 |
|
346 l = MAKE_TINT64(0x7fffffff,0xffffffff); |
|
347 x = I64REAL(l); |
|
348 |
|
349 TReal xx = i64limit - 1.0; |
|
350 test(x == xx); |
|
351 |
|
352 l = MAKE_TINT64(0x7fffffff,0xfffffc00); |
|
353 x = I64REAL(l); |
|
354 |
|
355 test(x == (i64limit - 1024.0)); |
|
356 |
|
357 l = MAKE_TINT64(0x80000000,0x00000000); |
|
358 x = I64REAL(l); |
|
359 |
|
360 test(x == -i64limit); |
|
361 |
|
362 l = MAKE_TINT64(0x80000000,0x00000400); |
|
363 x = I64REAL(l); |
|
364 |
|
365 test(x == (1024.0 - i64limit)); |
|
366 |
|
367 l = MAKE_TINT64(0x00000001,0x00000000); |
|
368 x = I64REAL(l); |
|
369 |
|
370 test(x == (65536.0 * 65536.0)); |
|
371 |
|
372 l = MAKE_TINT64(0xffffffff,0x00000000); |
|
373 x = I64REAL(l); |
|
374 |
|
375 test(x == (-65536.0 * 65536.0)); |
|
376 |
|
377 for (i=-99; i<100; i++) |
|
378 { |
|
379 x=1; |
|
380 l=1; |
|
381 TReal a(i); |
|
382 TInt64 b(i); |
|
383 while (Abs(x)<limit) |
|
384 { |
|
385 // test.Printf(_L("Testing %g\n"),x); |
|
386 TReal y = I64REAL(l); |
|
387 test(y==x); |
|
388 x*=a; |
|
389 l*=b; |
|
390 if (i==1 || i==0 || (i==-1 && l==TInt64(1))) |
|
391 break; |
|
392 } |
|
393 } |
|
394 |
|
395 // TInt64(const TInt64& aVal) |
|
396 test.Next(_L("Copy constructor")); |
|
397 TInt64 t13(t10); |
|
398 test(I64LOW(t13)==I64LOW(t10) && I64HIGH(t13)==I64HIGH(t10)); |
|
399 |
|
400 test.Next(_L("Set")); |
|
401 t13 = MAKE_TINT64(0, 0); |
|
402 test(I64LOW(t13)==0 && I64HIGH(t13)==0); |
|
403 test.End(); |
|
404 } |
|
405 |
|
406 LOCAL_C void Test1_2() |
|
407 // |
|
408 // Test Unary operators -, and + |
|
409 // |
|
410 { |
|
411 TInt64 r(0),q(0); |
|
412 |
|
413 r=1; |
|
414 test(-r==-1); |
|
415 test(+r==1); |
|
416 r=-100; |
|
417 test(-r==100); |
|
418 test(+r==-100); |
|
419 r = MAKE_TINT64(540423,21344); |
|
420 test(-r==(q-r)); |
|
421 test(+r==r); |
|
422 test(+r==MAKE_TINT64(540423,21344)); |
|
423 r=0; |
|
424 test(-r==0); |
|
425 test(+r==0); |
|
426 } |
|
427 |
|
428 |
|
429 LOCAL_C void Test2() |
|
430 { |
|
431 // Test the operators |
|
432 |
|
433 // = |
|
434 test.Start(_L("=")); |
|
435 TInt64 r=0,r2=0, a = MAKE_TINT64(12345,54321); |
|
436 r=KMaxTInt32; |
|
437 test(I64LOW(r)==(TUint)KMaxTInt32 && I64HIGH(r)==0); |
|
438 r2=r=KMinTInt32; |
|
439 test(I64INT(r)==KMinTInt32); |
|
440 test(I64INT(r2)==KMinTInt32); |
|
441 r2=r=KMaxTUint32; |
|
442 test(I64LOW(r)==KMaxTUint32 && I64HIGH(r)==0); |
|
443 test(I64LOW(r2)==KMaxTUint32 && I64HIGH(r2)==0); |
|
444 r2=r=a; |
|
445 test(I64LOW(r)==I64LOW(a) && I64HIGH(r)==I64HIGH(a)); |
|
446 test(I64LOW(r2)==I64LOW(a) && I64HIGH(r2)==I64HIGH(a)); |
|
447 |
|
448 r2=r=(TInt64)((TReal)1.2); |
|
449 test(r==1); |
|
450 test(r2==1); |
|
451 r2=r=(TInt64)((TReal)20.9); |
|
452 test(r==20); |
|
453 test(r2==20); |
|
454 r2=r=(TInt64)((TReal)-100.2); |
|
455 test(r==-100); |
|
456 test(r2==-100); |
|
457 |
|
458 |
|
459 |
|
460 // +=, -=, *=, /=, %=, >>=, <<=, >>, << |
|
461 // += |
|
462 test.Next(_L("+=")); |
|
463 r=-1; |
|
464 r+=1; |
|
465 test(I64INT(r)==0); |
|
466 |
|
467 r+=1; |
|
468 test(I64INT(r)==1); |
|
469 |
|
470 r=KMaxTUint32; |
|
471 r+=1; |
|
472 test(I64INT(r)-1==(TInt)KMaxTUint32); |
|
473 |
|
474 r=KMinTInt32; |
|
475 r+=1; |
|
476 test(I64INT(r)==KMinTInt32+1); |
|
477 |
|
478 r=0; |
|
479 r+=MAKE_TINT64(0,0x80000000u); |
|
480 test(r==MAKE_TINT64(0,0x80000000u)); |
|
481 |
|
482 // -= |
|
483 test.Next(_L("-=")); |
|
484 r=-1; |
|
485 r-=1; |
|
486 test(I64INT(r)==-2); |
|
487 r=0; |
|
488 r-=1; |
|
489 test(I64INT(r)==-1); |
|
490 r=1; |
|
491 r-=1; |
|
492 test(I64INT(r)==0); |
|
493 r=KMaxTUint32; |
|
494 r+=1; |
|
495 r-=1; |
|
496 test(I64HIGH(r)==0 && I64LOW(r)==KMaxTUint32); |
|
497 test(I64INT(r)==(TInt)KMaxTUint32); |
|
498 r-=1; |
|
499 test(I64INT(r)==(TInt)(KMaxTUint32-1)); |
|
500 |
|
501 |
|
502 // *= |
|
503 test.Next(_L("*=")); |
|
504 r=KMaxTUint32; // ffffffff * 2 = 1 fffffffe |
|
505 r*=2; |
|
506 test(I64HIGH(r)==1 && I64LOW(r)==KMaxTUint32-1); |
|
507 |
|
508 r=KMaxTUint32-1; |
|
509 r*=2; |
|
510 r+=2; |
|
511 test(I64HIGH(r)==1 && I64LOW(r)==KMaxTUint32-1); |
|
512 |
|
513 r=KMaxTUint32; |
|
514 r+=1; |
|
515 r*=2; |
|
516 test(I64HIGH(r)==2 && I64LOW(r)==0); |
|
517 |
|
518 TUint PosMinTInt=(TUint)KMinTInt32; |
|
519 r=PosMinTInt; |
|
520 r*=-1; |
|
521 test(I64INT(r)==KMinTInt32); |
|
522 |
|
523 r=KMinTInt32; |
|
524 r*=-1; |
|
525 r-=1; |
|
526 test(I64INT(r)==KMaxTInt32); |
|
527 |
|
528 r=KMaxTUint32; // ffffffff * ffffffff + (2 * ffffffff) = ffffffff ffffffff |
|
529 r*=KMaxTUint32; |
|
530 r+=KMaxTUint32; |
|
531 r+=KMaxTUint32; |
|
532 test(I64LOW(r)==KMaxTUint32 && I64HIGH(r)==KMaxTUint32); |
|
533 |
|
534 r=KMaxTUint32; |
|
535 r+=1; |
|
536 r*=2; |
|
537 test(I64LOW(r)==0 && I64HIGH(r)==2); |
|
538 |
|
539 |
|
540 // /= |
|
541 test.Next(_L("/=")); |
|
542 r=4; |
|
543 r/=2; |
|
544 test(I64INT(r)==2); |
|
545 r=4; |
|
546 r/=-2; |
|
547 test(I64INT(r)==-2); |
|
548 r=-4; |
|
549 r/=1; |
|
550 test(I64INT(r)==-4); |
|
551 r=-8; |
|
552 |
|
553 r/=-2; |
|
554 test(I64INT(r)==4); |
|
555 r=4; |
|
556 |
|
557 r/=4; |
|
558 test(I64INT(r)==1); |
|
559 r=0; |
|
560 |
|
561 r/=4; |
|
562 test(I64INT(r)==0); |
|
563 r=KMaxTUint32; |
|
564 TInt64 z(KMaxTUint32); |
|
565 r/=z; |
|
566 test(I64INT(r)==1); |
|
567 r=KMinTInt32; |
|
568 z=KMinTInt32; |
|
569 r/=z; |
|
570 test(I64INT(r)==1); |
|
571 r=KMinTInt32; |
|
572 z = MAKE_TINT64(0,(TUint)KMinTInt32); |
|
573 r/=z; |
|
574 test(I64INT(r)==-1); |
|
575 r=KMaxTUint32; |
|
576 r*=2; |
|
577 r/=2; |
|
578 test(I64HIGH(r)==0 && I64LOW(r)==KMaxTUint32); |
|
579 r=KMaxTUint32; |
|
580 a=KMaxTUint32; |
|
581 r*=z; |
|
582 r/=z; |
|
583 test(I64HIGH(r)==0 && I64LOW(r)==KMaxTUint32); |
|
584 r = MAKE_TINT64(0,(TUint)KMinTInt32); |
|
585 r/=-1; |
|
586 test(I64LOW(r)==(TUint)KMinTInt32); |
|
587 r=0; |
|
588 r/=KMaxTUint32; |
|
589 test(I64INT(r)==0); |
|
590 r=0; |
|
591 r/=KMinTInt32; |
|
592 test(I64INT(r)==0); |
|
593 r=0; |
|
594 TInt64 b = MAKE_TINT64(KMaxTUint32,KMaxTUint32); |
|
595 r/=b; |
|
596 test(I64INT(r)==0); |
|
597 TInt64 c = MAKE_TINT64(KMaxTUint32,KMaxTUint32); // -1/Anything == 0 |
|
598 TInt64* cptr = &c; // MSVC compiler calculates -1/anything at compile time |
|
599 *cptr /= KMaxTUint32; // and gets it wrong if we don't use a pointer, bizarre. |
|
600 test(I64LOW(c)==0 && I64HIGH(c)==0); |
|
601 r=-1; |
|
602 z=1; |
|
603 r/=z; |
|
604 test(r==-1); |
|
605 r=-r; |
|
606 r/=z; |
|
607 test(r==1); |
|
608 r = MAKE_TINT64(0x01,KMaxTUint32); |
|
609 z=2; |
|
610 r/=z; |
|
611 test(r==TInt64(KMaxTUint32)); |
|
612 r = MAKE_TINT64(0x01,KMaxTUint32); |
|
613 z = MAKE_TINT64(0,KMaxTUint32); |
|
614 r/=z; |
|
615 test(r==TInt64(2)); |
|
616 r = MAKE_TINT64(1,0); |
|
617 r/=z; |
|
618 test(r==TInt64(1)); |
|
619 r = MAKE_TINT64(6221,5621243); |
|
620 z = MAKE_TINT64(3,42011); |
|
621 r/=z; |
|
622 test(r==2073); |
|
623 r=100; |
|
624 z=99; |
|
625 r/=z; |
|
626 test(r==1); |
|
627 r = MAKE_TINT64(17,KMaxTUint32); |
|
628 z = MAKE_TINT64(0,8); |
|
629 test((r/=z)==MAKE_TINT64(0x2, 0x3fffffff)); |
|
630 |
|
631 // %= |
|
632 test.Next(_L("%=")); |
|
633 r=4; |
|
634 r%=4; |
|
635 test(I64INT(r)==0); |
|
636 r=4; |
|
637 r%=1; |
|
638 test(I64INT(r)==0); |
|
639 r=5; |
|
640 r%=3; |
|
641 test(I64INT(r)==2); |
|
642 r=(-5); |
|
643 r%=3; |
|
644 test(I64INT(r)==(-2)); |
|
645 r = MAKE_TINT64(134,KMaxTUint32-10342); |
|
646 z = MAKE_TINT64(134,0); |
|
647 test((r%=z)==KMaxTUint32-10342); |
|
648 r = MAKE_TINT64(134,KMaxTUint32-10342); |
|
649 z = MAKE_TINT64(134,KMaxTUint32-10343); |
|
650 test((r%=z)==1); |
|
651 r = MAKE_TINT64(1363,0xfd432ab0u); |
|
652 z = MAKE_TINT64(0,16); |
|
653 test((r%=z)==0); |
|
654 |
|
655 r=-10; |
|
656 r%=3; |
|
657 test(r==-1); |
|
658 r=-10; |
|
659 r%=-3; |
|
660 test(r==-1); |
|
661 r=10; |
|
662 r%=3; |
|
663 test(r==1); |
|
664 r=10; |
|
665 r%=-3; |
|
666 test(r==1); |
|
667 |
|
668 // <<= and >>= |
|
669 // <<= |
|
670 test.Next(_L("<<=")); |
|
671 r=1; |
|
672 r<<=32; |
|
673 test(I64LOW(r)==0 && I64HIGH(r)==1); |
|
674 r<<=31; |
|
675 test(I64LOW(r)==0 && I64HIGH(r)==0x80000000); |
|
676 |
|
677 r=1; |
|
678 r<<=31; |
|
679 test(I64LOW(r)==0x80000000 && I64HIGH(r)==0); |
|
680 r<<=32; |
|
681 test(I64LOW(r)==0 && I64HIGH(r)==0x80000000); |
|
682 |
|
683 r=1; |
|
684 r<<=63; |
|
685 test(I64LOW(r)==0 && I64HIGH(r)==0x80000000); |
|
686 |
|
687 r=0; |
|
688 r<<=32; |
|
689 test(I64LOW(r)==0 && I64HIGH(r)==0); |
|
690 |
|
691 r=0xC0000000; // 1100000.......... |
|
692 r<<=1; |
|
693 test(I64HIGH(r)==1 && I64LOW(r)==0x80000000); // 100000....... |
|
694 r<<=1; |
|
695 test(I64HIGH(r)==3 && I64LOW(r)==0); |
|
696 r<<=1; |
|
697 test(I64HIGH(r)==6 && I64LOW(r)==0); |
|
698 |
|
699 r = MAKE_TINT64(0,KMaxTUint32); |
|
700 r<<=32; |
|
701 test(I64LOW(r)==0 && I64HIGH(r)==KMaxTUint32); |
|
702 |
|
703 // >>= |
|
704 test.Next(_L(">>=")); |
|
705 r = MAKE_TINT64(3,0); |
|
706 r>>=1; |
|
707 test(I64HIGH(r)==1 && I64LOW(r)==0x80000000); |
|
708 r>>=1; |
|
709 test(I64HIGH(r)==0 && I64LOW(r)==0xC0000000); |
|
710 |
|
711 r = MAKE_TINT64(0x80000000,0); |
|
712 r>>=(31); |
|
713 test(I64HIGH(r)==KMaxTUint32 && I64LOW(r)==0); |
|
714 r>>=(32); |
|
715 test(I64HIGH(r)==KMaxTUint32 && I64LOW(r)==KMaxTUint32); |
|
716 |
|
717 r = MAKE_TINT64(0x80000000,0); |
|
718 r>>=(32); |
|
719 test(I64HIGH(r)==KMaxTUint32 && I64LOW(r)==0x80000000); |
|
720 |
|
721 r = MAKE_TINT64(0x80000000,0); |
|
722 r>>=63; |
|
723 test(I64LOW(r)==KMaxTUint32 && I64HIGH(r)==KMaxTUint32); |
|
724 |
|
725 r = MAKE_TINT64(KMaxTUint32, 0); |
|
726 r>>=32; |
|
727 test(I64HIGH(r)==KMaxTUint32 && I64LOW(r)==KMaxTUint32); |
|
728 |
|
729 // << |
|
730 test.Next(_L("<<")); |
|
731 r=1; |
|
732 TInt64 t = r<<32; |
|
733 test(I64LOW(t)==0 && I64HIGH(t)==1); |
|
734 t = t<<31; |
|
735 test(I64LOW(t)==0 && I64HIGH(t)==0x80000000); |
|
736 |
|
737 r=1; |
|
738 t = r<<31; |
|
739 test(I64LOW(t)==0x80000000 && I64HIGH(t)==0); |
|
740 t = t<<32; |
|
741 test(I64LOW(t)==0 && I64HIGH(t)==0x80000000); |
|
742 |
|
743 r=1; |
|
744 t = r<<63; |
|
745 test(I64LOW(t)==0 && I64HIGH(t)==0x80000000); |
|
746 |
|
747 r=0; |
|
748 t = r<<32; |
|
749 test(I64LOW(t)==0 && I64HIGH(t)==0); |
|
750 |
|
751 r=0xC0000000; // 1100000.......... |
|
752 t = r<<1; |
|
753 test(I64HIGH(t)==1 && I64LOW(t)==0x80000000); // 100000....... |
|
754 t = t<<1; |
|
755 test(I64HIGH(t)==3 && I64LOW(t)==0); |
|
756 t = t<<1; |
|
757 test(I64HIGH(t)==6 && I64LOW(t)==0); |
|
758 |
|
759 r = MAKE_TINT64(0,KMaxTUint32); |
|
760 t = r<<32; |
|
761 test(I64LOW(t)==0 && I64HIGH(t)==KMaxTUint32); |
|
762 |
|
763 // >> |
|
764 test.Next(_L(">>")); |
|
765 r = MAKE_TINT64(3,0); |
|
766 t = r>>1; |
|
767 test(I64HIGH(t)==1 && I64LOW(t)==0x80000000); |
|
768 t = t>>1; |
|
769 test(I64HIGH(t)==0 && I64LOW(t)==0xC0000000); |
|
770 |
|
771 r = MAKE_TINT64(0x80000000,0); |
|
772 t = r>>(31); |
|
773 test(I64HIGH(t)==KMaxTUint32 && I64LOW(t)==0); |
|
774 t = t>>(32); |
|
775 test(I64HIGH(t)==KMaxTUint32 && I64LOW(t)==KMaxTUint32); |
|
776 t = t>>1; |
|
777 test(I64HIGH(t)==KMaxTUint32 && I64LOW(t)==KMaxTUint32); |
|
778 t = t>>16; |
|
779 test(I64HIGH(t)==KMaxTUint32 && I64LOW(t)==KMaxTUint32); |
|
780 |
|
781 r = MAKE_TINT64(0x80000000,0); |
|
782 t = r>>(32); |
|
783 test(I64HIGH(t)==KMaxTUint32 && I64LOW(t)==0x80000000); |
|
784 |
|
785 r = MAKE_TINT64(0x80000000,0); |
|
786 t = r>>63; |
|
787 test(I64LOW(t)==KMaxTUint32 && I64HIGH(t)==KMaxTUint32); |
|
788 |
|
789 r = MAKE_TINT64(KMaxTUint32, 0); |
|
790 t = r>>32; |
|
791 test(I64HIGH(t)==KMaxTUint32 && I64LOW(t)==KMaxTUint32); |
|
792 |
|
793 r = MAKE_TINT64(0x40000000,0); |
|
794 t = r>>30; |
|
795 test(I64HIGH(t)==1 && I64LOW(t)==0); |
|
796 t = r>>31; |
|
797 test(I64HIGH(t)==0 && I64LOW(t)==0x80000000); |
|
798 t = r>>62; |
|
799 test(I64HIGH(t)==0 && I64LOW(t)==1); |
|
800 t = r>>63; |
|
801 test(I64HIGH(t)==0 && I64LOW(t)==0); |
|
802 |
|
803 test.End(); |
|
804 } |
|
805 |
|
806 LOCAL_C void Test3() |
|
807 { |
|
808 // Test some more operators |
|
809 |
|
810 // unary - |
|
811 test.Start(_L("unary -")); |
|
812 TInt64 r=0, x(KMinTInt32); |
|
813 r=-x; |
|
814 test(I64INT(r)==KMinTInt32); |
|
815 |
|
816 x = MAKE_TINT64(0,0x80000000); |
|
817 r=-x; |
|
818 test(I64INT(r)==KMinTInt32); |
|
819 |
|
820 // ++ |
|
821 // post increment |
|
822 test.Next(_L("++")); |
|
823 x=-1; |
|
824 r=x++; |
|
825 test(I64INT(r)==-1 && I64INT(x)==0); |
|
826 r=x++; |
|
827 test(I64INT(r)==0 && I64INT(x)==1); |
|
828 r=x++; |
|
829 test(I64INT(r)==1 && I64INT(x)==2); |
|
830 |
|
831 x=KMinTInt32; |
|
832 r=x++; |
|
833 test(I64INT(r)==KMinTInt32 && I64INT(x)==KMinTInt32+1); |
|
834 |
|
835 x=KMaxTUint32; |
|
836 r=x++; |
|
837 test(I64INT(r)==(TInt)KMaxTUint32 && I64HIGH(x)==1 && I64LOW(x)==0); |
|
838 r=x++; |
|
839 test(I64HIGH(r)==1 && I64LOW(r)==0 && I64HIGH(x)==1 && I64LOW(x)==1); |
|
840 |
|
841 // pre increment; |
|
842 x=-1; |
|
843 r=++x; |
|
844 test(I64INT(r)==0 && I64INT(x)==0); |
|
845 r=++x; |
|
846 test(I64INT(r)==1 && I64INT(x)==1); |
|
847 r=++x; |
|
848 test(I64INT(r)==2 && I64INT(x)==2); |
|
849 |
|
850 x=KMinTInt32; |
|
851 r=++x; |
|
852 test(I64INT(r)==KMinTInt32+1 && I64INT(x)==KMinTInt32+1); |
|
853 |
|
854 x=KMaxTUint32; |
|
855 r=++x; |
|
856 test(I64HIGH(r) && I64HIGH(x)==1 && I64LOW(x)==0); |
|
857 r=x++; |
|
858 test(I64HIGH(r)==1 && I64LOW(r)==0 && I64HIGH(x)==1 && I64LOW(x)==1); |
|
859 |
|
860 |
|
861 // -- |
|
862 test.Next(_L("--")); |
|
863 // post decrement |
|
864 x=1; |
|
865 r=x--; |
|
866 test(I64INT(r)==1 && I64INT(x)==0); |
|
867 r=x--; |
|
868 test(I64INT(r)==0 && I64INT(x)==-1); |
|
869 r=x--; |
|
870 test(I64INT(r)==-1 && I64INT(x)==-2); |
|
871 |
|
872 x=KMinTInt32+1; |
|
873 r=x--; |
|
874 test(I64INT(r)==KMinTInt32+1 && I64INT(x)==KMinTInt32); |
|
875 |
|
876 x=KMaxTUint32; |
|
877 x+=1; |
|
878 r=x--; |
|
879 test(I64HIGH(r)==1 && I64LOW(r)==0 && I64HIGH(x)==0 && I64LOW(x)==KMaxTUint32); |
|
880 r=x--; |
|
881 test(I64HIGH(r)==0 && I64LOW(r)==KMaxTUint32 && I64HIGH(x)==0 && I64LOW(x)==KMaxTUint32-1); |
|
882 |
|
883 x = MAKE_TINT64(KMaxTUint32,KMaxTUint32); |
|
884 r=x--; |
|
885 test(I64HIGH(r)==KMaxTUint32 && I64LOW(r)==KMaxTUint32 && I64HIGH(x)==KMaxTUint32 && I64LOW(x)==KMaxTUint32-1); |
|
886 |
|
887 // pre decrement |
|
888 x=1; |
|
889 r=--x; |
|
890 test(I64INT(r)==0 && I64INT(x)==0); |
|
891 r=--x; |
|
892 test(I64INT(r)==-1 && I64INT(x)==-1); |
|
893 r=--x; |
|
894 test(I64INT(r)==-2 && I64INT(x)==-2); |
|
895 |
|
896 x=KMinTInt32+1; |
|
897 r=--x; |
|
898 test(I64INT(r)==KMinTInt32 && I64INT(x)==KMinTInt32); |
|
899 |
|
900 x=KMaxTUint32; |
|
901 x+=1; |
|
902 r=--x; |
|
903 test(I64HIGH(r)==0 && I64LOW(r)==KMaxTUint32 && I64HIGH(x)==0 && I64LOW(x)==KMaxTUint32); |
|
904 r=--x; |
|
905 test(I64HIGH(r)==0 && I64LOW(r)==KMaxTUint32-1 && I64HIGH(x)==0 && I64LOW(x)==KMaxTUint32-1); |
|
906 |
|
907 x = MAKE_TINT64(KMaxTUint32,KMaxTUint32); |
|
908 r=--x; |
|
909 test(I64HIGH(r)==KMaxTUint32 && I64LOW(r)==KMaxTUint32-1 && I64HIGH(x)==KMaxTUint32 && I64LOW(x)==KMaxTUint32-1); |
|
910 |
|
911 |
|
912 |
|
913 // Binary + |
|
914 test.Next(_L("Binary +")); |
|
915 x=KMinTInt32; |
|
916 r=x+1; |
|
917 test(I64INT(r)==KMinTInt32+1 && I64INT(x)==KMinTInt32); |
|
918 |
|
919 x=-1; |
|
920 r=x+1; |
|
921 test(I64INT(r)==0 && I64INT(x)==-1); |
|
922 x=r+1; |
|
923 test(I64INT(r)==0 && I64INT(x)==1); |
|
924 |
|
925 x=KMaxTUint32; |
|
926 r=x+KMaxTUint32; |
|
927 test(I64HIGH(r)==1 && I64LOW(r)==KMaxTUint-1); |
|
928 |
|
929 x=KMaxTUint32; |
|
930 x+=1; |
|
931 r=x+(-1); |
|
932 test(I64HIGH(r)==0 && I64LOW(r)==KMaxTUint32); |
|
933 |
|
934 TInt64 y(0); |
|
935 x=KMaxTUint32; |
|
936 r=x+y; |
|
937 test(I64HIGH(r)==0 && I64LOW(r)==KMaxTUint32); |
|
938 |
|
939 y=KMaxTUint32; |
|
940 r=x+y; |
|
941 test(I64HIGH(r)==1 && I64LOW(r)==KMaxTUint32-1); |
|
942 |
|
943 y=0; |
|
944 x = MAKE_TINT64(KMaxTUint32,KMaxTUint32); |
|
945 r=x+y; |
|
946 test(I64HIGH(r)==KMaxTUint32 && I64LOW(r)==KMaxTUint32); |
|
947 |
|
948 y=1; |
|
949 x = MAKE_TINT64(KMaxTUint32,KMaxTUint32); |
|
950 x-=1; |
|
951 r=x+y; |
|
952 test(I64HIGH(r)==KMaxTUint32 && I64LOW(r)==KMaxTUint32); |
|
953 |
|
954 y=0; |
|
955 x=KMinTInt32; |
|
956 r=x+y; |
|
957 test(I64INT(r)==KMinTInt32); |
|
958 |
|
959 y=-1; |
|
960 x=KMinTInt32; |
|
961 x+=1; |
|
962 r=x+y; |
|
963 test(I64INT(r)==KMinTInt32); |
|
964 |
|
965 y=-1; |
|
966 x=-1; |
|
967 r=x+y; |
|
968 test(I64INT(r)==-2); |
|
969 |
|
970 y=-1; |
|
971 x=KMaxTUint32; |
|
972 r=x+y; |
|
973 test(I64HIGH(r)==0 && I64LOW(r)==KMaxTUint32-1); |
|
974 y=-1; |
|
975 x+=1; |
|
976 r=x+y; |
|
977 test(I64HIGH(r)==0 && I64LOW(r)==KMaxTUint32); |
|
978 y=-1; |
|
979 x = MAKE_TINT64(KMaxTUint32,KMaxTUint32); |
|
980 r=x+y; |
|
981 test(I64HIGH(r)==KMaxTUint32 && I64LOW(r)==KMaxTUint32-1); |
|
982 |
|
983 y=KMinTInt32; |
|
984 x=KMaxTUint32; |
|
985 r=x+y; |
|
986 test(I64HIGH(r)==0 && I64LOW(r)==KMaxTUint32-(TUint)KMinTInt32); |
|
987 x = MAKE_TINT64(KMaxTUint32,KMaxTUint32); |
|
988 r=x+y; |
|
989 test(I64HIGH(r)==KMaxTUint32 && I64LOW(r)==0x7fffffff); |
|
990 |
|
991 y=KMinTInt32; |
|
992 x=-(KMinTInt32+1); |
|
993 x+=1; |
|
994 r=x+y; |
|
995 test(I64INT(r)==0); |
|
996 |
|
997 |
|
998 // Binary - |
|
999 test.Next(_L("Binary -")); |
|
1000 x=KMinTInt32+1; |
|
1001 r=x-1; |
|
1002 test(I64INT(r)==KMinTInt32); |
|
1003 |
|
1004 x=2; |
|
1005 r=x-1; |
|
1006 test(I64INT(r)==1); |
|
1007 x=1; |
|
1008 r=x-1; |
|
1009 test(I64INT(r)==0); |
|
1010 x=0; |
|
1011 r=x-1; |
|
1012 test(I64INT(r)==-1); |
|
1013 |
|
1014 x=KMaxTUint32; |
|
1015 r=x-KMaxTUint32; |
|
1016 test(I64INT(r)==0); |
|
1017 |
|
1018 x=KMaxTUint32; |
|
1019 x+=1; |
|
1020 r=x-1; |
|
1021 test(I64HIGH(r)==0 && I64LOW(r)==KMaxTUint32); |
|
1022 |
|
1023 x=KMaxTUint32; |
|
1024 r=x-1; |
|
1025 test(I64HIGH(r)==0 && I64LOW(r)==KMaxTUint32-1); |
|
1026 |
|
1027 x = MAKE_TINT64(KMaxTUint32,KMaxTUint32); |
|
1028 r=x-1; |
|
1029 test(I64HIGH(r)==KMaxTUint32 && I64LOW(r)==KMaxTUint32-1); |
|
1030 |
|
1031 |
|
1032 y=0; |
|
1033 x=KMaxTUint32; |
|
1034 r=x-y; |
|
1035 test(I64HIGH(r)==0 && I64LOW(r)==KMaxTUint32); |
|
1036 |
|
1037 y=KMaxTUint32; |
|
1038 r=x-y; |
|
1039 test(I64INT(r)==0); |
|
1040 |
|
1041 x=KMaxTUint32; |
|
1042 x+=1; |
|
1043 y=1; |
|
1044 r=x-1; |
|
1045 test(I64HIGH(r)==0 && I64LOW(r)==KMaxTUint32); |
|
1046 x-=1; |
|
1047 r=x-1; |
|
1048 test(I64HIGH(r)==0 && I64LOW(r)==KMaxTUint32-1); |
|
1049 |
|
1050 y=0; |
|
1051 x = MAKE_TINT64(KMaxTUint32,KMaxTUint32); |
|
1052 r=x-y; |
|
1053 test(I64HIGH(r)==KMaxTUint32 && I64LOW(r)==KMaxTUint32); |
|
1054 |
|
1055 y=1; |
|
1056 x = MAKE_TINT64(KMaxTUint32,KMaxTUint32); |
|
1057 r=x-y; |
|
1058 test(I64HIGH(r)==KMaxTUint32 && I64LOW(r)==KMaxTUint32-1); |
|
1059 |
|
1060 y=0; |
|
1061 x=KMinTInt32; |
|
1062 r=x-y; |
|
1063 test(I64INT(r)==KMinTInt32); |
|
1064 |
|
1065 y=1; |
|
1066 x=KMinTInt32; |
|
1067 x+=1; |
|
1068 r=x-y; |
|
1069 test(I64INT(r)==KMinTInt32); |
|
1070 |
|
1071 y=1; |
|
1072 x=1; |
|
1073 r=x-y; |
|
1074 test(I64INT(r)==0); |
|
1075 |
|
1076 y=-1; |
|
1077 x=-1; |
|
1078 r=x-y; |
|
1079 test(I64INT(r)==0); |
|
1080 |
|
1081 x=0; |
|
1082 y=KMinTInt32; |
|
1083 r=x-y; |
|
1084 test(I64INT(r)==KMinTInt32); |
|
1085 |
|
1086 x=KMinTInt32; |
|
1087 y=KMinTInt32; |
|
1088 r=x-y; |
|
1089 test(I64INT(r)==0); |
|
1090 |
|
1091 test.End(); |
|
1092 } |
|
1093 |
|
1094 |
|
1095 LOCAL_C void Test4() |
|
1096 // still more operators |
|
1097 { |
|
1098 // * |
|
1099 test.Start(_L("Binary *")); |
|
1100 TInt64 r(0), x(1), y(0); |
|
1101 r=x*y; |
|
1102 test(I64INT(r)==0); |
|
1103 |
|
1104 y=-1; |
|
1105 r=x*y; |
|
1106 test(I64INT(r)==-1); |
|
1107 |
|
1108 x=-1; |
|
1109 r=x*y; |
|
1110 test(I64INT(r)==1); |
|
1111 |
|
1112 x=KMinTInt32; |
|
1113 r=x*y; |
|
1114 test(I64INT(r)==KMinTInt32); |
|
1115 |
|
1116 y=0; |
|
1117 r=x*y; |
|
1118 test(I64INT(r)==0); |
|
1119 |
|
1120 y=KMinTInt32; |
|
1121 r=x*y; |
|
1122 test(I64LOW(r)==0 && I64HIGH(r)==0x40000000); |
|
1123 |
|
1124 y=KMaxTUint32; |
|
1125 x=KMaxTUint32; |
|
1126 r=x*y; |
|
1127 test(I64LOW(r)==1 && I64HIGH(r)==0xfffffffe); |
|
1128 |
|
1129 |
|
1130 // / |
|
1131 test.Next(_L("Binary /")); |
|
1132 x=5; |
|
1133 y=5; |
|
1134 r=x/y; |
|
1135 test(I64INT(r)==1); |
|
1136 |
|
1137 y=1; |
|
1138 r=x/y; |
|
1139 test(I64INT(r)==5); |
|
1140 |
|
1141 x=-5; |
|
1142 r=x/y; |
|
1143 test(I64INT(r)==-5); |
|
1144 |
|
1145 y=-1; |
|
1146 r=x/y; |
|
1147 test(I64INT(r)==5); |
|
1148 |
|
1149 x=-1; |
|
1150 r=x/y; |
|
1151 test(I64INT(r)==1); |
|
1152 |
|
1153 x=0; |
|
1154 r=x/y; |
|
1155 test(I64INT(r)==0); |
|
1156 |
|
1157 x=KMinTInt32; |
|
1158 y=-1; |
|
1159 r=x/y; |
|
1160 test(I64INT(r)==KMinTInt32); |
|
1161 |
|
1162 x=KMinTInt32; |
|
1163 y=KMinTInt32; |
|
1164 r=x/y; |
|
1165 test(I64INT(r)==1); |
|
1166 |
|
1167 x=KMaxTUint32; |
|
1168 y=KMaxTUint32; |
|
1169 r=x/y; |
|
1170 test(I64INT(r)==1); |
|
1171 |
|
1172 x = MAKE_TINT64(KMaxTUint32,KMaxTUint32); |
|
1173 r=x/y; |
|
1174 test(I64INT(r)==0); |
|
1175 |
|
1176 y = MAKE_TINT64(KMaxTUint32,KMaxTUint32); |
|
1177 r=x/y; |
|
1178 test(I64INT(r)==1); |
|
1179 |
|
1180 y=KMinTInt32; |
|
1181 r=x/y; |
|
1182 test(I64INT(r)==0); |
|
1183 |
|
1184 x = MAKE_TINT64(4,257629747); |
|
1185 y=KMaxTInt; |
|
1186 r=x/y; |
|
1187 test(I64LOW(r)==8 && I64HIGH(r)==0); |
|
1188 |
|
1189 x = MAKE_TINT64(3452,533254); |
|
1190 x=-x; |
|
1191 x=x/x; |
|
1192 test(x==1); |
|
1193 |
|
1194 // % |
|
1195 test.Next(_L("binary %%")); |
|
1196 x=2341; |
|
1197 y=2340; |
|
1198 test(x%y==1); |
|
1199 y=2; |
|
1200 test(x%y==1); |
|
1201 x = MAKE_TINT64(234893,23494); |
|
1202 test(x%x==0); |
|
1203 test(x%y==0); |
|
1204 x=-x; |
|
1205 y=10; |
|
1206 test(x%y==-2); |
|
1207 test(x%(-y)==-2); |
|
1208 |
|
1209 |
|
1210 // Lsr |
|
1211 test.Next(_L("Lsr")); |
|
1212 |
|
1213 r = MAKE_TINT64(3,0); |
|
1214 I64LSR(r, 1); |
|
1215 test(I64HIGH(r)==1 && I64LOW(r)==0x80000000); |
|
1216 I64LSR(r, 1); |
|
1217 test(I64HIGH(r)==0 && I64LOW(r)==0xC0000000); |
|
1218 |
|
1219 r = MAKE_TINT64(0x80000000,0); |
|
1220 I64LSR(r, 31); |
|
1221 test(I64HIGH(r)==1 && I64LOW(r)==0); |
|
1222 //test(I64HIGH(r)==KMaxTUint32 && I64LOW(r)==0); |
|
1223 I64LSR(r, 32); |
|
1224 //test(I64HIGH(r)==KMaxTUint32 && I64LOW(r)==KMaxTUint32); |
|
1225 test(I64HIGH(r)==0 && I64LOW(r)==1); |
|
1226 |
|
1227 r = MAKE_TINT64(0x80000000,0); |
|
1228 I64LSR(r, 32); |
|
1229 test(I64HIGH(r)==0 && I64LOW(r)==0x80000000); |
|
1230 //test(I64HIGH(r)==KMaxTUint32 && I64LOW(r)==0x80000000); |
|
1231 |
|
1232 r = MAKE_TINT64(0x80000000,0); |
|
1233 I64LSR(r, 63); |
|
1234 test(I64LOW(r)==1 && I64HIGH(r)==0); |
|
1235 //test(I64LOW(r)==KMaxTUint32 && I64HIGH(r)==KMaxTUint32); |
|
1236 |
|
1237 r = MAKE_TINT64(KMaxTUint32, 0); |
|
1238 I64LSR(r, 32); |
|
1239 test(I64HIGH(r)==0 && I64LOW(r)==KMaxTUint32); |
|
1240 //test(I64HIGH(r)==KMaxTUint32 && I64LOW(r)==KMaxTUint32); |
|
1241 |
|
1242 |
|
1243 // Mul10 |
|
1244 test.Next(_L("Mul10")); |
|
1245 const TInt64 KMaxDiv10= KMaxTInt64 / 10; |
|
1246 const TInt64 KStep=MAKE_TINT64(0x003dfe03, 0xf7ea23cd); |
|
1247 for(TInt64 jj=-KMaxDiv10; jj<=KMaxDiv10; jj+=KStep) |
|
1248 { |
|
1249 r=jj; |
|
1250 r *= 10; |
|
1251 test(r==jj*10); |
|
1252 r/=10; |
|
1253 test(r==jj); |
|
1254 } |
|
1255 |
|
1256 r=KMinTInt32/10; |
|
1257 r *= 10; |
|
1258 test(I64INT(r)==(KMinTInt/10)*10); |
|
1259 |
|
1260 r=KMaxTUint32; |
|
1261 r *= 10; |
|
1262 test(I64HIGH(r)==9 && I64LOW(r)==0xFFFFFFF6); |
|
1263 |
|
1264 r/=10; |
|
1265 test(r==MAKE_TINT64(0,KMaxTUint32)); |
|
1266 |
|
1267 |
|
1268 // DivMod |
|
1269 test.Next(_L("DivMod")); |
|
1270 TInt64 seed = MAKE_TINT64(0x0000336a,0xb2001a78); |
|
1271 for (TInt i=0; i<200; i++) |
|
1272 { |
|
1273 TInt o=Math::Rand(seed); |
|
1274 TInt p=Math::Rand(seed); |
|
1275 TInt r=Math::Rand(seed); |
|
1276 TInt q=Math::Rand(seed); |
|
1277 |
|
1278 DivModTest(MAKE_TINT64(0,q), MAKE_TINT64(0,r)); |
|
1279 DivModTest(MAKE_TINT64(r,q), MAKE_TINT64(o,p)); |
|
1280 DivModTest(MAKE_TINT64(p,q), MAKE_TINT64(0,o)); |
|
1281 DivModTest(MAKE_TINT64(0,p), MAKE_TINT64(r,o)); |
|
1282 |
|
1283 DivModTest(-MAKE_TINT64(0,q), -MAKE_TINT64(0,r)); |
|
1284 DivModTest( MAKE_TINT64(0,q), -MAKE_TINT64(0,r)); |
|
1285 DivModTest(-MAKE_TINT64(0,q), MAKE_TINT64(0,r)); |
|
1286 |
|
1287 DivModTest(-MAKE_TINT64(r,q), -MAKE_TINT64(o,p)); |
|
1288 DivModTest( MAKE_TINT64(r,q), -MAKE_TINT64(o,p)); |
|
1289 DivModTest(-MAKE_TINT64(r,q), MAKE_TINT64(o,p)); |
|
1290 |
|
1291 DivModTest(-MAKE_TINT64(0,p), -MAKE_TINT64(r,o)); |
|
1292 DivModTest( MAKE_TINT64(0,p), -MAKE_TINT64(r,o)); |
|
1293 DivModTest(-MAKE_TINT64(0,p), MAKE_TINT64(r,o)); |
|
1294 } |
|
1295 |
|
1296 test.End(); |
|
1297 } |
|
1298 |
|
1299 LOCAL_C void Test5() |
|
1300 // still more operators |
|
1301 { |
|
1302 |
|
1303 // fast multiply by 10 |
|
1304 test.Start(_L("Mul10")); |
|
1305 TInt64 r(0); |
|
1306 r *= 10; |
|
1307 test(I64INT(r)==0); |
|
1308 |
|
1309 r=-1; |
|
1310 r *= 10; |
|
1311 test(I64INT(r)==-10); |
|
1312 |
|
1313 r=KMinTInt32/10; |
|
1314 r *= 10; |
|
1315 test(I64INT(r)==KMinTInt32-(KMinTInt32%10)); |
|
1316 |
|
1317 r=1; |
|
1318 r *= 10; |
|
1319 test(I64INT(r)==10); |
|
1320 |
|
1321 r=KMaxTUint32/10; |
|
1322 r *= 10; |
|
1323 test(I64LOW(r)==(KMaxTUint32-(KMaxTUint%10)) && I64HIGH(r)==0); |
|
1324 |
|
1325 r *= 10; |
|
1326 test(r==TInt64(KMaxTUint32-(KMaxTUint%10))*10); |
|
1327 |
|
1328 r *= 10; |
|
1329 test(r==TInt64(KMaxTUint32-(KMaxTUint%10))*100); |
|
1330 |
|
1331 // Comparisons |
|
1332 test.Next(_L("Comparison operators")); |
|
1333 |
|
1334 // == , !=, <= and >= |
|
1335 test.Next(_L("==, !=, <= and >=")); |
|
1336 r=KMinTInt32; |
|
1337 TInt64 x(KMinTInt32); |
|
1338 TInt64 y(100); |
|
1339 test(r==x && r!=y && r>=x && r<=x); |
|
1340 |
|
1341 r=-1; |
|
1342 x=-1; |
|
1343 test(r==x && r!=y && r>=x && r<=x); |
|
1344 |
|
1345 r=0; |
|
1346 x=0; |
|
1347 test(r==x && r!=y && r>=x && r<=x); |
|
1348 |
|
1349 r=1; |
|
1350 x=1; |
|
1351 test(r==x && r!=y && r>=x && r<=x); |
|
1352 |
|
1353 r=KMaxTUint32; |
|
1354 x=KMaxTUint32; |
|
1355 test(r==x && r!=y && r>=x && r<=x); |
|
1356 |
|
1357 r = MAKE_TINT64(KMaxTUint32,KMaxTUint32); |
|
1358 x = MAKE_TINT64(KMaxTUint32,KMaxTUint32); |
|
1359 test(x==r && x!=y && x>=r && x<=r); |
|
1360 |
|
1361 //>=, <=, > and < |
|
1362 test.Next(_L(">=, <=, > and <")); |
|
1363 r=KMinTInt32; |
|
1364 x=KMinTInt32+1; |
|
1365 test(x>r && x>=r && r<x && r<=x); |
|
1366 |
|
1367 r=1; |
|
1368 x=-1; |
|
1369 test(r>x && x<r && r>=x && x<=r); |
|
1370 |
|
1371 r=KMaxTUint32; |
|
1372 x=KMaxTUint32-1; |
|
1373 test(r>x && x<r && r>=x && x<=r); |
|
1374 |
|
1375 r+=1; |
|
1376 x+=1; |
|
1377 test(r>x && x<r && r>=x && x<=r); |
|
1378 |
|
1379 r = MAKE_TINT64(KMaxTUint32,KMaxTUint32); |
|
1380 x = MAKE_TINT64(KMaxTUint32,KMaxTUint32-1); |
|
1381 test(r>x && x<r && r>=x && x<=r); |
|
1382 |
|
1383 r = MAKE_TINT64(0x80000000,0); |
|
1384 x = MAKE_TINT64(KMaxTInt32,KMaxTUint32); |
|
1385 test(r<x); |
|
1386 test(x>r); |
|
1387 test(x!=r); |
|
1388 test(r<=x); |
|
1389 test(x>=r); |
|
1390 test(r<0 && x>0); |
|
1391 |
|
1392 x = MAKE_TINT64(0x80000000,1); |
|
1393 test(r<x && x>r && x!=r && r<=x && x>=r); |
|
1394 |
|
1395 r = MAKE_TINT64(KMaxTInt32,KMaxTUint32); |
|
1396 --r; |
|
1397 test(r>x && x<r && x!=r && r>=x && x<=r); |
|
1398 |
|
1399 // multiply top bits |
|
1400 test.Next(_L("MulTop")); |
|
1401 r=0; |
|
1402 x=0; |
|
1403 I64MULTOP(r, x); |
|
1404 test(I64INT(r)==0); |
|
1405 |
|
1406 r=1; |
|
1407 x=1; |
|
1408 I64MULTOP(r, x); |
|
1409 test(I64INT(r)==0); |
|
1410 |
|
1411 r = MAKE_TINT64(KMaxTInt,KMaxTUint); |
|
1412 x=2; |
|
1413 I64MULTOP(r, x); |
|
1414 test(I64INT(r)==0); |
|
1415 |
|
1416 r = MAKE_TINT64(KMaxTInt,KMaxTUint); |
|
1417 x=4; |
|
1418 I64MULTOP(r, x); |
|
1419 test(I64INT(r)==1); |
|
1420 |
|
1421 r = MAKE_TINT64(0x80000000,0); |
|
1422 x = MAKE_TINT64(0x80000000,0); |
|
1423 I64MULTOP(r, x); |
|
1424 r>>=32; |
|
1425 test(I64INT(r)==0x40000000); |
|
1426 |
|
1427 r = MAKE_TINT64(0x18763529,0x93263921); |
|
1428 x = MAKE_TINT64(0x0abcdef0,0x647239ea); |
|
1429 TInt64 r2=r; |
|
1430 TInt64 x2=x; |
|
1431 I64MULTOP(r, x2); |
|
1432 I64MULTOP(x, r2); |
|
1433 test(r==x); |
|
1434 |
|
1435 // TInt64(0xac11b680,0x1e603000) * TInt64(0x014a5c20,0xc9d58740) |
|
1436 |
|
1437 TPtrC8 a4=_L8("ac11b6801e603000"); |
|
1438 TPtrC8 a5=_L8("014a5c20c9d58740"); |
|
1439 TBuf8<64> a6; |
|
1440 HexMul(a4,a5,a6); |
|
1441 |
|
1442 x = MAKE_TINT64(0x014a5c20,0xc9d58740); |
|
1443 |
|
1444 r = MAKE_TINT64(0xac11b680,0x1e603000); |
|
1445 y = MAKE_TINT64(0x0963fbc4,0x415c0000); // Expected result (bottom 64 bits) |
|
1446 |
|
1447 r *= x; |
|
1448 |
|
1449 test(r==y); |
|
1450 |
|
1451 r = MAKE_TINT64(0xac11b680,0x1e603000); |
|
1452 y = MAKE_TINT64(0x00de0cc1,0xa89d70dc); // Expected result (top 64 bits) |
|
1453 I64MULTOP(r, x); |
|
1454 test(r==y); |
|
1455 |
|
1456 test.End(); |
|
1457 } |
|
1458 |
|
1459 |
|
1460 GLDEF_C TInt E32Main() |
|
1461 { |
|
1462 test.Title(); |
|
1463 test.Start(_L("Constructors")); |
|
1464 Test1(); |
|
1465 test.Next(_L("Unary operators")); |
|
1466 Test1_2(); |
|
1467 test.Next(_L("Operators 1")); |
|
1468 Test2(); |
|
1469 test.Next(_L("Operators 2")); |
|
1470 Test3(); |
|
1471 test.Next(_L("Operators 3")); |
|
1472 Test4(); |
|
1473 test.Next(_L("Operators 4")); |
|
1474 Test5(); |
|
1475 test.End(); |
|
1476 return(KErrNone); |
|
1477 } |