kerneltest/e32test/math/t_i64.cpp
changeset 15 4122176ea935
parent 0 a41df078684a
child 109 b3a1d9898418
equal deleted inserted replaced
0:a41df078684a 15:4122176ea935
   272 	TInt64 t19((TInt64)-123325.23411412);
   272 	TInt64 t19((TInt64)-123325.23411412);
   273 	test(I64LOW(t19)==(TUint)(-123325) && I64HIGH(t19)==0xffffffff);
   273 	test(I64LOW(t19)==(TUint)(-123325) && I64HIGH(t19)==0xffffffff);
   274 	TInt64 t20((TInt64)1.0E-1);
   274 	TInt64 t20((TInt64)1.0E-1);
   275 	test(I64LOW(t20)==0 && I64HIGH(t20)==0);
   275 	test(I64LOW(t20)==0 && I64HIGH(t20)==0);
   276 	
   276 	
   277 	x = 9.223372036854776831e18; // 2^63 + 2^10 (to ensure rounding outside of TInt64 range)
   277 	// Make variable volatile to protect ourselves from compiler optimisations. Given that the
   278 	TInt64 t21((TInt64)x);
   278 	// following test is negative with unspecified results, we don't really care if we do not have
       
   279 	// FPU/compiler parity.
       
   280 	volatile TReal xout;
       
   281 	xout = 9.223372036854776831e18; // 2^63 + 2^10 (to ensure rounding outside of TInt64 range)
       
   282 	TInt64 t21((TInt64)xout);
   279 
   283 
   280 	// IEEE 754 does not specify the value to be returned when a conversion
   284 	// 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
   285 	// 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
   286 	// that an invalid operation exception be raised if the io fp exception
   283 	// is not masked.
   287 	// is not masked.
   293 	TInt64 t22((TInt64)limit);
   297 	TInt64 t22((TInt64)limit);
   294 	test(I64LOW(t22)==0 && I64HIGH(t22)==0x00200000);
   298 	test(I64LOW(t22)==0 && I64HIGH(t22)==0x00200000);
   295 	TInt64 t23((TInt64)(limit-1.0));
   299 	TInt64 t23((TInt64)(limit-1.0));
   296 	test(I64LOW(t23)==0xffffffff && I64HIGH(t23)==0x001fffff);
   300 	test(I64LOW(t23)==0xffffffff && I64HIGH(t23)==0x001fffff);
   297 	TReal i64limit=limit*1024.0;				// 2^63
   301 	TReal i64limit=limit*1024.0;				// 2^63
   298 	TInt64 t24((TInt64)i64limit);
   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);
   299 	
   307 	
   300 	// IEEE 754 does not specify the value to be returned when a conversion
   308 	// 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
   309 	// 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
   310 	// that an invalid operation exception be raised if the io fp exception
   303 	// is not masked.
   311 	// is not masked.
   341 		}
   349 		}
   342 
   350 
   343 	// TInt64::GetTReal
   351 	// TInt64::GetTReal
   344 	test.Next(_L("TInt64::GetTReal"));
   352 	test.Next(_L("TInt64::GetTReal"));
   345 
   353 
   346 	l = MAKE_TINT64(0x7fffffff,0xffffffff);
   354 	// GCC does optimise large portions of the test code out and there can be small
   347 	x = I64REAL(l);
   355 	// differences in the way GCC and the FPU round floating point values.
   348 
   356 	// We isolate the following test by giving it its own variables. This should
   349 	TReal xx = i64limit - 1.0;
   357 	// prevent values returned by the FPU from being compared with wrong GCC calculations.
   350 	test(x == xx);
   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
       
   361 	test(xy == xx);
       
   362 	//
   351 
   363 
   352 	l = MAKE_TINT64(0x7fffffff,0xfffffc00);
   364 	l = MAKE_TINT64(0x7fffffff,0xfffffc00);
   353 	x = I64REAL(l);
   365 	x = I64REAL(l);
   354 
   366 
   355 	test(x == (i64limit - 1024.0));
   367 	test(x == (i64limit - 1024.0));