os/kernelhwsrv/kerneltest/e32test/math/t_i64.cpp
changeset 0 bde4ae8d615e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/os/kernelhwsrv/kerneltest/e32test/math/t_i64.cpp	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,1489 @@
     1.4 +// Copyright (c) 1995-2009 Nokia Corporation and/or its subsidiary(-ies).
     1.5 +// All rights reserved.
     1.6 +// This component and the accompanying materials are made available
     1.7 +// under the terms of the License "Eclipse Public License v1.0"
     1.8 +// which accompanies this distribution, and is available
     1.9 +// at the URL "http://www.eclipse.org/legal/epl-v10.html".
    1.10 +//
    1.11 +// Initial Contributors:
    1.12 +// Nokia Corporation - initial contribution.
    1.13 +//
    1.14 +// Contributors:
    1.15 +//
    1.16 +// Description:
    1.17 +// e32test\math\t_i64.cpp
    1.18 +// Tests TInt64
    1.19 +// Overview:
    1.20 +// Test 64-bit integer functionality.
    1.21 +// API Information:
    1.22 +// TInt64.
    1.23 +// Details:
    1.24 +// - Construct TInt64 with specified range of integer, real, high
    1.25 +// and low values and check constructor, copy constructor are as expected.
    1.26 +// - Test all the operators for range of values and check it is as expected.
    1.27 +// - Check the logical shift of specified number of bits is as expected.
    1.28 +// - Check multiplication of 64 bit integer by the specified 64 bit integer 
    1.29 +// using MulTop, fast multiplication of 64 bit integer by 10.
    1.30 +// - Verify the 64 bit integer divide and mod results are as expected.
    1.31 +// Platforms/Drives/Compatibility:
    1.32 +// All.
    1.33 +// Assumptions/Requirement/Pre-requisites:
    1.34 +// Failures and causes:
    1.35 +// Base Port information:
    1.36 +// 
    1.37 +//
    1.38 +
    1.39 +#include <e32test.h>
    1.40 +#include <e32math.h>
    1.41 +
    1.42 +inline TInt __i64multop(TInt64& aX, TInt64& aValue)
    1.43 +			{	Uint64 __lowResult; \
    1.44 +				Uint64 __highResult; \
    1.45 +				Math::UMul64(aX, aValue, __highResult, __lowResult); \
    1.46 +				aX = static_cast<TInt64>(__highResult); \
    1.47 +				return (__lowResult == UI64LIT(0x0000000000000000)) ?	-2 : \
    1.48 +				(__lowResult < UI64LIT(0x8000000000000000)) ?	-1 : \
    1.49 +				(__lowResult == UI64LIT(0x8000000000000000)) ?	0  : \
    1.50 +				/*__lowResult > UI64LIT(0x8000000000000000)*/	1; \
    1.51 +			}
    1.52 +
    1.53 +#define	I64MULTOP(x, value) __i64multop(x, (value))
    1.54 +
    1.55 +
    1.56 +TInt HexMulAdd(TUint8 a1,TUint8 a2,TUint8& answer,TUint8& carry)
    1.57 +	{
    1.58 +	TUint x1= a1>'9' ? a1-'a'+10 : a1-'0';
    1.59 +	TUint x2= a2>'9' ? a2-'a'+10 : a2-'0';
    1.60 +	TUint a= answer>'9' ? answer-'a'+10 : answer-'0';
    1.61 +	TUint c= carry>'9' ? carry-'a'+10 : carry-'0';
    1.62 +	if (x1>15) return (KErrArgument);
    1.63 +	if (x2>15) return (KErrArgument);
    1.64 +	if (a>15) return (KErrArgument);
    1.65 +	if (c>15) return (KErrArgument);
    1.66 +	a+=(x1*x2)+c;
    1.67 +	c=a/16;
    1.68 +	a=a%16;
    1.69 +	a= a>9 ? a-10+'a' : a+'0';
    1.70 +	c= c>9 ? c-10+'a' : c+'0';
    1.71 +	answer=(TUint8)a;
    1.72 +	carry=(TUint8)c;
    1.73 +	return(KErrNone);
    1.74 +	}
    1.75 +
    1.76 +TInt HexMul(TDesC8& a1,TDesC8& a2,TDes8& a3)
    1.77 +//
    1.78 +// Infinite precision hex multiplier
    1.79 +//
    1.80 +	{
    1.81 +	TInt l1=a1.Length();
    1.82 +	TInt l2=a2.Length();
    1.83 +	TInt l3=l1+l2;
    1.84 +	if (a3.MaxLength()<l3)
    1.85 +		return(KErrArgument);
    1.86 +	a3.Zero();
    1.87 +	TInt x;
    1.88 +	TInt y;
    1.89 +	TInt z;
    1.90 +	for (x=0;x<l3;x++)
    1.91 +		a3.Append('0');
    1.92 +	for (y=0;y<l2;y++)
    1.93 +		{
    1.94 +		TUint8 carry='0';
    1.95 +		for (z=0;z<l1;z++)
    1.96 +			{
    1.97 +			if(HexMulAdd(a2[l2-y-1],a1[l1-z-1],a3[l3-y-z-1],carry)!=KErrNone)
    1.98 +				return(KErrArgument);
    1.99 +			}
   1.100 +		if(HexMulAdd('0','0',a3[l3-y-l1-1],carry)!=KErrNone)
   1.101 +			return(KErrArgument);
   1.102 +		}
   1.103 +	return(KErrNone);
   1.104 +	}
   1.105 +
   1.106 +
   1.107 +LOCAL_D RTest test(_L("T_I64"));
   1.108 +
   1.109 +LOCAL_C void SlowDivMod(const TInt64& aA, const TInt64& aB, TInt64& aDiv, TInt64& aMod)
   1.110 +//
   1.111 +//	Calculate Division/Remainder using repeated subtraction
   1.112 +//
   1.113 +	{
   1.114 +		TInt negative=0;
   1.115 +		TInt64 t=0;
   1.116 +
   1.117 +		if (aA<0)
   1.118 +			{
   1.119 +			negative=1;
   1.120 +			aMod=-aA;
   1.121 +			}
   1.122 +		else
   1.123 +			{
   1.124 +			aMod=aA;
   1.125 +			}
   1.126 +		if (aB<0)
   1.127 +			{
   1.128 +			if (negative)
   1.129 +				negative=0;
   1.130 +			else
   1.131 +				negative=1;
   1.132 +			t=-aB;
   1.133 +			}
   1.134 +		else
   1.135 +			{
   1.136 +			t=aB;
   1.137 +			}
   1.138 +		aDiv=0;
   1.139 +
   1.140 +		if ((t & UI64LIT(0xffffffff00000000)) == 0)
   1.141 +			{
   1.142 +			while (aMod >= (t << 31))
   1.143 +				{
   1.144 +				aDiv += static_cast<TUint32>(1 << 31);
   1.145 +				aMod -= t << 31;
   1.146 +				}
   1.147 +			}
   1.148 +		if ((t & UI64LIT(0xffffff0000000000)) == 0)
   1.149 +			{
   1.150 +			while (aMod >= (t << 23))
   1.151 +				{
   1.152 +				aDiv += 1 << 23;
   1.153 +				aMod -= t << 23;
   1.154 +				}
   1.155 +			}
   1.156 +		if ((t & UI64LIT(0xffff000000000000)) == 0)
   1.157 +			{
   1.158 +			while (aMod >= (t << 15))
   1.159 +				{
   1.160 +				aDiv += 1 << 15;
   1.161 +				aMod -= t << 15;
   1.162 +				}
   1.163 +			}
   1.164 +		if ((t & UI64LIT(0xff00000000000000)) == 0)
   1.165 +			{
   1.166 +			while (aMod >= (t << 7))
   1.167 +				{
   1.168 +				aDiv += 1 << 7;
   1.169 +				aMod -= t << 7;
   1.170 +				}
   1.171 +			}
   1.172 +		if ((t & UI64LIT(0xf000000000000000)) == 0)
   1.173 +			{
   1.174 +			while (aMod >= (t << 3))
   1.175 +				{
   1.176 +				aDiv += 1 << 3;
   1.177 +				aMod -= t << 3;
   1.178 +				}
   1.179 +			}
   1.180 +		while (aMod >= t)
   1.181 +			{
   1.182 +			++aDiv;
   1.183 +			aMod -= t;
   1.184 +			}
   1.185 +
   1.186 +		if (negative)
   1.187 +			{
   1.188 +			aDiv=-aDiv;
   1.189 +			}
   1.190 +
   1.191 +		if (aA < 0)
   1.192 +			{
   1.193 +			aMod =- aMod;	
   1.194 +			}
   1.195 +	}
   1.196 +
   1.197 +LOCAL_C void DivModTest(const TInt64& aA, const TInt64& aB)
   1.198 +//
   1.199 +//	Test DivMod against SlowDivMod
   1.200 +//
   1.201 +	{
   1.202 +
   1.203 +	if (aB!=0)
   1.204 +		{
   1.205 +		TInt64 n(aA),d(aB);
   1.206 +		TInt64 div=0,mod=0,res=0;
   1.207 +		
   1.208 +		SlowDivMod(n,d,div,mod);
   1.209 +		
   1.210 +		res = n % d;
   1.211 +		n /= d;
   1.212 +		
   1.213 +		test(n==div);
   1.214 +		test(res==mod);
   1.215 +		}
   1.216 +	}
   1.217 +
   1.218 +
   1.219 +LOCAL_C void Test1()
   1.220 +	{
   1.221 +	// Test the constructors
   1.222 +
   1.223 +	// TInt64()
   1.224 +	test.Start(_L("Default constructor"));
   1.225 +	TInt64 t1;
   1.226 +	t1 = 0; // to prevent uninitialised warnings
   1.227 +	(void)(t1 > 0); // to prevent unused warnings
   1.228 +	
   1.229 +	// TInt64(TInt aVal)
   1.230 +	test.Next(_L("TInt64(TInt aVal)"));
   1.231 +	TInt64 t2(0);
   1.232 +	test(I64LOW(t2)==0 && I64HIGH(t2)==0);
   1.233 +	TInt64 t3(1);  	 
   1.234 +	test(I64LOW(t3)==1 && I64HIGH(t3)==0);
   1.235 +	TInt64 t4(KMaxTInt32);
   1.236 +	test(I64LOW(t4)==(TUint)KMaxTInt32 && I64HIGH(t4)==0);
   1.237 +	TInt64 t5(-1);
   1.238 +	test(I64INT(t5)==-1);
   1.239 +	test(I64LOW(t5)==KMaxTUint32 && I64HIGH(t5)==KMaxTUint32);
   1.240 +	TInt64 t6(KMinTInt32); 	
   1.241 +	test(I64INT(t6)==KMinTInt32);
   1.242 +
   1.243 +	// TInt64(TUint aVal)
   1.244 +	test.Next(_L("TInt64(TUint aVal)"));
   1.245 +	TInt64 t7((TUint)0);
   1.246 +	test(I64LOW(t7)==0 && I64HIGH(t7)==0);
   1.247 +	TInt64 t8((TUint)1);  	 
   1.248 +	test(I64LOW(t8)==1 && I64HIGH(t8)==0);
   1.249 +	TInt64 t9(KMaxTUint32);
   1.250 +	test(I64LOW(t9)==KMaxTUint32 && I64HIGH(t9)==0);
   1.251 +
   1.252 +	// TInt64(TUint aHigh,TUint aLow)
   1.253 +	test.Next(_L("TInt64(TUint aHigh,TUint aLow)"));
   1.254 +	TInt64 t10 = MAKE_TINT64(0,0);
   1.255 +	test(I64LOW(t10)==0 && I64HIGH(t10)==0);
   1.256 +	TInt64 t11 = MAKE_TINT64(KMaxTUint32,KMaxTUint32);   // highest value stored === (2**64)-1
   1.257 +	test(I64LOW(t11)==KMaxTUint32 && I64HIGH(t11)==KMaxTUint32);
   1.258 +
   1.259 +	// TInt64(TReal aVal)
   1.260 +	test.Next(_L("TInt64(TReal aVal)"));
   1.261 +	TInt64 t12((TInt64)1.0);
   1.262 +	test(I64LOW(t12)==1 && I64HIGH(t12)==0);
   1.263 +	TInt64 t15((TInt64)4.99);
   1.264 +	test(I64LOW(t15)==4 && I64HIGH(t15)==0);
   1.265 +	
   1.266 +	TReal x;
   1.267 +	
   1.268 +	x = -9.223372036854776831e18; // -2^63 - 2^10 (to ensure rounding outside of TInt64 range)
   1.269 +	TInt64 t16((TInt64)x);
   1.270 +	test(t16==KMinTInt64);
   1.271 +	TInt64 t17((TInt64)0.5);
   1.272 +	test(I64LOW(t17)==0 && I64HIGH(t17)==0);
   1.273 +	TInt64 t18((TInt64)0.0);
   1.274 +	test(I64LOW(t18)==0 && I64HIGH(t18)==0);
   1.275 +	TInt64 t19((TInt64)-123325.23411412);
   1.276 +	test(I64LOW(t19)==(TUint)(-123325) && I64HIGH(t19)==0xffffffff);
   1.277 +	TInt64 t20((TInt64)1.0E-1);
   1.278 +	test(I64LOW(t20)==0 && I64HIGH(t20)==0);
   1.279 +	
   1.280 +	// Make variable volatile to protect ourselves from compiler optimisations. Given that the
   1.281 +	// following test is negative with unspecified results, we don't really care if we do not have
   1.282 +	// FPU/compiler parity.
   1.283 +	volatile TReal xout;
   1.284 +	xout = 9.223372036854776831e18; // 2^63 + 2^10 (to ensure rounding outside of TInt64 range)
   1.285 +	TInt64 t21((TInt64)xout);
   1.286 +
   1.287 +	// IEEE 754 does not specify the value to be returned when a conversion
   1.288 +	// is performed on a value that is outside the range of the target, only
   1.289 +	// that an invalid operation exception be raised if the io fp exception
   1.290 +	// is not masked.
   1.291 +#if defined(__WINS__) || defined(__X86__)
   1.292 +	// The x86 FPU returns KMin... as the "indefinite number"
   1.293 +	test(t21 == KMinTInt64);
   1.294 +#else
   1.295 +	// The target compiler support libraries return KMax...
   1.296 +	test(t21 == KMaxTInt64);
   1.297 +#endif
   1.298 +
   1.299 +	TReal limit=1048576.0*1048576.0*8192.0;		// integers <2^53 in modulus can be represented exactly
   1.300 +	TInt64 t22((TInt64)limit);
   1.301 +	test(I64LOW(t22)==0 && I64HIGH(t22)==0x00200000);
   1.302 +	TInt64 t23((TInt64)(limit-1.0));
   1.303 +	test(I64LOW(t23)==0xffffffff && I64HIGH(t23)==0x001fffff);
   1.304 +	TReal i64limit=limit*1024.0;				// 2^63
   1.305 +	// Make variable volatile to protect ourselves from compiler optimisations. Given that the
   1.306 +	// following test is negative with unspecified results, we don't really care if we do not have
   1.307 +	// FPU/compiler parity.
   1.308 +	volatile TReal i64limitout=i64limit;
   1.309 +	TInt64 t24((TInt64)i64limitout);
   1.310 +	
   1.311 +	// IEEE 754 does not specify the value to be returned when a conversion
   1.312 +	// is performed on a value that is outside the range of the target, only
   1.313 +	// that an invalid operation exception be raised if the io fp exception
   1.314 +	// is not masked.
   1.315 +#if defined(__WINS__) || defined(__X86__)
   1.316 +	// The x86 FPU returns KMin... as the "indefinite number"
   1.317 +	test(t24 == KMinTInt64);
   1.318 +#else
   1.319 +	// The target compiler support libraries return KMax...
   1.320 +	test(t24 == KMaxTInt64);
   1.321 +#endif
   1.322 +
   1.323 +	TInt64 t25((TInt64)(i64limit-1024.0));
   1.324 +	test(I64LOW(t25)==0xfffffc00 && I64HIGH(t25)==0x7fffffff);
   1.325 +	TInt64 t26((TInt64)-i64limit);
   1.326 +	test(I64LOW(t26)==0x00000000 && I64HIGH(t26)==0x80000000);
   1.327 +	TInt64 t27((TInt64)(1024.0-i64limit));
   1.328 +	test(I64LOW(t27)==0x00000400 && I64HIGH(t27)==0x80000000);
   1.329 +
   1.330 +
   1.331 +	TInt i;
   1.332 +	TInt64 l;
   1.333 +	for (i=-99; i<100; i++)
   1.334 +		{
   1.335 +		x=1;
   1.336 +		l=1;
   1.337 +		TReal a(i);
   1.338 +		TInt64 b(i);
   1.339 +		while (Abs(x)<limit)
   1.340 +			{
   1.341 +//			test.Printf(_L("Testing %g\n"),x);
   1.342 +			TInt64 ll((TInt64)x);
   1.343 +			test(ll==l);
   1.344 +			ll=0;
   1.345 +			ll = (TInt64)x;
   1.346 +			test(ll==l);
   1.347 +			x*=a;
   1.348 +			l*=b;
   1.349 +			if (i==1 || i==0 || (i==-1 && l==TInt64(1)))
   1.350 +				break;
   1.351 +			}
   1.352 +		}
   1.353 +
   1.354 +	// TInt64::GetTReal
   1.355 +	test.Next(_L("TInt64::GetTReal"));
   1.356 +
   1.357 +	// GCC does optimise large portions of the test code out and there can be small
   1.358 +	// differences in the way GCC and the FPU round floating point values.
   1.359 +	// We isolate the following test by giving it its own variables. This should
   1.360 +	// prevent values returned by the FPU from being compared with wrong GCC calculations.
   1.361 +	TInt64 m = MAKE_TINT64(0x7fffffff,0xffffffff);
   1.362 +	TReal xy = I64REAL(m);
   1.363 +	TReal xx = 1048576.0*1048576.0*1048576.0*8.0 - 1.0; // 2^63 - 1
   1.364 +	test(xy == xx);
   1.365 +	//
   1.366 +
   1.367 +	l = MAKE_TINT64(0x7fffffff,0xfffffc00);
   1.368 +	x = I64REAL(l);
   1.369 +
   1.370 +	test(x == (i64limit - 1024.0));
   1.371 +
   1.372 +	l = MAKE_TINT64(0x80000000,0x00000000);
   1.373 +	x = I64REAL(l);
   1.374 +
   1.375 +	test(x == -i64limit);
   1.376 +
   1.377 +	l = MAKE_TINT64(0x80000000,0x00000400);
   1.378 +	x = I64REAL(l);
   1.379 +
   1.380 +	test(x == (1024.0 - i64limit));
   1.381 +
   1.382 +	l = MAKE_TINT64(0x00000001,0x00000000);
   1.383 +	x = I64REAL(l);
   1.384 +
   1.385 +	test(x == (65536.0 * 65536.0));
   1.386 +
   1.387 +	l = MAKE_TINT64(0xffffffff,0x00000000);
   1.388 +	x = I64REAL(l);
   1.389 +
   1.390 +	test(x == (-65536.0 * 65536.0));
   1.391 +
   1.392 +	for (i=-99; i<100; i++)
   1.393 +		{
   1.394 +		x=1;
   1.395 +		l=1;
   1.396 +		TReal a(i);
   1.397 +		TInt64 b(i);
   1.398 +		while (Abs(x)<limit)
   1.399 +			{
   1.400 +//			test.Printf(_L("Testing %g\n"),x);
   1.401 +			TReal y = I64REAL(l);
   1.402 +			test(y==x);
   1.403 +			x*=a;
   1.404 +			l*=b;
   1.405 +			if (i==1 || i==0 || (i==-1 && l==TInt64(1)))
   1.406 +				break;
   1.407 +			}
   1.408 +		}
   1.409 + 
   1.410 +	// TInt64(const TInt64& aVal)
   1.411 +	test.Next(_L("Copy constructor"));
   1.412 +	TInt64 t13(t10);
   1.413 +	test(I64LOW(t13)==I64LOW(t10) && I64HIGH(t13)==I64HIGH(t10));
   1.414 +
   1.415 +	test.Next(_L("Set"));
   1.416 +	t13 = MAKE_TINT64(0, 0);
   1.417 +	test(I64LOW(t13)==0 && I64HIGH(t13)==0);
   1.418 +	test.End();
   1.419 +	}
   1.420 +
   1.421 +LOCAL_C void Test1_2()
   1.422 +//
   1.423 +//	Test Unary operators -, and +
   1.424 +//
   1.425 +	{
   1.426 +	TInt64 r(0),q(0);
   1.427 +
   1.428 +	r=1;
   1.429 +	test(-r==-1);
   1.430 +	test(+r==1);
   1.431 +	r=-100;
   1.432 +	test(-r==100);
   1.433 +	test(+r==-100);
   1.434 +	r = MAKE_TINT64(540423,21344);
   1.435 +	test(-r==(q-r));
   1.436 +	test(+r==r);
   1.437 +	test(+r==MAKE_TINT64(540423,21344));
   1.438 +	r=0;
   1.439 +	test(-r==0);
   1.440 +	test(+r==0);
   1.441 +	}
   1.442 +
   1.443 +
   1.444 +LOCAL_C void Test2()
   1.445 +	{
   1.446 +	// Test the operators
   1.447 +
   1.448 +	// =
   1.449 +	test.Start(_L("="));
   1.450 +	TInt64 r=0,r2=0, a = MAKE_TINT64(12345,54321);
   1.451 +	r=KMaxTInt32;
   1.452 +	test(I64LOW(r)==(TUint)KMaxTInt32 && I64HIGH(r)==0);
   1.453 +	r2=r=KMinTInt32;
   1.454 +	test(I64INT(r)==KMinTInt32);
   1.455 +	test(I64INT(r2)==KMinTInt32);
   1.456 +	r2=r=KMaxTUint32;
   1.457 +	test(I64LOW(r)==KMaxTUint32 && I64HIGH(r)==0);
   1.458 +	test(I64LOW(r2)==KMaxTUint32 && I64HIGH(r2)==0);
   1.459 +	r2=r=a;
   1.460 +	test(I64LOW(r)==I64LOW(a) && I64HIGH(r)==I64HIGH(a));
   1.461 +	test(I64LOW(r2)==I64LOW(a) && I64HIGH(r2)==I64HIGH(a));
   1.462 +
   1.463 +	r2=r=(TInt64)((TReal)1.2);
   1.464 +	test(r==1);
   1.465 +	test(r2==1);
   1.466 +	r2=r=(TInt64)((TReal)20.9);
   1.467 +	test(r==20);
   1.468 +	test(r2==20);
   1.469 +	r2=r=(TInt64)((TReal)-100.2);
   1.470 +	test(r==-100);
   1.471 +	test(r2==-100);
   1.472 +	
   1.473 +
   1.474 +
   1.475 +	// +=, -=, *=, /=, %=, >>=, <<=, >>, <<
   1.476 +	// += 
   1.477 +	test.Next(_L("+="));
   1.478 +	r=-1;
   1.479 +	r+=1;
   1.480 +	test(I64INT(r)==0);
   1.481 +
   1.482 +	r+=1;
   1.483 +	test(I64INT(r)==1);
   1.484 +
   1.485 +	r=KMaxTUint32;
   1.486 +	r+=1;
   1.487 +	test(I64INT(r)-1==(TInt)KMaxTUint32);
   1.488 +
   1.489 +	r=KMinTInt32;
   1.490 +	r+=1;
   1.491 +	test(I64INT(r)==KMinTInt32+1);
   1.492 +
   1.493 +	r=0;
   1.494 +	r+=MAKE_TINT64(0,0x80000000u);
   1.495 +	test(r==MAKE_TINT64(0,0x80000000u));
   1.496 +
   1.497 +	// -=
   1.498 +	test.Next(_L("-="));						 
   1.499 +	r=-1;
   1.500 +	r-=1;
   1.501 +	test(I64INT(r)==-2);
   1.502 +	r=0;
   1.503 +	r-=1;
   1.504 +	test(I64INT(r)==-1);
   1.505 +	r=1;
   1.506 +	r-=1;
   1.507 +	test(I64INT(r)==0);
   1.508 +	r=KMaxTUint32;
   1.509 +	r+=1;
   1.510 +	r-=1;
   1.511 +	test(I64HIGH(r)==0 && I64LOW(r)==KMaxTUint32);
   1.512 +	test(I64INT(r)==(TInt)KMaxTUint32);
   1.513 +	r-=1;
   1.514 +	test(I64INT(r)==(TInt)(KMaxTUint32-1));
   1.515 +
   1.516 +
   1.517 +	// *= 
   1.518 +	test.Next(_L("*="));
   1.519 +	r=KMaxTUint32;			// ffffffff * 2 = 1 fffffffe
   1.520 +	r*=2;
   1.521 +	test(I64HIGH(r)==1 && I64LOW(r)==KMaxTUint32-1);
   1.522 +
   1.523 +	r=KMaxTUint32-1;
   1.524 +	r*=2;
   1.525 +	r+=2;
   1.526 +	test(I64HIGH(r)==1 && I64LOW(r)==KMaxTUint32-1);
   1.527 +
   1.528 +	r=KMaxTUint32;
   1.529 +	r+=1;
   1.530 +	r*=2;
   1.531 +	test(I64HIGH(r)==2 && I64LOW(r)==0);
   1.532 +
   1.533 +	TUint PosMinTInt=(TUint)KMinTInt32;
   1.534 +	r=PosMinTInt;
   1.535 +	r*=-1;
   1.536 +	test(I64INT(r)==KMinTInt32);
   1.537 +
   1.538 +	r=KMinTInt32;
   1.539 +	r*=-1;
   1.540 +	r-=1;
   1.541 +	test(I64INT(r)==KMaxTInt32);
   1.542 +
   1.543 +	r=KMaxTUint32;	   	// ffffffff * ffffffff + (2 * ffffffff) = ffffffff ffffffff
   1.544 +	r*=KMaxTUint32;
   1.545 +	r+=KMaxTUint32;
   1.546 +	r+=KMaxTUint32;
   1.547 +	test(I64LOW(r)==KMaxTUint32 && I64HIGH(r)==KMaxTUint32);
   1.548 +
   1.549 +	r=KMaxTUint32;
   1.550 +	r+=1;
   1.551 +	r*=2;
   1.552 +	test(I64LOW(r)==0 && I64HIGH(r)==2);
   1.553 +
   1.554 +
   1.555 +	// /=
   1.556 +	test.Next(_L("/="));
   1.557 +	r=4;
   1.558 +	r/=2;
   1.559 +	test(I64INT(r)==2);
   1.560 +	r=4;
   1.561 +	r/=-2;
   1.562 +	test(I64INT(r)==-2);
   1.563 +	r=-4;
   1.564 +	r/=1;
   1.565 +	test(I64INT(r)==-4);
   1.566 +	r=-8;
   1.567 +
   1.568 +	r/=-2;
   1.569 +	test(I64INT(r)==4);
   1.570 +	r=4;
   1.571 +
   1.572 +	r/=4;
   1.573 +	test(I64INT(r)==1);
   1.574 +	r=0;
   1.575 +
   1.576 +	r/=4;
   1.577 +	test(I64INT(r)==0);
   1.578 +	r=KMaxTUint32;
   1.579 +	TInt64 z(KMaxTUint32);
   1.580 +	r/=z;
   1.581 +	test(I64INT(r)==1);
   1.582 +	r=KMinTInt32;
   1.583 +	z=KMinTInt32;
   1.584 +	r/=z;
   1.585 +	test(I64INT(r)==1);
   1.586 +	r=KMinTInt32;
   1.587 +	z = MAKE_TINT64(0,(TUint)KMinTInt32);
   1.588 +	r/=z;
   1.589 +	test(I64INT(r)==-1);
   1.590 +	r=KMaxTUint32;			
   1.591 +	r*=2;
   1.592 +	r/=2;
   1.593 +	test(I64HIGH(r)==0 && I64LOW(r)==KMaxTUint32);
   1.594 +   	r=KMaxTUint32;
   1.595 +	a=KMaxTUint32;
   1.596 +	r*=z;
   1.597 +	r/=z;
   1.598 +	test(I64HIGH(r)==0 && I64LOW(r)==KMaxTUint32);
   1.599 +	r = MAKE_TINT64(0,(TUint)KMinTInt32);
   1.600 +	r/=-1;
   1.601 +	test(I64LOW(r)==(TUint)KMinTInt32);
   1.602 +	r=0;
   1.603 +	r/=KMaxTUint32;
   1.604 +	test(I64INT(r)==0);
   1.605 +	r=0;
   1.606 +	r/=KMinTInt32;
   1.607 +	test(I64INT(r)==0);
   1.608 +	r=0;
   1.609 +	TInt64 b = MAKE_TINT64(KMaxTUint32,KMaxTUint32);
   1.610 +	r/=b;
   1.611 +	test(I64INT(r)==0);
   1.612 +	TInt64 c = MAKE_TINT64(KMaxTUint32,KMaxTUint32);	  // -1/Anything == 0
   1.613 +	TInt64* cptr = &c;		// MSVC compiler calculates -1/anything at compile time
   1.614 +	*cptr /= KMaxTUint32;	// and gets it wrong if we don't use a pointer, bizarre.
   1.615 +	test(I64LOW(c)==0 && I64HIGH(c)==0);
   1.616 +	r=-1;
   1.617 +	z=1;
   1.618 +	r/=z;
   1.619 +	test(r==-1);
   1.620 +	r=-r;
   1.621 +	r/=z;
   1.622 +	test(r==1);
   1.623 +	r = MAKE_TINT64(0x01,KMaxTUint32);
   1.624 +	z=2;
   1.625 +	r/=z;
   1.626 +	test(r==TInt64(KMaxTUint32));
   1.627 +	r = MAKE_TINT64(0x01,KMaxTUint32);
   1.628 +	z = MAKE_TINT64(0,KMaxTUint32);
   1.629 +	r/=z;
   1.630 +	test(r==TInt64(2));
   1.631 +	r = MAKE_TINT64(1,0);
   1.632 +	r/=z;
   1.633 +	test(r==TInt64(1));
   1.634 +	r = MAKE_TINT64(6221,5621243);
   1.635 +	z = MAKE_TINT64(3,42011);
   1.636 +	r/=z;
   1.637 +	test(r==2073);
   1.638 +	r=100;
   1.639 +	z=99;
   1.640 +	r/=z;
   1.641 +	test(r==1);
   1.642 +	r = MAKE_TINT64(17,KMaxTUint32);
   1.643 +	z = MAKE_TINT64(0,8);
   1.644 +	test((r/=z)==MAKE_TINT64(0x2, 0x3fffffff));
   1.645 +
   1.646 +	// %=
   1.647 +	test.Next(_L("%="));
   1.648 +	r=4;
   1.649 +	r%=4;
   1.650 +	test(I64INT(r)==0);
   1.651 +	r=4;
   1.652 +	r%=1;
   1.653 +	test(I64INT(r)==0);
   1.654 +	r=5;
   1.655 +	r%=3;
   1.656 +	test(I64INT(r)==2);
   1.657 +	r=(-5);
   1.658 +	r%=3;
   1.659 +	test(I64INT(r)==(-2));
   1.660 +	r = MAKE_TINT64(134,KMaxTUint32-10342);
   1.661 +	z = MAKE_TINT64(134,0);
   1.662 +	test((r%=z)==KMaxTUint32-10342);
   1.663 +	r = MAKE_TINT64(134,KMaxTUint32-10342);
   1.664 +	z = MAKE_TINT64(134,KMaxTUint32-10343);
   1.665 +	test((r%=z)==1);
   1.666 +	r = MAKE_TINT64(1363,0xfd432ab0u);
   1.667 +	z = MAKE_TINT64(0,16);
   1.668 +	test((r%=z)==0);
   1.669 +	
   1.670 +	r=-10;
   1.671 +	r%=3;
   1.672 +	test(r==-1);
   1.673 +	r=-10;
   1.674 +	r%=-3;
   1.675 +	test(r==-1);
   1.676 +	r=10;
   1.677 +	r%=3;
   1.678 +	test(r==1);
   1.679 +	r=10;
   1.680 +	r%=-3;
   1.681 +	test(r==1);
   1.682 +
   1.683 +	// <<= and >>=
   1.684 +	// <<=
   1.685 +	test.Next(_L("<<="));
   1.686 +	r=1;
   1.687 +	r<<=32;
   1.688 +	test(I64LOW(r)==0 && I64HIGH(r)==1);
   1.689 +	r<<=31;
   1.690 +	test(I64LOW(r)==0 && I64HIGH(r)==0x80000000);
   1.691 +
   1.692 +	r=1;
   1.693 +	r<<=31;
   1.694 +	test(I64LOW(r)==0x80000000 && I64HIGH(r)==0);
   1.695 +	r<<=32;
   1.696 +	test(I64LOW(r)==0 && I64HIGH(r)==0x80000000);
   1.697 +
   1.698 +	r=1;
   1.699 +	r<<=63;
   1.700 +	test(I64LOW(r)==0 && I64HIGH(r)==0x80000000);
   1.701 +
   1.702 +	r=0;
   1.703 +	r<<=32;
   1.704 +	test(I64LOW(r)==0 && I64HIGH(r)==0);
   1.705 +
   1.706 +	r=0xC0000000; 	// 1100000..........
   1.707 +	r<<=1;
   1.708 +	test(I64HIGH(r)==1 && I64LOW(r)==0x80000000);	// 100000.......
   1.709 +	r<<=1;
   1.710 +	test(I64HIGH(r)==3 && I64LOW(r)==0);
   1.711 +	r<<=1;
   1.712 +	test(I64HIGH(r)==6 && I64LOW(r)==0);
   1.713 +
   1.714 +	r = MAKE_TINT64(0,KMaxTUint32);
   1.715 +	r<<=32;
   1.716 +	test(I64LOW(r)==0 && I64HIGH(r)==KMaxTUint32);
   1.717 +
   1.718 +	// >>=
   1.719 +	test.Next(_L(">>="));
   1.720 +	r = MAKE_TINT64(3,0);
   1.721 +	r>>=1;
   1.722 +	test(I64HIGH(r)==1 && I64LOW(r)==0x80000000);
   1.723 +	r>>=1;
   1.724 +	test(I64HIGH(r)==0 && I64LOW(r)==0xC0000000);
   1.725 +
   1.726 +	r = MAKE_TINT64(0x80000000,0);  
   1.727 +	r>>=(31);
   1.728 +	test(I64HIGH(r)==KMaxTUint32 && I64LOW(r)==0);
   1.729 +	r>>=(32);
   1.730 +	test(I64HIGH(r)==KMaxTUint32 && I64LOW(r)==KMaxTUint32);
   1.731 +
   1.732 +	r = MAKE_TINT64(0x80000000,0);
   1.733 +	r>>=(32);
   1.734 +	test(I64HIGH(r)==KMaxTUint32 && I64LOW(r)==0x80000000);
   1.735 +
   1.736 +	r = MAKE_TINT64(0x80000000,0);
   1.737 +	r>>=63;
   1.738 +	test(I64LOW(r)==KMaxTUint32 && I64HIGH(r)==KMaxTUint32);
   1.739 +
   1.740 +	r = MAKE_TINT64(KMaxTUint32, 0);
   1.741 +	r>>=32;
   1.742 +	test(I64HIGH(r)==KMaxTUint32 && I64LOW(r)==KMaxTUint32);
   1.743 +
   1.744 +	// <<
   1.745 +	test.Next(_L("<<"));
   1.746 +	r=1;
   1.747 +	TInt64 t = r<<32;
   1.748 +	test(I64LOW(t)==0 && I64HIGH(t)==1);
   1.749 +	t = t<<31;
   1.750 +	test(I64LOW(t)==0 && I64HIGH(t)==0x80000000);
   1.751 +
   1.752 +	r=1;
   1.753 +	t = r<<31;
   1.754 +	test(I64LOW(t)==0x80000000 && I64HIGH(t)==0);
   1.755 +	t = t<<32;
   1.756 +	test(I64LOW(t)==0 && I64HIGH(t)==0x80000000);
   1.757 +
   1.758 +	r=1;
   1.759 +	t = r<<63;
   1.760 +	test(I64LOW(t)==0 && I64HIGH(t)==0x80000000);
   1.761 +
   1.762 +	r=0;
   1.763 +	t = r<<32;
   1.764 +	test(I64LOW(t)==0 && I64HIGH(t)==0);
   1.765 +
   1.766 +	r=0xC0000000; 	// 1100000..........
   1.767 +	t = r<<1;
   1.768 +	test(I64HIGH(t)==1 && I64LOW(t)==0x80000000);	// 100000.......
   1.769 +	t = t<<1;
   1.770 +	test(I64HIGH(t)==3 && I64LOW(t)==0);
   1.771 +	t = t<<1;
   1.772 +	test(I64HIGH(t)==6 && I64LOW(t)==0);
   1.773 +
   1.774 +	r = MAKE_TINT64(0,KMaxTUint32);
   1.775 +	t = r<<32;
   1.776 +	test(I64LOW(t)==0 && I64HIGH(t)==KMaxTUint32);
   1.777 +
   1.778 +	// >>
   1.779 +	test.Next(_L(">>"));
   1.780 +	r = MAKE_TINT64(3,0);
   1.781 +	t = r>>1;
   1.782 +	test(I64HIGH(t)==1 && I64LOW(t)==0x80000000);
   1.783 +	t = t>>1;
   1.784 +	test(I64HIGH(t)==0 && I64LOW(t)==0xC0000000);
   1.785 +
   1.786 +	r = MAKE_TINT64(0x80000000,0);  
   1.787 +	t = r>>(31);
   1.788 +	test(I64HIGH(t)==KMaxTUint32 && I64LOW(t)==0);
   1.789 +	t = t>>(32);
   1.790 +	test(I64HIGH(t)==KMaxTUint32 && I64LOW(t)==KMaxTUint32);
   1.791 +	t = t>>1;
   1.792 +	test(I64HIGH(t)==KMaxTUint32 && I64LOW(t)==KMaxTUint32);
   1.793 +	t = t>>16;
   1.794 +	test(I64HIGH(t)==KMaxTUint32 && I64LOW(t)==KMaxTUint32);
   1.795 +
   1.796 +	r = MAKE_TINT64(0x80000000,0);
   1.797 +	t = r>>(32);
   1.798 +	test(I64HIGH(t)==KMaxTUint32 && I64LOW(t)==0x80000000);
   1.799 +
   1.800 +	r = MAKE_TINT64(0x80000000,0);
   1.801 +	t = r>>63;
   1.802 +	test(I64LOW(t)==KMaxTUint32 && I64HIGH(t)==KMaxTUint32);
   1.803 +
   1.804 +	r = MAKE_TINT64(KMaxTUint32, 0);
   1.805 +	t = r>>32;
   1.806 +	test(I64HIGH(t)==KMaxTUint32 && I64LOW(t)==KMaxTUint32);
   1.807 +
   1.808 +	r = MAKE_TINT64(0x40000000,0);
   1.809 +	t = r>>30;
   1.810 +	test(I64HIGH(t)==1 && I64LOW(t)==0);
   1.811 +	t = r>>31;
   1.812 +	test(I64HIGH(t)==0 && I64LOW(t)==0x80000000);
   1.813 +	t = r>>62;
   1.814 +	test(I64HIGH(t)==0 && I64LOW(t)==1);
   1.815 +	t = r>>63;
   1.816 +	test(I64HIGH(t)==0 && I64LOW(t)==0);
   1.817 +
   1.818 +	test.End();
   1.819 +	}
   1.820 +
   1.821 +LOCAL_C void Test3()
   1.822 +	{
   1.823 +	// Test some more operators
   1.824 +
   1.825 +	// unary -
   1.826 +	test.Start(_L("unary -"));
   1.827 +	TInt64 r=0, x(KMinTInt32);
   1.828 +	r=-x;
   1.829 +	test(I64INT(r)==KMinTInt32);
   1.830 +
   1.831 +	x = MAKE_TINT64(0,0x80000000);
   1.832 +	r=-x;
   1.833 +	test(I64INT(r)==KMinTInt32);
   1.834 +
   1.835 +	// ++
   1.836 +	// post increment
   1.837 +	test.Next(_L("++"));
   1.838 +	x=-1;
   1.839 +	r=x++;
   1.840 +	test(I64INT(r)==-1 && I64INT(x)==0);
   1.841 +	r=x++;
   1.842 +	test(I64INT(r)==0 && I64INT(x)==1);
   1.843 +	r=x++;
   1.844 +	test(I64INT(r)==1 && I64INT(x)==2);
   1.845 +
   1.846 +	x=KMinTInt32;
   1.847 +	r=x++;
   1.848 +	test(I64INT(r)==KMinTInt32 && I64INT(x)==KMinTInt32+1);
   1.849 +
   1.850 +	x=KMaxTUint32;
   1.851 +	r=x++;
   1.852 +	test(I64INT(r)==(TInt)KMaxTUint32 && I64HIGH(x)==1 && I64LOW(x)==0);
   1.853 +	r=x++;
   1.854 +	test(I64HIGH(r)==1 && I64LOW(r)==0 && I64HIGH(x)==1 && I64LOW(x)==1);
   1.855 +
   1.856 +	// pre increment;
   1.857 +	x=-1;
   1.858 +	r=++x;
   1.859 +	test(I64INT(r)==0 && I64INT(x)==0);
   1.860 +	r=++x;
   1.861 +	test(I64INT(r)==1 && I64INT(x)==1);
   1.862 +	r=++x;
   1.863 +	test(I64INT(r)==2 && I64INT(x)==2);
   1.864 +
   1.865 +	x=KMinTInt32;
   1.866 +	r=++x;
   1.867 +	test(I64INT(r)==KMinTInt32+1 && I64INT(x)==KMinTInt32+1);
   1.868 +
   1.869 +	x=KMaxTUint32;
   1.870 +	r=++x;
   1.871 +	test(I64HIGH(r) && I64HIGH(x)==1 && I64LOW(x)==0);
   1.872 +	r=x++;
   1.873 +	test(I64HIGH(r)==1 && I64LOW(r)==0 && I64HIGH(x)==1 && I64LOW(x)==1);
   1.874 +
   1.875 +	
   1.876 +	// --
   1.877 +	test.Next(_L("--"));
   1.878 +	// post decrement	   
   1.879 +	x=1;
   1.880 +	r=x--;
   1.881 +	test(I64INT(r)==1 && I64INT(x)==0);
   1.882 +	r=x--;
   1.883 +	test(I64INT(r)==0 && I64INT(x)==-1);
   1.884 +	r=x--;
   1.885 +	test(I64INT(r)==-1 && I64INT(x)==-2);
   1.886 +
   1.887 +	x=KMinTInt32+1;
   1.888 +	r=x--;
   1.889 +	test(I64INT(r)==KMinTInt32+1 && I64INT(x)==KMinTInt32);
   1.890 +
   1.891 +	x=KMaxTUint32;
   1.892 +	x+=1;
   1.893 +	r=x--;
   1.894 +	test(I64HIGH(r)==1 && I64LOW(r)==0 && I64HIGH(x)==0 && I64LOW(x)==KMaxTUint32);
   1.895 +	r=x--;
   1.896 +	test(I64HIGH(r)==0 && I64LOW(r)==KMaxTUint32 && I64HIGH(x)==0 && I64LOW(x)==KMaxTUint32-1);
   1.897 +
   1.898 +	x = MAKE_TINT64(KMaxTUint32,KMaxTUint32);
   1.899 +	r=x--;
   1.900 +	test(I64HIGH(r)==KMaxTUint32 && I64LOW(r)==KMaxTUint32 && I64HIGH(x)==KMaxTUint32 && I64LOW(x)==KMaxTUint32-1);
   1.901 +
   1.902 +	// pre decrement	   
   1.903 +	x=1;
   1.904 +	r=--x;
   1.905 +	test(I64INT(r)==0 && I64INT(x)==0);
   1.906 +	r=--x;
   1.907 +	test(I64INT(r)==-1 && I64INT(x)==-1);
   1.908 +	r=--x;
   1.909 +	test(I64INT(r)==-2 && I64INT(x)==-2);
   1.910 +
   1.911 +	x=KMinTInt32+1;
   1.912 +	r=--x;
   1.913 +	test(I64INT(r)==KMinTInt32 && I64INT(x)==KMinTInt32);
   1.914 +
   1.915 +	x=KMaxTUint32;
   1.916 +	x+=1;
   1.917 +	r=--x;
   1.918 +	test(I64HIGH(r)==0 && I64LOW(r)==KMaxTUint32 && I64HIGH(x)==0 && I64LOW(x)==KMaxTUint32);
   1.919 +	r=--x;
   1.920 +	test(I64HIGH(r)==0 && I64LOW(r)==KMaxTUint32-1 && I64HIGH(x)==0 && I64LOW(x)==KMaxTUint32-1);
   1.921 +
   1.922 +	x = MAKE_TINT64(KMaxTUint32,KMaxTUint32);
   1.923 +	r=--x;
   1.924 +	test(I64HIGH(r)==KMaxTUint32 && I64LOW(r)==KMaxTUint32-1 && I64HIGH(x)==KMaxTUint32 && I64LOW(x)==KMaxTUint32-1);
   1.925 +
   1.926 +  
   1.927 +
   1.928 +	// Binary +
   1.929 +	test.Next(_L("Binary +"));
   1.930 +	x=KMinTInt32;
   1.931 +	r=x+1;
   1.932 +	test(I64INT(r)==KMinTInt32+1 && I64INT(x)==KMinTInt32);
   1.933 +
   1.934 +	x=-1;
   1.935 +	r=x+1;
   1.936 +	test(I64INT(r)==0 && I64INT(x)==-1);
   1.937 +	x=r+1;
   1.938 +	test(I64INT(r)==0 && I64INT(x)==1);
   1.939 +
   1.940 +	x=KMaxTUint32;
   1.941 +	r=x+KMaxTUint32;
   1.942 +	test(I64HIGH(r)==1 && I64LOW(r)==KMaxTUint-1);
   1.943 +
   1.944 +	x=KMaxTUint32;
   1.945 +	x+=1;
   1.946 +	r=x+(-1);
   1.947 +	test(I64HIGH(r)==0 && I64LOW(r)==KMaxTUint32);
   1.948 +
   1.949 +	TInt64 y(0);
   1.950 +	x=KMaxTUint32;
   1.951 +	r=x+y;
   1.952 +	test(I64HIGH(r)==0 && I64LOW(r)==KMaxTUint32);
   1.953 +
   1.954 +	y=KMaxTUint32;
   1.955 +	r=x+y;
   1.956 +	test(I64HIGH(r)==1 && I64LOW(r)==KMaxTUint32-1);
   1.957 +
   1.958 +	y=0;
   1.959 +	x = MAKE_TINT64(KMaxTUint32,KMaxTUint32);
   1.960 +	r=x+y;
   1.961 +	test(I64HIGH(r)==KMaxTUint32 && I64LOW(r)==KMaxTUint32);
   1.962 +
   1.963 +	y=1;
   1.964 +	x = MAKE_TINT64(KMaxTUint32,KMaxTUint32);
   1.965 +	x-=1;
   1.966 +	r=x+y;
   1.967 +	test(I64HIGH(r)==KMaxTUint32 && I64LOW(r)==KMaxTUint32);
   1.968 +
   1.969 +	y=0;
   1.970 +	x=KMinTInt32;
   1.971 +	r=x+y;
   1.972 +	test(I64INT(r)==KMinTInt32);
   1.973 +
   1.974 +	y=-1;
   1.975 +	x=KMinTInt32;
   1.976 +	x+=1;
   1.977 +	r=x+y;
   1.978 +	test(I64INT(r)==KMinTInt32);
   1.979 +	
   1.980 +	y=-1;
   1.981 +	x=-1;
   1.982 +	r=x+y;
   1.983 +	test(I64INT(r)==-2);
   1.984 +
   1.985 +	y=-1;
   1.986 +	x=KMaxTUint32;
   1.987 +	r=x+y;
   1.988 +	test(I64HIGH(r)==0 && I64LOW(r)==KMaxTUint32-1);
   1.989 +	y=-1;
   1.990 +	x+=1;
   1.991 +	r=x+y;
   1.992 +	test(I64HIGH(r)==0 && I64LOW(r)==KMaxTUint32);
   1.993 +	y=-1;
   1.994 +	x = MAKE_TINT64(KMaxTUint32,KMaxTUint32);
   1.995 +	r=x+y;
   1.996 +	test(I64HIGH(r)==KMaxTUint32 && I64LOW(r)==KMaxTUint32-1);
   1.997 +
   1.998 +	y=KMinTInt32;
   1.999 +	x=KMaxTUint32;
  1.1000 +	r=x+y;
  1.1001 +	test(I64HIGH(r)==0 && I64LOW(r)==KMaxTUint32-(TUint)KMinTInt32);
  1.1002 +	x = MAKE_TINT64(KMaxTUint32,KMaxTUint32);
  1.1003 +	r=x+y;
  1.1004 +	test(I64HIGH(r)==KMaxTUint32 && I64LOW(r)==0x7fffffff);
  1.1005 +
  1.1006 +	y=KMinTInt32;
  1.1007 +	x=-(KMinTInt32+1);
  1.1008 +	x+=1;
  1.1009 +	r=x+y;
  1.1010 +	test(I64INT(r)==0);
  1.1011 +
  1.1012 +
  1.1013 +	// Binary -
  1.1014 +	test.Next(_L("Binary -"));
  1.1015 +	x=KMinTInt32+1;
  1.1016 +	r=x-1;
  1.1017 +	test(I64INT(r)==KMinTInt32);
  1.1018 +
  1.1019 +	x=2;
  1.1020 +	r=x-1;
  1.1021 +	test(I64INT(r)==1);
  1.1022 +	x=1;
  1.1023 +	r=x-1;
  1.1024 +	test(I64INT(r)==0);
  1.1025 +	x=0;
  1.1026 +	r=x-1;
  1.1027 +	test(I64INT(r)==-1);
  1.1028 +
  1.1029 +	x=KMaxTUint32;
  1.1030 +	r=x-KMaxTUint32;
  1.1031 +	test(I64INT(r)==0);
  1.1032 +
  1.1033 +	x=KMaxTUint32;
  1.1034 +	x+=1;
  1.1035 +	r=x-1;
  1.1036 +	test(I64HIGH(r)==0 && I64LOW(r)==KMaxTUint32);
  1.1037 +
  1.1038 +	x=KMaxTUint32;
  1.1039 +	r=x-1;
  1.1040 +	test(I64HIGH(r)==0 && I64LOW(r)==KMaxTUint32-1);
  1.1041 +
  1.1042 +	x = MAKE_TINT64(KMaxTUint32,KMaxTUint32);
  1.1043 +	r=x-1;
  1.1044 +	test(I64HIGH(r)==KMaxTUint32 && I64LOW(r)==KMaxTUint32-1);
  1.1045 +
  1.1046 +
  1.1047 +	y=0;
  1.1048 +	x=KMaxTUint32;
  1.1049 +	r=x-y;
  1.1050 +	test(I64HIGH(r)==0 && I64LOW(r)==KMaxTUint32);
  1.1051 +
  1.1052 +	y=KMaxTUint32;
  1.1053 +	r=x-y;
  1.1054 +	test(I64INT(r)==0);
  1.1055 +
  1.1056 +	x=KMaxTUint32;
  1.1057 +	x+=1;
  1.1058 +	y=1;
  1.1059 +	r=x-1;
  1.1060 +   	test(I64HIGH(r)==0 && I64LOW(r)==KMaxTUint32);
  1.1061 +	x-=1;
  1.1062 +	r=x-1;
  1.1063 +	test(I64HIGH(r)==0 && I64LOW(r)==KMaxTUint32-1);
  1.1064 +
  1.1065 +	y=0;
  1.1066 +	x = MAKE_TINT64(KMaxTUint32,KMaxTUint32);
  1.1067 +	r=x-y;
  1.1068 +	test(I64HIGH(r)==KMaxTUint32 && I64LOW(r)==KMaxTUint32);
  1.1069 +
  1.1070 +	y=1;
  1.1071 +	x = MAKE_TINT64(KMaxTUint32,KMaxTUint32);
  1.1072 +	r=x-y;
  1.1073 +	test(I64HIGH(r)==KMaxTUint32 && I64LOW(r)==KMaxTUint32-1);
  1.1074 +
  1.1075 +	y=0;
  1.1076 +	x=KMinTInt32;
  1.1077 +	r=x-y;
  1.1078 +	test(I64INT(r)==KMinTInt32);
  1.1079 +
  1.1080 +	y=1;
  1.1081 +	x=KMinTInt32;
  1.1082 +	x+=1;
  1.1083 +	r=x-y;
  1.1084 +	test(I64INT(r)==KMinTInt32);
  1.1085 +	
  1.1086 +	y=1;
  1.1087 +	x=1;
  1.1088 +	r=x-y;
  1.1089 +	test(I64INT(r)==0);
  1.1090 +
  1.1091 +	y=-1;
  1.1092 +	x=-1;
  1.1093 +	r=x-y;
  1.1094 +	test(I64INT(r)==0);
  1.1095 +
  1.1096 +	x=0;
  1.1097 +	y=KMinTInt32;
  1.1098 +	r=x-y;
  1.1099 +	test(I64INT(r)==KMinTInt32);
  1.1100 +
  1.1101 +	x=KMinTInt32;
  1.1102 +	y=KMinTInt32;
  1.1103 +	r=x-y;
  1.1104 +	test(I64INT(r)==0);
  1.1105 +
  1.1106 +	test.End();
  1.1107 +	}
  1.1108 +
  1.1109 +
  1.1110 +LOCAL_C void Test4()
  1.1111 +// still more operators
  1.1112 +	{
  1.1113 +	// * 
  1.1114 +	test.Start(_L("Binary *"));
  1.1115 +	TInt64 r(0), x(1), y(0);
  1.1116 +	r=x*y;
  1.1117 +	test(I64INT(r)==0);
  1.1118 +
  1.1119 +	y=-1;
  1.1120 +	r=x*y;
  1.1121 +	test(I64INT(r)==-1);
  1.1122 +
  1.1123 +	x=-1;
  1.1124 +	r=x*y;
  1.1125 +	test(I64INT(r)==1);
  1.1126 +
  1.1127 +	x=KMinTInt32;
  1.1128 +	r=x*y;
  1.1129 +	test(I64INT(r)==KMinTInt32);
  1.1130 +
  1.1131 +	y=0;
  1.1132 +	r=x*y;
  1.1133 +	test(I64INT(r)==0);
  1.1134 +
  1.1135 +	y=KMinTInt32;
  1.1136 +	r=x*y;
  1.1137 +	test(I64LOW(r)==0 && I64HIGH(r)==0x40000000);
  1.1138 +
  1.1139 +	y=KMaxTUint32;
  1.1140 +	x=KMaxTUint32;
  1.1141 +	r=x*y;
  1.1142 +	test(I64LOW(r)==1 && I64HIGH(r)==0xfffffffe);
  1.1143 +
  1.1144 +
  1.1145 +	// /
  1.1146 +	test.Next(_L("Binary /"));
  1.1147 +	x=5;
  1.1148 +	y=5;
  1.1149 +	r=x/y;
  1.1150 +	test(I64INT(r)==1);
  1.1151 +
  1.1152 +	y=1;
  1.1153 +	r=x/y;
  1.1154 +	test(I64INT(r)==5);
  1.1155 +
  1.1156 +	x=-5;
  1.1157 +	r=x/y;
  1.1158 +	test(I64INT(r)==-5);
  1.1159 +
  1.1160 +	y=-1;
  1.1161 +	r=x/y;
  1.1162 +	test(I64INT(r)==5);
  1.1163 +	
  1.1164 +	x=-1;
  1.1165 +	r=x/y;
  1.1166 +	test(I64INT(r)==1);
  1.1167 +
  1.1168 +	x=0;
  1.1169 +	r=x/y;
  1.1170 +	test(I64INT(r)==0);
  1.1171 +
  1.1172 +	x=KMinTInt32;
  1.1173 +	y=-1;
  1.1174 +	r=x/y;
  1.1175 +	test(I64INT(r)==KMinTInt32);
  1.1176 +
  1.1177 +	x=KMinTInt32;
  1.1178 +	y=KMinTInt32;
  1.1179 +	r=x/y;
  1.1180 +	test(I64INT(r)==1);
  1.1181 +
  1.1182 +	x=KMaxTUint32;
  1.1183 +	y=KMaxTUint32;
  1.1184 +	r=x/y;
  1.1185 +	test(I64INT(r)==1);
  1.1186 +
  1.1187 +	x = MAKE_TINT64(KMaxTUint32,KMaxTUint32);
  1.1188 +	r=x/y;	   
  1.1189 +	test(I64INT(r)==0);
  1.1190 +
  1.1191 +	y = MAKE_TINT64(KMaxTUint32,KMaxTUint32);
  1.1192 +	r=x/y;
  1.1193 +	test(I64INT(r)==1);
  1.1194 +
  1.1195 +	y=KMinTInt32;
  1.1196 +	r=x/y;
  1.1197 +	test(I64INT(r)==0);
  1.1198 +  
  1.1199 +    x = MAKE_TINT64(4,257629747);
  1.1200 +    y=KMaxTInt;
  1.1201 +	r=x/y;
  1.1202 +	test(I64LOW(r)==8 && I64HIGH(r)==0);
  1.1203 +
  1.1204 +	x = MAKE_TINT64(3452,533254);
  1.1205 +	x=-x;
  1.1206 +	x=x/x;
  1.1207 +	test(x==1);
  1.1208 +
  1.1209 +  	// %
  1.1210 +	test.Next(_L("binary %%"));
  1.1211 +	x=2341;
  1.1212 +	y=2340;
  1.1213 +	test(x%y==1);
  1.1214 +	y=2;
  1.1215 +	test(x%y==1);
  1.1216 +	x = MAKE_TINT64(234893,23494);
  1.1217 +	test(x%x==0);
  1.1218 +	test(x%y==0);
  1.1219 +	x=-x;
  1.1220 +	y=10;
  1.1221 +	test(x%y==-2);
  1.1222 +	test(x%(-y)==-2);
  1.1223 +	
  1.1224 +					 
  1.1225 +	// Lsr
  1.1226 +	test.Next(_L("Lsr"));
  1.1227 +
  1.1228 +	r = MAKE_TINT64(3,0);
  1.1229 +	I64LSR(r, 1);
  1.1230 +	test(I64HIGH(r)==1 && I64LOW(r)==0x80000000);
  1.1231 +	I64LSR(r, 1);
  1.1232 +	test(I64HIGH(r)==0 && I64LOW(r)==0xC0000000);
  1.1233 +
  1.1234 +	r = MAKE_TINT64(0x80000000,0);  
  1.1235 +	I64LSR(r, 31);
  1.1236 +	test(I64HIGH(r)==1 && I64LOW(r)==0);
  1.1237 +	//test(I64HIGH(r)==KMaxTUint32 && I64LOW(r)==0);
  1.1238 +	I64LSR(r, 32);
  1.1239 +	//test(I64HIGH(r)==KMaxTUint32 && I64LOW(r)==KMaxTUint32);
  1.1240 +	test(I64HIGH(r)==0 && I64LOW(r)==1);
  1.1241 +
  1.1242 +	r = MAKE_TINT64(0x80000000,0);
  1.1243 +	I64LSR(r, 32);
  1.1244 +	test(I64HIGH(r)==0 && I64LOW(r)==0x80000000);
  1.1245 +	//test(I64HIGH(r)==KMaxTUint32 && I64LOW(r)==0x80000000);
  1.1246 +
  1.1247 +	r = MAKE_TINT64(0x80000000,0);
  1.1248 +	I64LSR(r, 63);
  1.1249 +	test(I64LOW(r)==1 && I64HIGH(r)==0);
  1.1250 +	//test(I64LOW(r)==KMaxTUint32 && I64HIGH(r)==KMaxTUint32);
  1.1251 +
  1.1252 +	r = MAKE_TINT64(KMaxTUint32, 0);
  1.1253 +	I64LSR(r, 32);
  1.1254 +	test(I64HIGH(r)==0 && I64LOW(r)==KMaxTUint32);
  1.1255 +	//test(I64HIGH(r)==KMaxTUint32 && I64LOW(r)==KMaxTUint32);
  1.1256 +
  1.1257 +
  1.1258 +	// Mul10
  1.1259 +	test.Next(_L("Mul10"));
  1.1260 +	const TInt64 KMaxDiv10= KMaxTInt64 / 10;
  1.1261 +	const TInt64 KStep=MAKE_TINT64(0x003dfe03, 0xf7ea23cd);
  1.1262 +	for(TInt64 jj=-KMaxDiv10; jj<=KMaxDiv10; jj+=KStep)
  1.1263 +		{
  1.1264 +		r=jj;
  1.1265 +		r *= 10;
  1.1266 +		test(r==jj*10);
  1.1267 +		r/=10;
  1.1268 +		test(r==jj);
  1.1269 +		}
  1.1270 +
  1.1271 +	r=KMinTInt32/10;
  1.1272 +	r *= 10;
  1.1273 +	test(I64INT(r)==(KMinTInt/10)*10);
  1.1274 +
  1.1275 +	r=KMaxTUint32;
  1.1276 +	r *= 10;
  1.1277 +	test(I64HIGH(r)==9 && I64LOW(r)==0xFFFFFFF6);
  1.1278 +
  1.1279 +	r/=10;
  1.1280 +	test(r==MAKE_TINT64(0,KMaxTUint32));
  1.1281 +
  1.1282 +
  1.1283 +	// DivMod
  1.1284 +	test.Next(_L("DivMod"));
  1.1285 +	TInt64 seed = MAKE_TINT64(0x0000336a,0xb2001a78);
  1.1286 +	for (TInt i=0; i<200; i++)
  1.1287 +		{
  1.1288 +		TInt o=Math::Rand(seed);
  1.1289 +		TInt p=Math::Rand(seed);
  1.1290 +		TInt r=Math::Rand(seed);
  1.1291 +		TInt q=Math::Rand(seed);
  1.1292 +
  1.1293 +		DivModTest(MAKE_TINT64(0,q), MAKE_TINT64(0,r));
  1.1294 +		DivModTest(MAKE_TINT64(r,q), MAKE_TINT64(o,p));
  1.1295 +		DivModTest(MAKE_TINT64(p,q), MAKE_TINT64(0,o));
  1.1296 +		DivModTest(MAKE_TINT64(0,p), MAKE_TINT64(r,o));
  1.1297 +		
  1.1298 +		DivModTest(-MAKE_TINT64(0,q), -MAKE_TINT64(0,r));
  1.1299 +		DivModTest( MAKE_TINT64(0,q), -MAKE_TINT64(0,r));
  1.1300 +		DivModTest(-MAKE_TINT64(0,q),  MAKE_TINT64(0,r));
  1.1301 +
  1.1302 +		DivModTest(-MAKE_TINT64(r,q), -MAKE_TINT64(o,p));
  1.1303 +		DivModTest( MAKE_TINT64(r,q), -MAKE_TINT64(o,p));
  1.1304 +		DivModTest(-MAKE_TINT64(r,q),  MAKE_TINT64(o,p));
  1.1305 +
  1.1306 +		DivModTest(-MAKE_TINT64(0,p), -MAKE_TINT64(r,o));
  1.1307 + 		DivModTest( MAKE_TINT64(0,p), -MAKE_TINT64(r,o));
  1.1308 +		DivModTest(-MAKE_TINT64(0,p),  MAKE_TINT64(r,o));
  1.1309 +		}
  1.1310 +
  1.1311 +	test.End();
  1.1312 +	}
  1.1313 +
  1.1314 +LOCAL_C void Test5()
  1.1315 +// still more operators
  1.1316 +	{
  1.1317 +
  1.1318 +	// fast multiply by 10
  1.1319 +	test.Start(_L("Mul10"));
  1.1320 +   	TInt64 r(0);
  1.1321 +	r *= 10;
  1.1322 +	test(I64INT(r)==0);
  1.1323 +
  1.1324 +	r=-1;
  1.1325 +	r *= 10;
  1.1326 +	test(I64INT(r)==-10);
  1.1327 +
  1.1328 +	r=KMinTInt32/10;
  1.1329 +	r *= 10;
  1.1330 +	test(I64INT(r)==KMinTInt32-(KMinTInt32%10));
  1.1331 +
  1.1332 +	r=1;
  1.1333 +	r *= 10;
  1.1334 +	test(I64INT(r)==10);
  1.1335 +
  1.1336 +	r=KMaxTUint32/10;
  1.1337 +	r *= 10;
  1.1338 +	test(I64LOW(r)==(KMaxTUint32-(KMaxTUint%10)) && I64HIGH(r)==0);
  1.1339 +
  1.1340 +	r *= 10;
  1.1341 +	test(r==TInt64(KMaxTUint32-(KMaxTUint%10))*10);
  1.1342 +
  1.1343 +	r *= 10;
  1.1344 +	test(r==TInt64(KMaxTUint32-(KMaxTUint%10))*100);
  1.1345 +
  1.1346 + 	// Comparisons
  1.1347 +	test.Next(_L("Comparison operators"));
  1.1348 +
  1.1349 +	// == , !=, <= and >=
  1.1350 +	test.Next(_L("==, !=, <= and >="));
  1.1351 +	r=KMinTInt32;
  1.1352 +	TInt64 x(KMinTInt32);
  1.1353 +	TInt64 y(100);
  1.1354 +	test(r==x && r!=y && r>=x && r<=x);
  1.1355 +
  1.1356 +	r=-1;
  1.1357 +	x=-1;
  1.1358 +	test(r==x && r!=y && r>=x && r<=x);
  1.1359 +
  1.1360 +	r=0;
  1.1361 +	x=0;
  1.1362 +	test(r==x && r!=y && r>=x && r<=x);
  1.1363 +
  1.1364 +	r=1;
  1.1365 +	x=1;
  1.1366 +	test(r==x && r!=y && r>=x && r<=x);
  1.1367 +
  1.1368 +	r=KMaxTUint32;
  1.1369 +	x=KMaxTUint32;
  1.1370 +	test(r==x && r!=y && r>=x && r<=x);
  1.1371 +
  1.1372 +	r = MAKE_TINT64(KMaxTUint32,KMaxTUint32);
  1.1373 +	x = MAKE_TINT64(KMaxTUint32,KMaxTUint32);
  1.1374 +	test(x==r && x!=y && x>=r && x<=r);
  1.1375 +
  1.1376 +	//>=, <=, > and <
  1.1377 +	test.Next(_L(">=, <=, > and <"));
  1.1378 +	r=KMinTInt32;
  1.1379 +	x=KMinTInt32+1;
  1.1380 +	test(x>r && x>=r && r<x && r<=x);
  1.1381 +
  1.1382 +	r=1;
  1.1383 +	x=-1;
  1.1384 +	test(r>x && x<r && r>=x && x<=r);
  1.1385 +
  1.1386 +	r=KMaxTUint32;
  1.1387 +	x=KMaxTUint32-1;
  1.1388 +	test(r>x && x<r && r>=x && x<=r);
  1.1389 +
  1.1390 +	r+=1;
  1.1391 +	x+=1;
  1.1392 +	test(r>x && x<r && r>=x && x<=r);
  1.1393 +
  1.1394 +	r = MAKE_TINT64(KMaxTUint32,KMaxTUint32);
  1.1395 +	x = MAKE_TINT64(KMaxTUint32,KMaxTUint32-1);
  1.1396 +	test(r>x && x<r && r>=x && x<=r);
  1.1397 +
  1.1398 +	r = MAKE_TINT64(0x80000000,0);
  1.1399 +	x = MAKE_TINT64(KMaxTInt32,KMaxTUint32);
  1.1400 +	test(r<x);
  1.1401 +	test(x>r);
  1.1402 +	test(x!=r);
  1.1403 +	test(r<=x);
  1.1404 +	test(x>=r);
  1.1405 +	test(r<0 && x>0);
  1.1406 +
  1.1407 +	x = MAKE_TINT64(0x80000000,1);
  1.1408 +	test(r<x && x>r && x!=r && r<=x && x>=r);
  1.1409 +
  1.1410 +	r = MAKE_TINT64(KMaxTInt32,KMaxTUint32);
  1.1411 +	--r;
  1.1412 +	test(r>x && x<r && x!=r && r>=x && x<=r);
  1.1413 +
  1.1414 +	// multiply top bits
  1.1415 +	test.Next(_L("MulTop"));
  1.1416 +   	r=0;
  1.1417 +    x=0;
  1.1418 +	I64MULTOP(r, x);
  1.1419 +	test(I64INT(r)==0);
  1.1420 +
  1.1421 +	r=1;
  1.1422 +    x=1;
  1.1423 +	I64MULTOP(r, x);
  1.1424 +	test(I64INT(r)==0);
  1.1425 +
  1.1426 +	r = MAKE_TINT64(KMaxTInt,KMaxTUint);
  1.1427 +    x=2;
  1.1428 +	I64MULTOP(r, x);
  1.1429 +	test(I64INT(r)==0);
  1.1430 +
  1.1431 +	r = MAKE_TINT64(KMaxTInt,KMaxTUint);
  1.1432 +    x=4;
  1.1433 +	I64MULTOP(r, x);
  1.1434 +	test(I64INT(r)==1);
  1.1435 +
  1.1436 +    r = MAKE_TINT64(0x80000000,0);
  1.1437 +    x = MAKE_TINT64(0x80000000,0);
  1.1438 +	I64MULTOP(r, x);
  1.1439 +    r>>=32;
  1.1440 +	test(I64INT(r)==0x40000000);
  1.1441 +
  1.1442 +    r = MAKE_TINT64(0x18763529,0x93263921);
  1.1443 +    x = MAKE_TINT64(0x0abcdef0,0x647239ea);
  1.1444 +    TInt64 r2=r;
  1.1445 +    TInt64 x2=x;
  1.1446 +    I64MULTOP(r, x2);
  1.1447 +    I64MULTOP(x, r2);
  1.1448 +    test(r==x);
  1.1449 +
  1.1450 +//	TInt64(0xac11b680,0x1e603000) * TInt64(0x014a5c20,0xc9d58740)
  1.1451 +
  1.1452 +	TPtrC8 a4=_L8("ac11b6801e603000");
  1.1453 +	TPtrC8 a5=_L8("014a5c20c9d58740");
  1.1454 +	TBuf8<64> a6;
  1.1455 +	HexMul(a4,a5,a6);
  1.1456 +
  1.1457 +	x = MAKE_TINT64(0x014a5c20,0xc9d58740); 
  1.1458 +
  1.1459 +	r = MAKE_TINT64(0xac11b680,0x1e603000);
  1.1460 +	y = MAKE_TINT64(0x0963fbc4,0x415c0000); // Expected result (bottom 64 bits)
  1.1461 +
  1.1462 +	r *= x;
  1.1463 +
  1.1464 +	test(r==y);
  1.1465 +
  1.1466 +	r = MAKE_TINT64(0xac11b680,0x1e603000);
  1.1467 +	y = MAKE_TINT64(0x00de0cc1,0xa89d70dc); // Expected result (top 64 bits)
  1.1468 +	I64MULTOP(r, x);
  1.1469 +	test(r==y);
  1.1470 +
  1.1471 +	test.End();
  1.1472 +	}
  1.1473 +
  1.1474 +
  1.1475 +GLDEF_C TInt E32Main()
  1.1476 +    {
  1.1477 +	test.Title();
  1.1478 +	test.Start(_L("Constructors"));
  1.1479 +	Test1();
  1.1480 +	test.Next(_L("Unary operators"));
  1.1481 +	Test1_2();
  1.1482 +	test.Next(_L("Operators 1"));
  1.1483 +	Test2();
  1.1484 +	test.Next(_L("Operators 2"));
  1.1485 +	Test3();
  1.1486 +	test.Next(_L("Operators 3"));
  1.1487 +	Test4();
  1.1488 +	test.Next(_L("Operators 4"));
  1.1489 +	Test5();
  1.1490 +	test.End();
  1.1491 +	return(KErrNone);
  1.1492 +    }