os/kernelhwsrv/kerneltest/e32test/math/t_r32.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_r32.cpp	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,711 @@
     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_r32.cpp
    1.18 +// T_R32.CPP - Test routines for TReal32
    1.19 +// Also note that these tests do not generally include testing of special values.  This is done
    1.20 +// in T_R96 tests and conversions are tested thoroughly, so explicit tests are unnecessary here.
    1.21 +// Overview:
    1.22 +// Test functionality of operations on 32bit real numbers.
    1.23 +// API Information:
    1.24 +// TReal32. 
    1.25 +// Details:
    1.26 +// - Test the conversion from TReal to TReal32 is as expected.
    1.27 +// - Check addition, subtraction and multiplication of 32-bit floating point
    1.28 +// numbers are as expected.
    1.29 +// - Check division of 32-bit floating-point numbers and verify that it is
    1.30 +// panicked when divided by zero.
    1.31 +// - Test arithmetic exceptions are raised for
    1.32 +// - overflow error during addition, subtraction.
    1.33 +// - overflow, underflow errors during multiplication.
    1.34 +// - overflow, underflow, divided by zero errors during division.
    1.35 +// - overflow, underflow, invalid operation errors during conversion
    1.36 +// from double to float.
    1.37 +// - Check unary operator, equalities and inequalities operators, pre/post 
    1.38 +// increment, decrement operators with TReal32 are as expected.
    1.39 +// Platforms/Drives/Compatibility:
    1.40 +// All 
    1.41 +// Assumptions/Requirement/Pre-requisites:
    1.42 +// Failures and causes:
    1.43 +// Base Port information:
    1.44 +// 
    1.45 +//
    1.46 +
    1.47 +#include "t_math.h"
    1.48 +#include "t_real32.h"
    1.49 +
    1.50 +#if defined(__VC32__)
    1.51 +// Some symbols generated by the VC++ compiler for floating point stuff.
    1.52 +extern "C" {
    1.53 +GLDEF_D TInt _adj_fdiv_m32;
    1.54 +}
    1.55 +#endif
    1.56 +
    1.57 +// Data for tests from T_R32DTA.cpp 
    1.58 +GLREF_D TReal32 addInput[];
    1.59 +GLREF_D TReal32 subInput[];
    1.60 +GLREF_D TReal32 multInput[];
    1.61 +GLREF_D TReal32 divInput[];
    1.62 +GLREF_D TReal32 unaryInput[];
    1.63 +GLREF_D TReal32 incDecInput[];
    1.64 +GLREF_D TInt sizeAdd;
    1.65 +GLREF_D TInt sizeSub;
    1.66 +GLREF_D TInt sizeMult;
    1.67 +GLREF_D TInt sizeDiv;
    1.68 +GLREF_D TInt sizeUnary;
    1.69 +GLREF_D TInt sizeIncDec;
    1.70 +
    1.71 +#if defined (__WINS__) || defined (__X86__)
    1.72 +// Functions from EMGCC32.CPP
    1.73 +GLREF_C TReal32 __addsf3(TReal32 a1,TReal32 a2);
    1.74 +GLREF_C TReal32 __subsf3(TReal32 a1,TReal32 a2);
    1.75 +GLREF_C TReal32 __mulsf3(TReal32 a1,TReal32 a2);
    1.76 +GLREF_C TReal32 __divsf3(TReal32 a1,TReal32 a2);
    1.77 +GLREF_C TReal32 __truncdfsf2(TReal64 a1);
    1.78 +#endif
    1.79 +
    1.80 +GLDEF_D TReal32 NaNTReal32;
    1.81 +GLDEF_D TReal32 posInfTReal32;
    1.82 +GLDEF_D TReal32 negInfTReal32;
    1.83 +GLDEF_D const TReal32 minDenormalTReal32=1.4E-45f;
    1.84 +GLDEF_D TReal NaNTReal;
    1.85 +GLDEF_D TReal posInfTReal;
    1.86 +GLDEF_D TReal negInfTReal;
    1.87 +
    1.88 +enum TOrder
    1.89 +	{
    1.90 +	ELessThan,
    1.91 +	EEqual,
    1.92 +	EGreaterThan
    1.93 +	};
    1.94 +
    1.95 +LOCAL_D RTest test(_L("T_R32"));
    1.96 +
    1.97 +LOCAL_C void initSpecialValues()
    1.98 +//
    1.99 +// Initialise special values
   1.100 +//
   1.101 +	{
   1.102 +
   1.103 +	SReal32 *p32=(SReal32*)&NaNTReal32;
   1.104 +	p32->sign=0;
   1.105 +	p32->exp=KTReal32SpecialExponent;
   1.106 +	p32->man=0x7fffff;
   1.107 +
   1.108 +	p32=(SReal32*)&posInfTReal32;
   1.109 +	p32->sign=0;
   1.110 +	p32->exp=KTReal32SpecialExponent;
   1.111 +	p32->man=0;
   1.112 +
   1.113 +	p32=(SReal32*)&negInfTReal32;
   1.114 +	p32->sign=1;
   1.115 +	p32->exp=KTReal32SpecialExponent;
   1.116 +	p32->man=0;
   1.117 +
   1.118 +	SReal64 *p64=(SReal64*)&NaNTReal;
   1.119 +	p64->sign=0;
   1.120 +	p64->exp=KTReal64SpecialExponent;
   1.121 +	p64->lsm=0xffffffffu;
   1.122 +	p64->msm=0xfffff;
   1.123 +
   1.124 +	p64=(SReal64*)&posInfTReal;
   1.125 +	p64->sign=0;
   1.126 +	p64->exp=KTReal64SpecialExponent;
   1.127 +	p64->lsm=0;
   1.128 +	p64->msm=0;
   1.129 +	
   1.130 +	p64=(SReal64*)&negInfTReal;
   1.131 +	p64->sign=1;
   1.132 +	p64->exp=KTReal64SpecialExponent;
   1.133 +	p64->lsm=0;
   1.134 +	p64->msm=0;
   1.135 +	}
   1.136 +
   1.137 +LOCAL_C void testConvert()
   1.138 +//
   1.139 +//	Conversion tests
   1.140 +//
   1.141 +	{
   1.142 +
   1.143 +	TRealX f;
   1.144 +
   1.145 +	TReal input[]=
   1.146 +		{
   1.147 +		KMaxTReal32inTReal,KMinTReal32inTReal,-KMaxTReal32inTReal,-KMinTReal32inTReal,
   1.148 +		KMaxTReal32inTReal,KMinTReal32inTReal,-KMaxTReal32inTReal,-KMinTReal32inTReal,
   1.149 +		3.4027E+38,1.1755E-38,-3.4027E+38,-1.1755E-38,
   1.150 +		0.0,64.5,-64.5,1.54E+18,-1.54E+18,4.72E-22,-4.72E-22,
   1.151 +		posInfTReal,negInfTReal,KNegZeroTReal,
   1.152 +		1.4E-45,-1.4E-45,2E-41,-2E-41,1E-38,-1E-38		
   1.153 +		};
   1.154 +
   1.155 +	TReal32 expect[]=
   1.156 +		{
   1.157 +		KMaxTReal32,KMinTReal32,-KMaxTReal32,-KMinTReal32,
   1.158 +		KMaxTReal32,KMinTReal32,-KMaxTReal32,-KMinTReal32,
   1.159 +		3.4027E+38f,1.17550E-38f,-3.40270E+38f,-1.17550E-38f,
   1.160 +		0.0f,64.5f,-64.5f,1.54E+18f,-1.54E+18f,4.72E-22f,-4.72E-22f,
   1.161 +		posInfTReal32,negInfTReal32,KNegZeroTReal32,
   1.162 +		1.4E-45f,-1.4E-45f,2E-41f,-2E-41f,1E-38f,-1E-38f				
   1.163 +		};
   1.164 +
   1.165 +	TInt size=sizeof(input)/sizeof(TReal);
   1.166 +
   1.167 +	for (TInt ii=0; ii<size; ii++)
   1.168 +		{
   1.169 +		f=TRealX(expect[ii]);
   1.170 +		test(f==TRealX(TReal32(input[ii])));
   1.171 +		}
   1.172 +
   1.173 +	// NaN
   1.174 +//	TReal a=NaNTReal;
   1.175 +	TReal32 b=NaNTReal32;
   1.176 +	f=TRealX(b);
   1.177 +//	test(f!=TRealX(TReal32(a)));
   1.178 +	test(f.IsNaN());
   1.179 +		
   1.180 +	// See EON Software Defects Bug Report no. HA-287
   1.181 +	// There is a bug in MSDev compiler which means comparing TReal32's directly
   1.182 +	// does not always work, hence...
   1.183 +	/*
   1.184 +	test(BitTest(TReal32(3.40270E+38),3.40270E+38f));	// this works
   1.185 +	// (BitTest() checks for all 32 bits being identical
   1.186 +	
   1.187 +	TReal32 a=TReal32(3.40270E+38);
   1.188 +	TReal32 b=3.40270E+38f;
   1.189 +	TReal64 c=3.40270E+38;
   1.190 +	TReal32 d=TReal32(c);
   1.191 +
   1.192 +	test(a==b);									// this works
   1.193 +	test(d==b);									// this works
   1.194 +	test(TRealX(TReal32(c))==TRealX(b));		// this works
   1.195 +	test(TReal64(TReal32(c))==TReal64(b));		// this panics
   1.196 +	test(TReal32(c)==b);						// this panics					  
   1.197 + 	test(TReal32(3.40270E+38)==3.40270E+38f);	// this panics
   1.198 +
   1.199 +	// As expected, all these work fine under ARM.
   1.200 +	*/
   1.201 +	}
   1.202 +
   1.203 +LOCAL_C void testAdd()
   1.204 +//
   1.205 +//	Addition tests
   1.206 +//
   1.207 +	{
   1.208 +	TReal32 f,g,h;
   1.209 +	TRealX ff,gg,hh;
   1.210 +	
   1.211 +	for (TInt ii=0; ii<sizeAdd-1; ii++)
   1.212 +		{										  
   1.213 +		f=addInput[ii];
   1.214 +		g=addInput[ii+1];
   1.215 +		ff=TRealX(f);
   1.216 +		gg=TRealX(g);
   1.217 +		// Test commute
   1.218 +		test(f+g == g+f);
   1.219 +		// Test PC real addition using fp-hardware same as TRealX addition
   1.220 +		test(TRealX(f+g)==TRealX(TReal32(ff+gg)));
   1.221 +		test(TRealX(g+f)==TRealX(TReal32(ff+gg)));
   1.222 +		// Test hex-encoded constants for TReal32s generated on PC using fp-hardware same as 
   1.223 +		// TRealX addition
   1.224 +		test(TRealX(*(TReal32*)&addArray[ii])==TRealX(f+g));
   1.225 +		test(TRealX(*(TReal32*)&addArray[ii])==TRealX(g+f));
   1.226 +		// similarly to tests above ...
   1.227 +		h=g;
   1.228 +		hh=gg;
   1.229 +		hh+=ff;
   1.230 +		test(TRealX(h+=f)==TRealX(TReal32(hh)));
   1.231 +		test(TRealX(h)==TRealX(TReal32(hh)));
   1.232 +		test(TRealX(*(TReal32*)&addArray[ii])==TRealX(h));
   1.233 +		//
   1.234 +		h=f;
   1.235 +		hh=ff;
   1.236 +		hh+=gg;
   1.237 +		test(TRealX(h+=g)==TRealX(TReal32(hh)));
   1.238 +		test(h==TReal32(hh));
   1.239 +		test(TRealX(*(TReal32*)&addArray[ii])==TRealX(h));
   1.240 +		}
   1.241 +	}
   1.242 +
   1.243 +LOCAL_C void testSubt()
   1.244 +//
   1.245 +// Subtraction tests
   1.246 +//
   1.247 +	{
   1.248 +	TReal32 f,g,h;
   1.249 +	TRealX ff,gg,hh;
   1.250 +
   1.251 +	for (TInt ii=0; ii<sizeSub-1; ii++)
   1.252 +		{
   1.253 +		f=subInput[ii];
   1.254 +		g=subInput[ii+1];
   1.255 +		ff=TRealX(f);
   1.256 +		gg=TRealX(g);
   1.257 +		//
   1.258 +
   1.259 +// This test fails on GCC (with -O1 switch). The reason is that
   1.260 +// comparing two intermediate floats is unpredictable.
   1.261 +// See http://www.parashift.com/c++-faq-lite/newbie.html#faq-29.18
   1.262 +#ifndef __GCC32__	
   1.263 +		test(f-g == -(g-f));
   1.264 +#endif
   1.265 +		//
   1.266 +		test(TRealX(f-g)==TRealX(TReal32(ff-gg)));
   1.267 +		test(TRealX(g-f)==TRealX(TReal32(gg-ff)));
   1.268 +		test(TRealX(*(TReal32*)&subArray[ii])==TRealX(f-g));
   1.269 +		test(TRealX(*(TReal32*)&subArray[ii])==TRealX(-(g-f)));
   1.270 +		//
   1.271 +		h=g;
   1.272 +		hh=gg;
   1.273 +		hh-=ff;
   1.274 +		test(TRealX(h-=f)==TRealX(TReal32(hh)));
   1.275 +		test(TRealX(h)==TRealX(TReal32(hh)));
   1.276 +		test(TRealX(*(TReal32*)&subArray[ii])==TRealX(-h));
   1.277 +		//
   1.278 +		h=f;
   1.279 +		hh=ff;
   1.280 +		hh-=gg;
   1.281 +		test(TRealX(h-=g)==TRealX(TReal32(hh)));
   1.282 +		test(TRealX(h)==TRealX(TReal32(hh)));
   1.283 +		test(TRealX(*(TReal32*)&subArray[ii])==TRealX(h));
   1.284 +		}
   1.285 +	}
   1.286 +
   1.287 +LOCAL_C void testMult()
   1.288 +//
   1.289 +//	Multiplication test
   1.290 +//
   1.291 +	{
   1.292 +	TReal32 f,g,h;
   1.293 +	TRealX ff,gg,hh;
   1.294 +	
   1.295 +	for (TInt ii=0; ii<sizeMult-1; ii++)
   1.296 +		{
   1.297 +		f=multInput[ii];
   1.298 +		g=multInput[ii+1];
   1.299 +		ff=TRealX(f);
   1.300 +		gg=TRealX(g);
   1.301 +		//
   1.302 +		test(f*g == g*f);
   1.303 +		//
   1.304 +		test(TRealX(f*g)==TRealX(TReal32(ff*gg)));
   1.305 +		test(TRealX(g*f)==TRealX(TReal32(gg*ff)));
   1.306 +		test(TRealX(*(TReal32*)&multArray[ii])==TRealX(f*g));
   1.307 +		test(TRealX(*(TReal32*)&multArray[ii])==TRealX(g*f));
   1.308 +		//
   1.309 +		h=f;		
   1.310 +		hh=ff;
   1.311 +		hh*=gg;
   1.312 +		test(TRealX(h*=g)==TRealX(TReal32(hh)));
   1.313 +		test(TRealX(h)==TRealX(TReal32(hh)));
   1.314 +		test(TRealX(*(TReal32*)&multArray[ii])==TRealX(h));
   1.315 +		//
   1.316 +		h=g;
   1.317 +		hh=gg;
   1.318 +		hh*=ff;
   1.319 +		test(TRealX(h*=f)==TRealX(TReal32(hh)));
   1.320 +		test(TRealX(h)==TRealX(TReal32(hh)));
   1.321 +		test(TRealX(*(TReal32*)&multArray[ii])==TRealX(h));
   1.322 +		}
   1.323 +	}
   1.324 +
   1.325 +LOCAL_C void testDiv()
   1.326 +//
   1.327 +//	Division test
   1.328 +//
   1.329 +	{
   1.330 +	TReal32 f,g,h;
   1.331 +	TRealX ff,gg,hh;
   1.332 +	TInt count=0;
   1.333 +	
   1.334 +	// Panic: Divide by Zero
   1.335 +	// f=1.0;
   1.336 +	// g=0.0;
   1.337 +	// f/=g;
   1.338 +
   1.339 +	for (TInt ii=0; ii<sizeDiv-1; ii++)
   1.340 +		{
   1.341 +		f=divInput[ii];
   1.342 +		g=divInput[ii+1];
   1.343 +		ff=TRealX(f);
   1.344 +		gg=TRealX(g);
   1.345 +		if (g!=0.0)
   1.346 +			{
   1.347 +			test(TRealX(f/g)==TRealX(TReal32(ff/gg)));
   1.348 +			test(TRealX(*(TReal32*)&divArray[count])==TRealX(f/g));
   1.349 +			//
   1.350 +			h=f;
   1.351 +			hh=ff;
   1.352 +			hh/=gg;
   1.353 +			test(TRealX(h/=g)==TRealX(TReal32(hh)));
   1.354 +			test(TRealX(h)==TRealX(TReal32(hh)));
   1.355 +			test(TRealX(*(TReal32*)&divArray[count])==TRealX(h));
   1.356 +			++count;
   1.357 +			}
   1.358 +		if (f!=0.0)
   1.359 +			{
   1.360 +			test(TRealX(g/f)==TRealX(TReal32(gg/ff)));
   1.361 +			h=g;
   1.362 +			hh=gg;
   1.363 +			hh/=ff;
   1.364 +			test(TRealX(h/=f)==TRealX(TReal32(hh)));
   1.365 +			test(h==TReal32(hh));
   1.366 +			}
   1.367 +		};
   1.368 +
   1.369 +	//Additional test
   1.370 +	f=3.9999f;
   1.371 +	g=KMinTReal32;
   1.372 +	ff=TRealX(f);
   1.373 +	gg=TRealX(g);
   1.374 +	test(TRealX(f/g)==TRealX(TReal32(ff/gg)));
   1.375 +	h=f;
   1.376 +	hh=ff;
   1.377 +	hh/=gg;
   1.378 +	test(TRealX(h/=g)==TRealX(TReal32(hh)));
   1.379 +	test(TRealX(h)==TRealX(TReal32(hh)));
   1.380 +	}
   1.381 +
   1.382 +#if defined (__WINS__) || defined (__X86__)
   1.383 +
   1.384 +LOCAL_C	 void testArithmeticExceptionRaising()
   1.385 +//
   1.386 +// Test that UP_GCC.CPP raise exceptions correctly by calling functions from EMGCC32.CPP which
   1.387 +// are copies of those in UP_GCC.CPP.  To be used in debugger only.
   1.388 +// Added by AnnW, December 1996
   1.389 +//
   1.390 +	{
   1.391 +	TReal32 f,g,h;
   1.392 +
   1.393 +	// Addition - possible errors are overflow, argument or none
   1.394 +	// NB no underflow
   1.395 +
   1.396 +	f=NaNTReal32;
   1.397 +	h=__addsf3(f,f);	// argument
   1.398 +
   1.399 +	f=KMaxTReal32;
   1.400 +	h=__addsf3(f,f);	// overflow
   1.401 +	
   1.402 +	f=1.0f;
   1.403 +	g=2.0f;
   1.404 +	h=__addsf3(f,g);	// none
   1.405 +	test(h==3.0f);
   1.406 +
   1.407 +	// Subtraction - possible errors are overflow, argument or none
   1.408 +	// NB no underflow
   1.409 +
   1.410 +	f=NaNTReal32;
   1.411 +	h=__subsf3(f,f);	// argument
   1.412 +
   1.413 +	f=KMaxTReal32;
   1.414 +	g=-KMaxTReal32;
   1.415 +	h=__subsf3(f,g);	// overflow
   1.416 +  
   1.417 +	f=1.0f;
   1.418 +	g=2.0f;
   1.419 +	h=__subsf3(f,g);	// none
   1.420 +	test(h==-1.0f);
   1.421 +
   1.422 +	// Multiplication - possible errors are argument, overflow, underflow or none
   1.423 +
   1.424 +	f=NaNTReal32;
   1.425 +	h=__mulsf3(f,f);	// argument
   1.426 +
   1.427 +	f=KMaxTReal32;
   1.428 +	g=2.0f;
   1.429 +	h=__mulsf3(f,g);	// overflow
   1.430 +
   1.431 +	f=minDenormalTReal32;
   1.432 +	g=0.1f;
   1.433 +	h=__mulsf3(f,g);	// underflow
   1.434 +
   1.435 +	f=1.0f;
   1.436 +	g=2.0f;
   1.437 +	h=__mulsf3(f,g);	// none
   1.438 +	test(h==2.0f);
   1.439 +
   1.440 +	// Division - possible errors are overflow, underflow, divide by zero, argument or none
   1.441 +
   1.442 +	f=KMaxTReal32;
   1.443 +	g=0.5f;
   1.444 +	h=__divsf3(f,g);	// overflow
   1.445 +
   1.446 +	f=minDenormalTReal32;
   1.447 +	g=10.0f;
   1.448 +	h=__divsf3(f,g);	// underflow
   1.449 +	
   1.450 +	f=4.0f;
   1.451 +	g=0.0f;
   1.452 +	h=__divsf3(f,g);	// divide by zero
   1.453 +	
   1.454 +	f=0.0f;
   1.455 +	g=0.0f;
   1.456 +	h=__divsf3(f,g);	// argument
   1.457 +
   1.458 +	f=1.0f;
   1.459 +	g=2.0f;
   1.460 +	h=__divsf3(f,g);	// none
   1.461 +	test(h==0.5f);
   1.462 +
   1.463 +	// Converting double to float - possible errors are overflow, underflow, invalid operation or none
   1.464 +	TReal64 d;
   1.465 +
   1.466 +	d=1.0E+50;
   1.467 +	f=__truncdfsf2(d);	// overflow
   1.468 +
   1.469 +	d=1.0E-50;
   1.470 +	f=__truncdfsf2(d);	// underflow
   1.471 +
   1.472 +	d=KNaNTReal64;
   1.473 +	f=__truncdfsf2(d);	// invalid operation
   1.474 +
   1.475 +	d=4.0;	
   1.476 +	f=__truncdfsf2(d);	// none
   1.477 +	}
   1.478 +
   1.479 +#endif
   1.480 +
   1.481 +LOCAL_C void testUnary()
   1.482 +//
   1.483 +//	Unary operator tests
   1.484 +//
   1.485 +	{
   1.486 +	TReal32 f;
   1.487 +	TRealX g;
   1.488 +	
   1.489 +	for (TInt ii=0; ii<sizeUnary-1; ii++)
   1.490 +		{
   1.491 +		f=unaryInput[ii];
   1.492 +		g=TRealX(f);
   1.493 +		test(TRealX(-f)==TRealX(TReal32(-g)));
   1.494 +		test(TRealX(-f)==TRealX(0.0f-f));
   1.495 +		test(TRealX(+f)==TRealX(TReal32(g)));
   1.496 +		test(TRealX(+f)==TRealX(0.0f+f));
   1.497 +		test(TRealX(*(TReal32*)&unaryArray[ii])==TRealX(-f));
   1.498 +		}
   1.499 +	}
   1.500 +
   1.501 +LOCAL_C void testEqualities(const TReal& aA, TOrder aOrder, const TReal& aB)
   1.502 +//
   1.503 +//	Test equality/inequality functions on aA and aB
   1.504 +//	aOrder specifies the operand's relative sizes
   1.505 +//
   1.506 +	{
   1.507 +
   1.508 +	//	Tautologies
   1.509 +	test((aA>aA) ==FALSE);
   1.510 +	test((aA<aA) ==FALSE);
   1.511 +	test((aA>=aA)==TRUE);
   1.512 +	test((aA<=aA)==TRUE);
   1.513 +	test((aA==aA)==TRUE);
   1.514 +	test((aA!=aA)==FALSE);
   1.515 +	if (aOrder!=EEqual)
   1.516 +		{
   1.517 +		test((aA==aB)==FALSE);
   1.518 +  		test((aA!=aB)==TRUE);
   1.519 +		}
   1.520 +	if (aOrder==ELessThan)
   1.521 +		{
   1.522 +		test((aA<aB) ==TRUE);
   1.523 +		test((aA<=aB)==TRUE);
   1.524 +		test((aA>aB) ==FALSE);
   1.525 +		test((aA>=aB)==FALSE);
   1.526 +		}
   1.527 +	if (aOrder==EEqual)
   1.528 +		{
   1.529 +		test((aA==aB)==TRUE);
   1.530 +		test((aA!=aB)==FALSE);
   1.531 +		test((aA>=aB)==TRUE);
   1.532 +		test((aA<=aB)==TRUE);
   1.533 +		test((aA>aB)==FALSE);
   1.534 +		test((aA<aB)==FALSE);
   1.535 +		}
   1.536 +	if (aOrder==EGreaterThan)
   1.537 +		{
   1.538 +		test((aA>aB) ==TRUE);
   1.539 +		test((aA>=aB)==TRUE);
   1.540 +		test((aA<aB) ==FALSE);
   1.541 +		test((aA<=aB)==FALSE);
   1.542 +		}
   1.543 +	}
   1.544 +	 
   1.545 +LOCAL_C void testEqualities()
   1.546 +//
   1.547 +//	Test >, <, >=, <=, ==, !=
   1.548 +//
   1.549 +	{
   1.550 +	TInt i, size;
   1.551 +	TReal32 lessThanMax = KMaxTReal32-TReal32(1.0E+32);
   1.552 +	TReal32 greaterThanMin = 1.17550E-38f;
   1.553 +	TReal32 zero(0.0f);
   1.554 +	
   1.555 +	TReal32 positive[] =
   1.556 +	{KMinTReal32,5.3824705E-26f,1.0f,2387501.0f,5.3824705E+28f,KMaxTReal32};
   1.557 +
   1.558 +	TReal32 large[] =
   1.559 +	{2.0f,KMaxTReal32,-lessThanMax,greaterThanMin,-KMinTReal32,10.4058482f,-10.4058482f,
   1.560 +	1.2443345E+14f,1.2443345E+14f,-1.3420344E-16f,132435.97f,5.0E-6f,9.6f,-8.0f}; 
   1.561 +	
   1.562 +	TReal32 small[] =
   1.563 +	{1.0f,lessThanMax,-KMaxTReal32,KMinTReal32,-greaterThanMin,10.4058474f,-10.4058496f,
   1.564 +	5.0E-10f,1.2443345E+10f,-5.0382470E+25f,-132435.97f,-5.1E-6f,8.0f,-9.6f};
   1.565 +	
   1.566 +	TReal32 equal[] =							  // Same as large[]
   1.567 +	{2.0f,KMaxTReal32,-lessThanMax,greaterThanMin,-KMinTReal32,10.4058482f,-10.4058482f,
   1.568 +	1.2443345E+14f,1.2443345E+14f,-1.3420344E-16f,132435.97f,5.0E-6f,9.6f,-8.0f}; 
   1.569 +
   1.570 +
   1.571 +	// Tests with zero
   1.572 +
   1.573 +	size = sizeof(positive)/sizeof(TReal32);
   1.574 +	
   1.575 +	test.Start(_L("Zero"));
   1.576 +	testEqualities(zero, EEqual, zero);
   1.577 +	for (i=0; i<size; i++)
   1.578 +		{
   1.579 +		testEqualities(positive[i], EGreaterThan, zero);
   1.580 +		testEqualities(-positive[i], ELessThan, zero);
   1.581 +		testEqualities(zero, ELessThan, positive[i]);
   1.582 +		testEqualities(zero, EGreaterThan, -positive[i]);
   1.583 +		}
   1.584 +
   1.585 +	// Test boundary and other numbers
   1.586 +	
   1.587 +	size = sizeof(large)/sizeof(TReal32);
   1.588 +	
   1.589 +	test.Next(_L("Nonzero"));
   1.590 +	for (i=0; i<size; i++)
   1.591 +		{
   1.592 +		testEqualities(large[i], EGreaterThan, small[i]);
   1.593 +		testEqualities(small[i], ELessThan, large[i]);
   1.594 +		testEqualities(large[i], EEqual, equal[i]);
   1.595 +		}
   1.596 +
   1.597 +	test.End();
   1.598 +	}
   1.599 +
   1.600 +LOCAL_C void testIncDec()
   1.601 +//
   1.602 +//	Test Pre/Post - increment/decrement
   1.603 +//
   1.604 +	{
   1.605 +
   1.606 +	TInt ii;
   1.607 +	TReal32 f;
   1.608 +	TRealX g;
   1.609 +	
   1.610 +	test.Start(_L("Pre-increment"));
   1.611 +	
   1.612 +	for (ii=0; ii<sizeIncDec; ii++)
   1.613 +		{
   1.614 +		f=incDecInput[ii];
   1.615 +		g=TRealX(f);
   1.616 +		test(TRealX(f)==TRealX(TReal32(g)));
   1.617 +		test(TRealX(++f)==TRealX(TReal32(++g)));
   1.618 +		test(TRealX(*(TReal32*)&preIncArray1[ii])==TRealX(f));
   1.619 +		test(TRealX(f)==TRealX(TReal32(g)));
   1.620 +		test(TRealX(++f)==TRealX(TReal32(++g)));
   1.621 +		test(TRealX(*(TReal32*)&preIncArray2[ii])==TRealX(f));
   1.622 +		test(TRealX(f)==TRealX(TReal32(g)));
   1.623 +		}
   1.624 +	
   1.625 +	test.Next(_L("Post-increment"));
   1.626 +
   1.627 +	for (ii=0; ii<sizeIncDec; ii++)
   1.628 +		{
   1.629 +		f=incDecInput[ii];
   1.630 +		g=TRealX(f);
   1.631 +		test(TRealX(f)==TRealX(TReal32(g)));
   1.632 +		test(TRealX(f++)==TRealX(TReal32(g++)));
   1.633 +		test(TRealX(*(TReal32*)&postIncArray1[ii])==TRealX(f));
   1.634 +		test(TRealX(f)==TRealX(TReal32(g)));
   1.635 +		test(TRealX(f++)==TRealX(TReal32(g++)));
   1.636 +		test(TRealX(*(TReal32*)&postIncArray2[ii])==TRealX(f));
   1.637 +		test(TRealX(f)==TRealX(TReal32(g)));
   1.638 +		}
   1.639 +	
   1.640 +	test.Next(_L("Pre-decrement"));
   1.641 +
   1.642 +	for (ii=0; ii<sizeIncDec; ii++)
   1.643 +		{
   1.644 +		f=incDecInput[ii];
   1.645 +		g=TRealX(f);
   1.646 +		test(TRealX(f)==TRealX(TReal32(g)));
   1.647 +		test(TRealX(--f)==TRealX(TReal32(--g)));
   1.648 +		test(TRealX(*(TReal32*)&preDecArray1[ii])==TRealX(f));
   1.649 +		test(TRealX(f)==TRealX(TReal32(g)));
   1.650 +		test(TRealX(--f)==TRealX(TReal32(--g)));
   1.651 +		test(TRealX(*(TReal32*)&preDecArray2[ii])==TRealX(f));
   1.652 +		test(TRealX(f)==TRealX(TReal32(g)));
   1.653 +		}
   1.654 +	
   1.655 +	test.Next(_L("Post-decrement"));
   1.656 +
   1.657 +	for	(ii=0; ii<sizeIncDec; ii++)
   1.658 +		{
   1.659 +		f=incDecInput[ii];
   1.660 +		g=TRealX(f);
   1.661 +		test(TRealX(f)==TRealX(TReal32(g)));
   1.662 +		test(TRealX(f--)==TRealX(TReal32(g--)));
   1.663 +		test(TRealX(*(TReal32*)&postDecArray1[ii])==TRealX(f));
   1.664 +		test(TRealX(f)==TRealX(TReal32(g)));
   1.665 +		test(TRealX(f--)==TRealX(TReal32(g--)));
   1.666 +		test(TRealX(*(TReal32*)&postDecArray2[ii])==TRealX(f));
   1.667 +		test(TRealX(f)==TRealX(TReal32(g)));
   1.668 +		}
   1.669 +	test.End();
   1.670 +	}
   1.671 +
   1.672 +LOCAL_C void _matherr(TExcType aType)
   1.673 +	{
   1.674 +	test.Printf(_L("_matherr: Exception type %u handled\n"),TUint(aType));
   1.675 +	}
   1.676 +
   1.677 +GLDEF_C TInt E32Main()
   1.678 +//
   1.679 +//	Test TReal32
   1.680 +//
   1.681 +    {	  
   1.682 +	
   1.683 +	test.Title();
   1.684 +
   1.685 +	User::SetExceptionHandler(_matherr,KExceptionFpe);
   1.686 +
   1.687 +	initSpecialValues();
   1.688 +
   1.689 +	test.Start(_L("Conversion from TReal to TReal32"));
   1.690 +	testConvert();
   1.691 +	test.Next(_L("Addition"));
   1.692 +	testAdd();
   1.693 +	test.Next(_L("Subtraction"));	
   1.694 +	testSubt();
   1.695 +	test.Next(_L("Multiplication"));
   1.696 +	testMult();
   1.697 +	test.Next(_L("Division"));
   1.698 +	testDiv();
   1.699 +#if defined (__WINS__) || defined (__X86__)
   1.700 +	test.Next(_L("Arithmetic which emulates UP_GCC and raises an exception"));
   1.701 +	testArithmeticExceptionRaising();
   1.702 +#endif
   1.703 +	test.Next(_L("Unary Operators"));
   1.704 +	testUnary();
   1.705 +	test.Next(_L("Equalities and Inequalities"));
   1.706 +	testEqualities();
   1.707 +	test.Next(_L("Increment and Decrement"));
   1.708 +	testIncDec();
   1.709 +
   1.710 +	test.End();
   1.711 +	return(KErrNone);
   1.712 +    }
   1.713 +
   1.714 +