First public contribution.
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".
8 // Initial Contributors:
9 // Nokia Corporation - initial contribution.
14 // e32test\math\t_i64.cpp
17 // Test 64-bit integer functionality.
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:
30 // Assumptions/Requirement/Pre-requisites:
31 // Failures and causes:
32 // Base Port information:
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; \
50 #define I64MULTOP(x, value) __i64multop(x, (value))
53 TInt HexMulAdd(TUint8 a1,TUint8 a2,TUint8& answer,TUint8& carry)
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);
66 a= a>9 ? a-10+'a' : a+'0';
67 c= c>9 ? c-10+'a' : c+'0';
73 TInt HexMul(TDesC8& a1,TDesC8& a2,TDes8& a3)
75 // Infinite precision hex multiplier
81 if (a3.MaxLength()<l3)
94 if(HexMulAdd(a2[l2-y-1],a1[l1-z-1],a3[l3-y-z-1],carry)!=KErrNone)
97 if(HexMulAdd('0','0',a3[l3-y-l1-1],carry)!=KErrNone)
104 LOCAL_D RTest test(_L("T_I64"));
106 LOCAL_C void SlowDivMod(const TInt64& aA, const TInt64& aB, TInt64& aDiv, TInt64& aMod)
108 // Calculate Division/Remainder using repeated subtraction
137 if ((t & UI64LIT(0xffffffff00000000)) == 0)
139 while (aMod >= (t << 31))
141 aDiv += static_cast<TUint32>(1 << 31);
145 if ((t & UI64LIT(0xffffff0000000000)) == 0)
147 while (aMod >= (t << 23))
153 if ((t & UI64LIT(0xffff000000000000)) == 0)
155 while (aMod >= (t << 15))
161 if ((t & UI64LIT(0xff00000000000000)) == 0)
163 while (aMod >= (t << 7))
169 if ((t & UI64LIT(0xf000000000000000)) == 0)
171 while (aMod >= (t << 3))
194 LOCAL_C void DivModTest(const TInt64& aA, const TInt64& aB)
196 // Test DivMod against SlowDivMod
203 TInt64 div=0,mod=0,res=0;
205 SlowDivMod(n,d,div,mod);
218 // Test the constructors
221 test.Start(_L("Default constructor"));
223 t1 = 0; // to prevent uninitialised warnings
224 (void)(t1 > 0); // to prevent unused warnings
227 test.Next(_L("TInt64(TInt aVal)"));
229 test(I64LOW(t2)==0 && I64HIGH(t2)==0);
231 test(I64LOW(t3)==1 && I64HIGH(t3)==0);
232 TInt64 t4(KMaxTInt32);
233 test(I64LOW(t4)==(TUint)KMaxTInt32 && I64HIGH(t4)==0);
235 test(I64INT(t5)==-1);
236 test(I64LOW(t5)==KMaxTUint32 && I64HIGH(t5)==KMaxTUint32);
237 TInt64 t6(KMinTInt32);
238 test(I64INT(t6)==KMinTInt32);
240 // TInt64(TUint aVal)
241 test.Next(_L("TInt64(TUint aVal)"));
243 test(I64LOW(t7)==0 && I64HIGH(t7)==0);
245 test(I64LOW(t8)==1 && I64HIGH(t8)==0);
246 TInt64 t9(KMaxTUint32);
247 test(I64LOW(t9)==KMaxTUint32 && I64HIGH(t9)==0);
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);
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);
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);
277 // Make variable volatile to protect ourselves from compiler optimisations. Given that the
278 // following test is negative with unspecified results, we don't really care if we do not have
279 // FPU/compiler parity.
281 xout = 9.223372036854776831e18; // 2^63 + 2^10 (to ensure rounding outside of TInt64 range)
282 TInt64 t21((TInt64)xout);
284 // IEEE 754 does not specify the value to be returned when a conversion
285 // is performed on a value that is outside the range of the target, only
286 // that an invalid operation exception be raised if the io fp exception
288 #if defined(__WINS__) || defined(__X86__)
289 // The x86 FPU returns KMin... as the "indefinite number"
290 test(t21 == KMinTInt64);
292 // The target compiler support libraries return KMax...
293 test(t21 == KMaxTInt64);
296 TReal limit=1048576.0*1048576.0*8192.0; // integers <2^53 in modulus can be represented exactly
297 TInt64 t22((TInt64)limit);
298 test(I64LOW(t22)==0 && I64HIGH(t22)==0x00200000);
299 TInt64 t23((TInt64)(limit-1.0));
300 test(I64LOW(t23)==0xffffffff && I64HIGH(t23)==0x001fffff);
301 TReal i64limit=limit*1024.0; // 2^63
302 // Make variable volatile to protect ourselves from compiler optimisations. Given that the
303 // following test is negative with unspecified results, we don't really care if we do not have
304 // FPU/compiler parity.
305 volatile TReal i64limitout=i64limit;
306 TInt64 t24((TInt64)i64limitout);
308 // IEEE 754 does not specify the value to be returned when a conversion
309 // is performed on a value that is outside the range of the target, only
310 // that an invalid operation exception be raised if the io fp exception
312 #if defined(__WINS__) || defined(__X86__)
313 // The x86 FPU returns KMin... as the "indefinite number"
314 test(t24 == KMinTInt64);
316 // The target compiler support libraries return KMax...
317 test(t24 == KMaxTInt64);
320 TInt64 t25((TInt64)(i64limit-1024.0));
321 test(I64LOW(t25)==0xfffffc00 && I64HIGH(t25)==0x7fffffff);
322 TInt64 t26((TInt64)-i64limit);
323 test(I64LOW(t26)==0x00000000 && I64HIGH(t26)==0x80000000);
324 TInt64 t27((TInt64)(1024.0-i64limit));
325 test(I64LOW(t27)==0x00000400 && I64HIGH(t27)==0x80000000);
330 for (i=-99; i<100; i++)
338 // test.Printf(_L("Testing %g\n"),x);
339 TInt64 ll((TInt64)x);
346 if (i==1 || i==0 || (i==-1 && l==TInt64(1)))
352 test.Next(_L("TInt64::GetTReal"));
354 // GCC does optimise large portions of the test code out and there can be small
355 // differences in the way GCC and the FPU round floating point values.
356 // We isolate the following test by giving it its own variables. This should
357 // prevent values returned by the FPU from being compared with wrong GCC calculations.
358 TInt64 m = MAKE_TINT64(0x7fffffff,0xffffffff);
359 TReal xy = I64REAL(m);
360 TReal xx = 1048576.0*1048576.0*1048576.0*8.0 - 1.0; // 2^63 - 1
364 l = MAKE_TINT64(0x7fffffff,0xfffffc00);
367 test(x == (i64limit - 1024.0));
369 l = MAKE_TINT64(0x80000000,0x00000000);
372 test(x == -i64limit);
374 l = MAKE_TINT64(0x80000000,0x00000400);
377 test(x == (1024.0 - i64limit));
379 l = MAKE_TINT64(0x00000001,0x00000000);
382 test(x == (65536.0 * 65536.0));
384 l = MAKE_TINT64(0xffffffff,0x00000000);
387 test(x == (-65536.0 * 65536.0));
389 for (i=-99; i<100; i++)
397 // test.Printf(_L("Testing %g\n"),x);
398 TReal y = I64REAL(l);
402 if (i==1 || i==0 || (i==-1 && l==TInt64(1)))
407 // TInt64(const TInt64& aVal)
408 test.Next(_L("Copy constructor"));
410 test(I64LOW(t13)==I64LOW(t10) && I64HIGH(t13)==I64HIGH(t10));
412 test.Next(_L("Set"));
413 t13 = MAKE_TINT64(0, 0);
414 test(I64LOW(t13)==0 && I64HIGH(t13)==0);
418 LOCAL_C void Test1_2()
420 // Test Unary operators -, and +
431 r = MAKE_TINT64(540423,21344);
434 test(+r==MAKE_TINT64(540423,21344));
443 // Test the operators
447 TInt64 r=0,r2=0, a = MAKE_TINT64(12345,54321);
449 test(I64LOW(r)==(TUint)KMaxTInt32 && I64HIGH(r)==0);
451 test(I64INT(r)==KMinTInt32);
452 test(I64INT(r2)==KMinTInt32);
454 test(I64LOW(r)==KMaxTUint32 && I64HIGH(r)==0);
455 test(I64LOW(r2)==KMaxTUint32 && I64HIGH(r2)==0);
457 test(I64LOW(r)==I64LOW(a) && I64HIGH(r)==I64HIGH(a));
458 test(I64LOW(r2)==I64LOW(a) && I64HIGH(r2)==I64HIGH(a));
460 r2=r=(TInt64)((TReal)1.2);
463 r2=r=(TInt64)((TReal)20.9);
466 r2=r=(TInt64)((TReal)-100.2);
472 // +=, -=, *=, /=, %=, >>=, <<=, >>, <<
484 test(I64INT(r)-1==(TInt)KMaxTUint32);
488 test(I64INT(r)==KMinTInt32+1);
491 r+=MAKE_TINT64(0,0x80000000u);
492 test(r==MAKE_TINT64(0,0x80000000u));
508 test(I64HIGH(r)==0 && I64LOW(r)==KMaxTUint32);
509 test(I64INT(r)==(TInt)KMaxTUint32);
511 test(I64INT(r)==(TInt)(KMaxTUint32-1));
516 r=KMaxTUint32; // ffffffff * 2 = 1 fffffffe
518 test(I64HIGH(r)==1 && I64LOW(r)==KMaxTUint32-1);
523 test(I64HIGH(r)==1 && I64LOW(r)==KMaxTUint32-1);
528 test(I64HIGH(r)==2 && I64LOW(r)==0);
530 TUint PosMinTInt=(TUint)KMinTInt32;
533 test(I64INT(r)==KMinTInt32);
538 test(I64INT(r)==KMaxTInt32);
540 r=KMaxTUint32; // ffffffff * ffffffff + (2 * ffffffff) = ffffffff ffffffff
544 test(I64LOW(r)==KMaxTUint32 && I64HIGH(r)==KMaxTUint32);
549 test(I64LOW(r)==0 && I64HIGH(r)==2);
576 TInt64 z(KMaxTUint32);
584 z = MAKE_TINT64(0,(TUint)KMinTInt32);
590 test(I64HIGH(r)==0 && I64LOW(r)==KMaxTUint32);
595 test(I64HIGH(r)==0 && I64LOW(r)==KMaxTUint32);
596 r = MAKE_TINT64(0,(TUint)KMinTInt32);
598 test(I64LOW(r)==(TUint)KMinTInt32);
606 TInt64 b = MAKE_TINT64(KMaxTUint32,KMaxTUint32);
609 TInt64 c = MAKE_TINT64(KMaxTUint32,KMaxTUint32); // -1/Anything == 0
610 TInt64* cptr = &c; // MSVC compiler calculates -1/anything at compile time
611 *cptr /= KMaxTUint32; // and gets it wrong if we don't use a pointer, bizarre.
612 test(I64LOW(c)==0 && I64HIGH(c)==0);
620 r = MAKE_TINT64(0x01,KMaxTUint32);
623 test(r==TInt64(KMaxTUint32));
624 r = MAKE_TINT64(0x01,KMaxTUint32);
625 z = MAKE_TINT64(0,KMaxTUint32);
628 r = MAKE_TINT64(1,0);
631 r = MAKE_TINT64(6221,5621243);
632 z = MAKE_TINT64(3,42011);
639 r = MAKE_TINT64(17,KMaxTUint32);
640 z = MAKE_TINT64(0,8);
641 test((r/=z)==MAKE_TINT64(0x2, 0x3fffffff));
656 test(I64INT(r)==(-2));
657 r = MAKE_TINT64(134,KMaxTUint32-10342);
658 z = MAKE_TINT64(134,0);
659 test((r%=z)==KMaxTUint32-10342);
660 r = MAKE_TINT64(134,KMaxTUint32-10342);
661 z = MAKE_TINT64(134,KMaxTUint32-10343);
663 r = MAKE_TINT64(1363,0xfd432ab0u);
664 z = MAKE_TINT64(0,16);
682 test.Next(_L("<<="));
685 test(I64LOW(r)==0 && I64HIGH(r)==1);
687 test(I64LOW(r)==0 && I64HIGH(r)==0x80000000);
691 test(I64LOW(r)==0x80000000 && I64HIGH(r)==0);
693 test(I64LOW(r)==0 && I64HIGH(r)==0x80000000);
697 test(I64LOW(r)==0 && I64HIGH(r)==0x80000000);
701 test(I64LOW(r)==0 && I64HIGH(r)==0);
703 r=0xC0000000; // 1100000..........
705 test(I64HIGH(r)==1 && I64LOW(r)==0x80000000); // 100000.......
707 test(I64HIGH(r)==3 && I64LOW(r)==0);
709 test(I64HIGH(r)==6 && I64LOW(r)==0);
711 r = MAKE_TINT64(0,KMaxTUint32);
713 test(I64LOW(r)==0 && I64HIGH(r)==KMaxTUint32);
716 test.Next(_L(">>="));
717 r = MAKE_TINT64(3,0);
719 test(I64HIGH(r)==1 && I64LOW(r)==0x80000000);
721 test(I64HIGH(r)==0 && I64LOW(r)==0xC0000000);
723 r = MAKE_TINT64(0x80000000,0);
725 test(I64HIGH(r)==KMaxTUint32 && I64LOW(r)==0);
727 test(I64HIGH(r)==KMaxTUint32 && I64LOW(r)==KMaxTUint32);
729 r = MAKE_TINT64(0x80000000,0);
731 test(I64HIGH(r)==KMaxTUint32 && I64LOW(r)==0x80000000);
733 r = MAKE_TINT64(0x80000000,0);
735 test(I64LOW(r)==KMaxTUint32 && I64HIGH(r)==KMaxTUint32);
737 r = MAKE_TINT64(KMaxTUint32, 0);
739 test(I64HIGH(r)==KMaxTUint32 && I64LOW(r)==KMaxTUint32);
745 test(I64LOW(t)==0 && I64HIGH(t)==1);
747 test(I64LOW(t)==0 && I64HIGH(t)==0x80000000);
751 test(I64LOW(t)==0x80000000 && I64HIGH(t)==0);
753 test(I64LOW(t)==0 && I64HIGH(t)==0x80000000);
757 test(I64LOW(t)==0 && I64HIGH(t)==0x80000000);
761 test(I64LOW(t)==0 && I64HIGH(t)==0);
763 r=0xC0000000; // 1100000..........
765 test(I64HIGH(t)==1 && I64LOW(t)==0x80000000); // 100000.......
767 test(I64HIGH(t)==3 && I64LOW(t)==0);
769 test(I64HIGH(t)==6 && I64LOW(t)==0);
771 r = MAKE_TINT64(0,KMaxTUint32);
773 test(I64LOW(t)==0 && I64HIGH(t)==KMaxTUint32);
777 r = MAKE_TINT64(3,0);
779 test(I64HIGH(t)==1 && I64LOW(t)==0x80000000);
781 test(I64HIGH(t)==0 && I64LOW(t)==0xC0000000);
783 r = MAKE_TINT64(0x80000000,0);
785 test(I64HIGH(t)==KMaxTUint32 && I64LOW(t)==0);
787 test(I64HIGH(t)==KMaxTUint32 && I64LOW(t)==KMaxTUint32);
789 test(I64HIGH(t)==KMaxTUint32 && I64LOW(t)==KMaxTUint32);
791 test(I64HIGH(t)==KMaxTUint32 && I64LOW(t)==KMaxTUint32);
793 r = MAKE_TINT64(0x80000000,0);
795 test(I64HIGH(t)==KMaxTUint32 && I64LOW(t)==0x80000000);
797 r = MAKE_TINT64(0x80000000,0);
799 test(I64LOW(t)==KMaxTUint32 && I64HIGH(t)==KMaxTUint32);
801 r = MAKE_TINT64(KMaxTUint32, 0);
803 test(I64HIGH(t)==KMaxTUint32 && I64LOW(t)==KMaxTUint32);
805 r = MAKE_TINT64(0x40000000,0);
807 test(I64HIGH(t)==1 && I64LOW(t)==0);
809 test(I64HIGH(t)==0 && I64LOW(t)==0x80000000);
811 test(I64HIGH(t)==0 && I64LOW(t)==1);
813 test(I64HIGH(t)==0 && I64LOW(t)==0);
820 // Test some more operators
823 test.Start(_L("unary -"));
824 TInt64 r=0, x(KMinTInt32);
826 test(I64INT(r)==KMinTInt32);
828 x = MAKE_TINT64(0,0x80000000);
830 test(I64INT(r)==KMinTInt32);
837 test(I64INT(r)==-1 && I64INT(x)==0);
839 test(I64INT(r)==0 && I64INT(x)==1);
841 test(I64INT(r)==1 && I64INT(x)==2);
845 test(I64INT(r)==KMinTInt32 && I64INT(x)==KMinTInt32+1);
849 test(I64INT(r)==(TInt)KMaxTUint32 && I64HIGH(x)==1 && I64LOW(x)==0);
851 test(I64HIGH(r)==1 && I64LOW(r)==0 && I64HIGH(x)==1 && I64LOW(x)==1);
856 test(I64INT(r)==0 && I64INT(x)==0);
858 test(I64INT(r)==1 && I64INT(x)==1);
860 test(I64INT(r)==2 && I64INT(x)==2);
864 test(I64INT(r)==KMinTInt32+1 && I64INT(x)==KMinTInt32+1);
868 test(I64HIGH(r) && I64HIGH(x)==1 && I64LOW(x)==0);
870 test(I64HIGH(r)==1 && I64LOW(r)==0 && I64HIGH(x)==1 && I64LOW(x)==1);
878 test(I64INT(r)==1 && I64INT(x)==0);
880 test(I64INT(r)==0 && I64INT(x)==-1);
882 test(I64INT(r)==-1 && I64INT(x)==-2);
886 test(I64INT(r)==KMinTInt32+1 && I64INT(x)==KMinTInt32);
891 test(I64HIGH(r)==1 && I64LOW(r)==0 && I64HIGH(x)==0 && I64LOW(x)==KMaxTUint32);
893 test(I64HIGH(r)==0 && I64LOW(r)==KMaxTUint32 && I64HIGH(x)==0 && I64LOW(x)==KMaxTUint32-1);
895 x = MAKE_TINT64(KMaxTUint32,KMaxTUint32);
897 test(I64HIGH(r)==KMaxTUint32 && I64LOW(r)==KMaxTUint32 && I64HIGH(x)==KMaxTUint32 && I64LOW(x)==KMaxTUint32-1);
902 test(I64INT(r)==0 && I64INT(x)==0);
904 test(I64INT(r)==-1 && I64INT(x)==-1);
906 test(I64INT(r)==-2 && I64INT(x)==-2);
910 test(I64INT(r)==KMinTInt32 && I64INT(x)==KMinTInt32);
915 test(I64HIGH(r)==0 && I64LOW(r)==KMaxTUint32 && I64HIGH(x)==0 && I64LOW(x)==KMaxTUint32);
917 test(I64HIGH(r)==0 && I64LOW(r)==KMaxTUint32-1 && I64HIGH(x)==0 && I64LOW(x)==KMaxTUint32-1);
919 x = MAKE_TINT64(KMaxTUint32,KMaxTUint32);
921 test(I64HIGH(r)==KMaxTUint32 && I64LOW(r)==KMaxTUint32-1 && I64HIGH(x)==KMaxTUint32 && I64LOW(x)==KMaxTUint32-1);
926 test.Next(_L("Binary +"));
929 test(I64INT(r)==KMinTInt32+1 && I64INT(x)==KMinTInt32);
933 test(I64INT(r)==0 && I64INT(x)==-1);
935 test(I64INT(r)==0 && I64INT(x)==1);
939 test(I64HIGH(r)==1 && I64LOW(r)==KMaxTUint-1);
944 test(I64HIGH(r)==0 && I64LOW(r)==KMaxTUint32);
949 test(I64HIGH(r)==0 && I64LOW(r)==KMaxTUint32);
953 test(I64HIGH(r)==1 && I64LOW(r)==KMaxTUint32-1);
956 x = MAKE_TINT64(KMaxTUint32,KMaxTUint32);
958 test(I64HIGH(r)==KMaxTUint32 && I64LOW(r)==KMaxTUint32);
961 x = MAKE_TINT64(KMaxTUint32,KMaxTUint32);
964 test(I64HIGH(r)==KMaxTUint32 && I64LOW(r)==KMaxTUint32);
969 test(I64INT(r)==KMinTInt32);
975 test(I64INT(r)==KMinTInt32);
985 test(I64HIGH(r)==0 && I64LOW(r)==KMaxTUint32-1);
989 test(I64HIGH(r)==0 && I64LOW(r)==KMaxTUint32);
991 x = MAKE_TINT64(KMaxTUint32,KMaxTUint32);
993 test(I64HIGH(r)==KMaxTUint32 && I64LOW(r)==KMaxTUint32-1);
998 test(I64HIGH(r)==0 && I64LOW(r)==KMaxTUint32-(TUint)KMinTInt32);
999 x = MAKE_TINT64(KMaxTUint32,KMaxTUint32);
1001 test(I64HIGH(r)==KMaxTUint32 && I64LOW(r)==0x7fffffff);
1011 test.Next(_L("Binary -"));
1014 test(I64INT(r)==KMinTInt32);
1024 test(I64INT(r)==-1);
1033 test(I64HIGH(r)==0 && I64LOW(r)==KMaxTUint32);
1037 test(I64HIGH(r)==0 && I64LOW(r)==KMaxTUint32-1);
1039 x = MAKE_TINT64(KMaxTUint32,KMaxTUint32);
1041 test(I64HIGH(r)==KMaxTUint32 && I64LOW(r)==KMaxTUint32-1);
1047 test(I64HIGH(r)==0 && I64LOW(r)==KMaxTUint32);
1057 test(I64HIGH(r)==0 && I64LOW(r)==KMaxTUint32);
1060 test(I64HIGH(r)==0 && I64LOW(r)==KMaxTUint32-1);
1063 x = MAKE_TINT64(KMaxTUint32,KMaxTUint32);
1065 test(I64HIGH(r)==KMaxTUint32 && I64LOW(r)==KMaxTUint32);
1068 x = MAKE_TINT64(KMaxTUint32,KMaxTUint32);
1070 test(I64HIGH(r)==KMaxTUint32 && I64LOW(r)==KMaxTUint32-1);
1075 test(I64INT(r)==KMinTInt32);
1081 test(I64INT(r)==KMinTInt32);
1096 test(I64INT(r)==KMinTInt32);
1107 LOCAL_C void Test4()
1108 // still more operators
1111 test.Start(_L("Binary *"));
1112 TInt64 r(0), x(1), y(0);
1118 test(I64INT(r)==-1);
1126 test(I64INT(r)==KMinTInt32);
1134 test(I64LOW(r)==0 && I64HIGH(r)==0x40000000);
1139 test(I64LOW(r)==1 && I64HIGH(r)==0xfffffffe);
1143 test.Next(_L("Binary /"));
1155 test(I64INT(r)==-5);
1172 test(I64INT(r)==KMinTInt32);
1184 x = MAKE_TINT64(KMaxTUint32,KMaxTUint32);
1188 y = MAKE_TINT64(KMaxTUint32,KMaxTUint32);
1196 x = MAKE_TINT64(4,257629747);
1199 test(I64LOW(r)==8 && I64HIGH(r)==0);
1201 x = MAKE_TINT64(3452,533254);
1207 test.Next(_L("binary %%"));
1213 x = MAKE_TINT64(234893,23494);
1223 test.Next(_L("Lsr"));
1225 r = MAKE_TINT64(3,0);
1227 test(I64HIGH(r)==1 && I64LOW(r)==0x80000000);
1229 test(I64HIGH(r)==0 && I64LOW(r)==0xC0000000);
1231 r = MAKE_TINT64(0x80000000,0);
1233 test(I64HIGH(r)==1 && I64LOW(r)==0);
1234 //test(I64HIGH(r)==KMaxTUint32 && I64LOW(r)==0);
1236 //test(I64HIGH(r)==KMaxTUint32 && I64LOW(r)==KMaxTUint32);
1237 test(I64HIGH(r)==0 && I64LOW(r)==1);
1239 r = MAKE_TINT64(0x80000000,0);
1241 test(I64HIGH(r)==0 && I64LOW(r)==0x80000000);
1242 //test(I64HIGH(r)==KMaxTUint32 && I64LOW(r)==0x80000000);
1244 r = MAKE_TINT64(0x80000000,0);
1246 test(I64LOW(r)==1 && I64HIGH(r)==0);
1247 //test(I64LOW(r)==KMaxTUint32 && I64HIGH(r)==KMaxTUint32);
1249 r = MAKE_TINT64(KMaxTUint32, 0);
1251 test(I64HIGH(r)==0 && I64LOW(r)==KMaxTUint32);
1252 //test(I64HIGH(r)==KMaxTUint32 && I64LOW(r)==KMaxTUint32);
1256 test.Next(_L("Mul10"));
1257 const TInt64 KMaxDiv10= KMaxTInt64 / 10;
1258 const TInt64 KStep=MAKE_TINT64(0x003dfe03, 0xf7ea23cd);
1259 for(TInt64 jj=-KMaxDiv10; jj<=KMaxDiv10; jj+=KStep)
1270 test(I64INT(r)==(KMinTInt/10)*10);
1274 test(I64HIGH(r)==9 && I64LOW(r)==0xFFFFFFF6);
1277 test(r==MAKE_TINT64(0,KMaxTUint32));
1281 test.Next(_L("DivMod"));
1282 TInt64 seed = MAKE_TINT64(0x0000336a,0xb2001a78);
1283 for (TInt i=0; i<200; i++)
1285 TInt o=Math::Rand(seed);
1286 TInt p=Math::Rand(seed);
1287 TInt r=Math::Rand(seed);
1288 TInt q=Math::Rand(seed);
1290 DivModTest(MAKE_TINT64(0,q), MAKE_TINT64(0,r));
1291 DivModTest(MAKE_TINT64(r,q), MAKE_TINT64(o,p));
1292 DivModTest(MAKE_TINT64(p,q), MAKE_TINT64(0,o));
1293 DivModTest(MAKE_TINT64(0,p), MAKE_TINT64(r,o));
1295 DivModTest(-MAKE_TINT64(0,q), -MAKE_TINT64(0,r));
1296 DivModTest( MAKE_TINT64(0,q), -MAKE_TINT64(0,r));
1297 DivModTest(-MAKE_TINT64(0,q), MAKE_TINT64(0,r));
1299 DivModTest(-MAKE_TINT64(r,q), -MAKE_TINT64(o,p));
1300 DivModTest( MAKE_TINT64(r,q), -MAKE_TINT64(o,p));
1301 DivModTest(-MAKE_TINT64(r,q), MAKE_TINT64(o,p));
1303 DivModTest(-MAKE_TINT64(0,p), -MAKE_TINT64(r,o));
1304 DivModTest( MAKE_TINT64(0,p), -MAKE_TINT64(r,o));
1305 DivModTest(-MAKE_TINT64(0,p), MAKE_TINT64(r,o));
1311 LOCAL_C void Test5()
1312 // still more operators
1315 // fast multiply by 10
1316 test.Start(_L("Mul10"));
1323 test(I64INT(r)==-10);
1327 test(I64INT(r)==KMinTInt32-(KMinTInt32%10));
1331 test(I64INT(r)==10);
1335 test(I64LOW(r)==(KMaxTUint32-(KMaxTUint%10)) && I64HIGH(r)==0);
1338 test(r==TInt64(KMaxTUint32-(KMaxTUint%10))*10);
1341 test(r==TInt64(KMaxTUint32-(KMaxTUint%10))*100);
1344 test.Next(_L("Comparison operators"));
1346 // == , !=, <= and >=
1347 test.Next(_L("==, !=, <= and >="));
1349 TInt64 x(KMinTInt32);
1351 test(r==x && r!=y && r>=x && r<=x);
1355 test(r==x && r!=y && r>=x && r<=x);
1359 test(r==x && r!=y && r>=x && r<=x);
1363 test(r==x && r!=y && r>=x && r<=x);
1367 test(r==x && r!=y && r>=x && r<=x);
1369 r = MAKE_TINT64(KMaxTUint32,KMaxTUint32);
1370 x = MAKE_TINT64(KMaxTUint32,KMaxTUint32);
1371 test(x==r && x!=y && x>=r && x<=r);
1374 test.Next(_L(">=, <=, > and <"));
1377 test(x>r && x>=r && r<x && r<=x);
1381 test(r>x && x<r && r>=x && x<=r);
1385 test(r>x && x<r && r>=x && x<=r);
1389 test(r>x && x<r && r>=x && x<=r);
1391 r = MAKE_TINT64(KMaxTUint32,KMaxTUint32);
1392 x = MAKE_TINT64(KMaxTUint32,KMaxTUint32-1);
1393 test(r>x && x<r && r>=x && x<=r);
1395 r = MAKE_TINT64(0x80000000,0);
1396 x = MAKE_TINT64(KMaxTInt32,KMaxTUint32);
1404 x = MAKE_TINT64(0x80000000,1);
1405 test(r<x && x>r && x!=r && r<=x && x>=r);
1407 r = MAKE_TINT64(KMaxTInt32,KMaxTUint32);
1409 test(r>x && x<r && x!=r && r>=x && x<=r);
1411 // multiply top bits
1412 test.Next(_L("MulTop"));
1423 r = MAKE_TINT64(KMaxTInt,KMaxTUint);
1428 r = MAKE_TINT64(KMaxTInt,KMaxTUint);
1433 r = MAKE_TINT64(0x80000000,0);
1434 x = MAKE_TINT64(0x80000000,0);
1437 test(I64INT(r)==0x40000000);
1439 r = MAKE_TINT64(0x18763529,0x93263921);
1440 x = MAKE_TINT64(0x0abcdef0,0x647239ea);
1447 // TInt64(0xac11b680,0x1e603000) * TInt64(0x014a5c20,0xc9d58740)
1449 TPtrC8 a4=_L8("ac11b6801e603000");
1450 TPtrC8 a5=_L8("014a5c20c9d58740");
1454 x = MAKE_TINT64(0x014a5c20,0xc9d58740);
1456 r = MAKE_TINT64(0xac11b680,0x1e603000);
1457 y = MAKE_TINT64(0x0963fbc4,0x415c0000); // Expected result (bottom 64 bits)
1463 r = MAKE_TINT64(0xac11b680,0x1e603000);
1464 y = MAKE_TINT64(0x00de0cc1,0xa89d70dc); // Expected result (top 64 bits)
1472 GLDEF_C TInt E32Main()
1475 test.Start(_L("Constructors"));
1477 test.Next(_L("Unary operators"));
1479 test.Next(_L("Operators 1"));
1481 test.Next(_L("Operators 2"));
1483 test.Next(_L("Operators 3"));
1485 test.Next(_L("Operators 4"));