os/kernelhwsrv/kerneltest/e32test/math/t_r32.cpp
author sl@SLION-WIN7.fritz.box
Fri, 15 Jun 2012 03:10:57 +0200
changeset 0 bde4ae8d615e
permissions -rw-r--r--
First public contribution.
sl@0
     1
// Copyright (c) 1995-2009 Nokia Corporation and/or its subsidiary(-ies).
sl@0
     2
// All rights reserved.
sl@0
     3
// This component and the accompanying materials are made available
sl@0
     4
// under the terms of the License "Eclipse Public License v1.0"
sl@0
     5
// which accompanies this distribution, and is available
sl@0
     6
// at the URL "http://www.eclipse.org/legal/epl-v10.html".
sl@0
     7
//
sl@0
     8
// Initial Contributors:
sl@0
     9
// Nokia Corporation - initial contribution.
sl@0
    10
//
sl@0
    11
// Contributors:
sl@0
    12
//
sl@0
    13
// Description:
sl@0
    14
// e32test\math\t_r32.cpp
sl@0
    15
// T_R32.CPP - Test routines for TReal32
sl@0
    16
// Also note that these tests do not generally include testing of special values.  This is done
sl@0
    17
// in T_R96 tests and conversions are tested thoroughly, so explicit tests are unnecessary here.
sl@0
    18
// Overview:
sl@0
    19
// Test functionality of operations on 32bit real numbers.
sl@0
    20
// API Information:
sl@0
    21
// TReal32. 
sl@0
    22
// Details:
sl@0
    23
// - Test the conversion from TReal to TReal32 is as expected.
sl@0
    24
// - Check addition, subtraction and multiplication of 32-bit floating point
sl@0
    25
// numbers are as expected.
sl@0
    26
// - Check division of 32-bit floating-point numbers and verify that it is
sl@0
    27
// panicked when divided by zero.
sl@0
    28
// - Test arithmetic exceptions are raised for
sl@0
    29
// - overflow error during addition, subtraction.
sl@0
    30
// - overflow, underflow errors during multiplication.
sl@0
    31
// - overflow, underflow, divided by zero errors during division.
sl@0
    32
// - overflow, underflow, invalid operation errors during conversion
sl@0
    33
// from double to float.
sl@0
    34
// - Check unary operator, equalities and inequalities operators, pre/post 
sl@0
    35
// increment, decrement operators with TReal32 are as expected.
sl@0
    36
// Platforms/Drives/Compatibility:
sl@0
    37
// All 
sl@0
    38
// Assumptions/Requirement/Pre-requisites:
sl@0
    39
// Failures and causes:
sl@0
    40
// Base Port information:
sl@0
    41
// 
sl@0
    42
//
sl@0
    43
sl@0
    44
#include "t_math.h"
sl@0
    45
#include "t_real32.h"
sl@0
    46
sl@0
    47
#if defined(__VC32__)
sl@0
    48
// Some symbols generated by the VC++ compiler for floating point stuff.
sl@0
    49
extern "C" {
sl@0
    50
GLDEF_D TInt _adj_fdiv_m32;
sl@0
    51
}
sl@0
    52
#endif
sl@0
    53
sl@0
    54
// Data for tests from T_R32DTA.cpp 
sl@0
    55
GLREF_D TReal32 addInput[];
sl@0
    56
GLREF_D TReal32 subInput[];
sl@0
    57
GLREF_D TReal32 multInput[];
sl@0
    58
GLREF_D TReal32 divInput[];
sl@0
    59
GLREF_D TReal32 unaryInput[];
sl@0
    60
GLREF_D TReal32 incDecInput[];
sl@0
    61
GLREF_D TInt sizeAdd;
sl@0
    62
GLREF_D TInt sizeSub;
sl@0
    63
GLREF_D TInt sizeMult;
sl@0
    64
GLREF_D TInt sizeDiv;
sl@0
    65
GLREF_D TInt sizeUnary;
sl@0
    66
GLREF_D TInt sizeIncDec;
sl@0
    67
sl@0
    68
#if defined (__WINS__) || defined (__X86__)
sl@0
    69
// Functions from EMGCC32.CPP
sl@0
    70
GLREF_C TReal32 __addsf3(TReal32 a1,TReal32 a2);
sl@0
    71
GLREF_C TReal32 __subsf3(TReal32 a1,TReal32 a2);
sl@0
    72
GLREF_C TReal32 __mulsf3(TReal32 a1,TReal32 a2);
sl@0
    73
GLREF_C TReal32 __divsf3(TReal32 a1,TReal32 a2);
sl@0
    74
GLREF_C TReal32 __truncdfsf2(TReal64 a1);
sl@0
    75
#endif
sl@0
    76
sl@0
    77
GLDEF_D TReal32 NaNTReal32;
sl@0
    78
GLDEF_D TReal32 posInfTReal32;
sl@0
    79
GLDEF_D TReal32 negInfTReal32;
sl@0
    80
GLDEF_D const TReal32 minDenormalTReal32=1.4E-45f;
sl@0
    81
GLDEF_D TReal NaNTReal;
sl@0
    82
GLDEF_D TReal posInfTReal;
sl@0
    83
GLDEF_D TReal negInfTReal;
sl@0
    84
sl@0
    85
enum TOrder
sl@0
    86
	{
sl@0
    87
	ELessThan,
sl@0
    88
	EEqual,
sl@0
    89
	EGreaterThan
sl@0
    90
	};
sl@0
    91
sl@0
    92
LOCAL_D RTest test(_L("T_R32"));
sl@0
    93
sl@0
    94
LOCAL_C void initSpecialValues()
sl@0
    95
//
sl@0
    96
// Initialise special values
sl@0
    97
//
sl@0
    98
	{
sl@0
    99
sl@0
   100
	SReal32 *p32=(SReal32*)&NaNTReal32;
sl@0
   101
	p32->sign=0;
sl@0
   102
	p32->exp=KTReal32SpecialExponent;
sl@0
   103
	p32->man=0x7fffff;
sl@0
   104
sl@0
   105
	p32=(SReal32*)&posInfTReal32;
sl@0
   106
	p32->sign=0;
sl@0
   107
	p32->exp=KTReal32SpecialExponent;
sl@0
   108
	p32->man=0;
sl@0
   109
sl@0
   110
	p32=(SReal32*)&negInfTReal32;
sl@0
   111
	p32->sign=1;
sl@0
   112
	p32->exp=KTReal32SpecialExponent;
sl@0
   113
	p32->man=0;
sl@0
   114
sl@0
   115
	SReal64 *p64=(SReal64*)&NaNTReal;
sl@0
   116
	p64->sign=0;
sl@0
   117
	p64->exp=KTReal64SpecialExponent;
sl@0
   118
	p64->lsm=0xffffffffu;
sl@0
   119
	p64->msm=0xfffff;
sl@0
   120
sl@0
   121
	p64=(SReal64*)&posInfTReal;
sl@0
   122
	p64->sign=0;
sl@0
   123
	p64->exp=KTReal64SpecialExponent;
sl@0
   124
	p64->lsm=0;
sl@0
   125
	p64->msm=0;
sl@0
   126
	
sl@0
   127
	p64=(SReal64*)&negInfTReal;
sl@0
   128
	p64->sign=1;
sl@0
   129
	p64->exp=KTReal64SpecialExponent;
sl@0
   130
	p64->lsm=0;
sl@0
   131
	p64->msm=0;
sl@0
   132
	}
sl@0
   133
sl@0
   134
LOCAL_C void testConvert()
sl@0
   135
//
sl@0
   136
//	Conversion tests
sl@0
   137
//
sl@0
   138
	{
sl@0
   139
sl@0
   140
	TRealX f;
sl@0
   141
sl@0
   142
	TReal input[]=
sl@0
   143
		{
sl@0
   144
		KMaxTReal32inTReal,KMinTReal32inTReal,-KMaxTReal32inTReal,-KMinTReal32inTReal,
sl@0
   145
		KMaxTReal32inTReal,KMinTReal32inTReal,-KMaxTReal32inTReal,-KMinTReal32inTReal,
sl@0
   146
		3.4027E+38,1.1755E-38,-3.4027E+38,-1.1755E-38,
sl@0
   147
		0.0,64.5,-64.5,1.54E+18,-1.54E+18,4.72E-22,-4.72E-22,
sl@0
   148
		posInfTReal,negInfTReal,KNegZeroTReal,
sl@0
   149
		1.4E-45,-1.4E-45,2E-41,-2E-41,1E-38,-1E-38		
sl@0
   150
		};
sl@0
   151
sl@0
   152
	TReal32 expect[]=
sl@0
   153
		{
sl@0
   154
		KMaxTReal32,KMinTReal32,-KMaxTReal32,-KMinTReal32,
sl@0
   155
		KMaxTReal32,KMinTReal32,-KMaxTReal32,-KMinTReal32,
sl@0
   156
		3.4027E+38f,1.17550E-38f,-3.40270E+38f,-1.17550E-38f,
sl@0
   157
		0.0f,64.5f,-64.5f,1.54E+18f,-1.54E+18f,4.72E-22f,-4.72E-22f,
sl@0
   158
		posInfTReal32,negInfTReal32,KNegZeroTReal32,
sl@0
   159
		1.4E-45f,-1.4E-45f,2E-41f,-2E-41f,1E-38f,-1E-38f				
sl@0
   160
		};
sl@0
   161
sl@0
   162
	TInt size=sizeof(input)/sizeof(TReal);
sl@0
   163
sl@0
   164
	for (TInt ii=0; ii<size; ii++)
sl@0
   165
		{
sl@0
   166
		f=TRealX(expect[ii]);
sl@0
   167
		test(f==TRealX(TReal32(input[ii])));
sl@0
   168
		}
sl@0
   169
sl@0
   170
	// NaN
sl@0
   171
//	TReal a=NaNTReal;
sl@0
   172
	TReal32 b=NaNTReal32;
sl@0
   173
	f=TRealX(b);
sl@0
   174
//	test(f!=TRealX(TReal32(a)));
sl@0
   175
	test(f.IsNaN());
sl@0
   176
		
sl@0
   177
	// See EON Software Defects Bug Report no. HA-287
sl@0
   178
	// There is a bug in MSDev compiler which means comparing TReal32's directly
sl@0
   179
	// does not always work, hence...
sl@0
   180
	/*
sl@0
   181
	test(BitTest(TReal32(3.40270E+38),3.40270E+38f));	// this works
sl@0
   182
	// (BitTest() checks for all 32 bits being identical
sl@0
   183
	
sl@0
   184
	TReal32 a=TReal32(3.40270E+38);
sl@0
   185
	TReal32 b=3.40270E+38f;
sl@0
   186
	TReal64 c=3.40270E+38;
sl@0
   187
	TReal32 d=TReal32(c);
sl@0
   188
sl@0
   189
	test(a==b);									// this works
sl@0
   190
	test(d==b);									// this works
sl@0
   191
	test(TRealX(TReal32(c))==TRealX(b));		// this works
sl@0
   192
	test(TReal64(TReal32(c))==TReal64(b));		// this panics
sl@0
   193
	test(TReal32(c)==b);						// this panics					  
sl@0
   194
 	test(TReal32(3.40270E+38)==3.40270E+38f);	// this panics
sl@0
   195
sl@0
   196
	// As expected, all these work fine under ARM.
sl@0
   197
	*/
sl@0
   198
	}
sl@0
   199
sl@0
   200
LOCAL_C void testAdd()
sl@0
   201
//
sl@0
   202
//	Addition tests
sl@0
   203
//
sl@0
   204
	{
sl@0
   205
	TReal32 f,g,h;
sl@0
   206
	TRealX ff,gg,hh;
sl@0
   207
	
sl@0
   208
	for (TInt ii=0; ii<sizeAdd-1; ii++)
sl@0
   209
		{										  
sl@0
   210
		f=addInput[ii];
sl@0
   211
		g=addInput[ii+1];
sl@0
   212
		ff=TRealX(f);
sl@0
   213
		gg=TRealX(g);
sl@0
   214
		// Test commute
sl@0
   215
		test(f+g == g+f);
sl@0
   216
		// Test PC real addition using fp-hardware same as TRealX addition
sl@0
   217
		test(TRealX(f+g)==TRealX(TReal32(ff+gg)));
sl@0
   218
		test(TRealX(g+f)==TRealX(TReal32(ff+gg)));
sl@0
   219
		// Test hex-encoded constants for TReal32s generated on PC using fp-hardware same as 
sl@0
   220
		// TRealX addition
sl@0
   221
		test(TRealX(*(TReal32*)&addArray[ii])==TRealX(f+g));
sl@0
   222
		test(TRealX(*(TReal32*)&addArray[ii])==TRealX(g+f));
sl@0
   223
		// similarly to tests above ...
sl@0
   224
		h=g;
sl@0
   225
		hh=gg;
sl@0
   226
		hh+=ff;
sl@0
   227
		test(TRealX(h+=f)==TRealX(TReal32(hh)));
sl@0
   228
		test(TRealX(h)==TRealX(TReal32(hh)));
sl@0
   229
		test(TRealX(*(TReal32*)&addArray[ii])==TRealX(h));
sl@0
   230
		//
sl@0
   231
		h=f;
sl@0
   232
		hh=ff;
sl@0
   233
		hh+=gg;
sl@0
   234
		test(TRealX(h+=g)==TRealX(TReal32(hh)));
sl@0
   235
		test(h==TReal32(hh));
sl@0
   236
		test(TRealX(*(TReal32*)&addArray[ii])==TRealX(h));
sl@0
   237
		}
sl@0
   238
	}
sl@0
   239
sl@0
   240
LOCAL_C void testSubt()
sl@0
   241
//
sl@0
   242
// Subtraction tests
sl@0
   243
//
sl@0
   244
	{
sl@0
   245
	TReal32 f,g,h;
sl@0
   246
	TRealX ff,gg,hh;
sl@0
   247
sl@0
   248
	for (TInt ii=0; ii<sizeSub-1; ii++)
sl@0
   249
		{
sl@0
   250
		f=subInput[ii];
sl@0
   251
		g=subInput[ii+1];
sl@0
   252
		ff=TRealX(f);
sl@0
   253
		gg=TRealX(g);
sl@0
   254
		//
sl@0
   255
sl@0
   256
// This test fails on GCC (with -O1 switch). The reason is that
sl@0
   257
// comparing two intermediate floats is unpredictable.
sl@0
   258
// See http://www.parashift.com/c++-faq-lite/newbie.html#faq-29.18
sl@0
   259
#ifndef __GCC32__	
sl@0
   260
		test(f-g == -(g-f));
sl@0
   261
#endif
sl@0
   262
		//
sl@0
   263
		test(TRealX(f-g)==TRealX(TReal32(ff-gg)));
sl@0
   264
		test(TRealX(g-f)==TRealX(TReal32(gg-ff)));
sl@0
   265
		test(TRealX(*(TReal32*)&subArray[ii])==TRealX(f-g));
sl@0
   266
		test(TRealX(*(TReal32*)&subArray[ii])==TRealX(-(g-f)));
sl@0
   267
		//
sl@0
   268
		h=g;
sl@0
   269
		hh=gg;
sl@0
   270
		hh-=ff;
sl@0
   271
		test(TRealX(h-=f)==TRealX(TReal32(hh)));
sl@0
   272
		test(TRealX(h)==TRealX(TReal32(hh)));
sl@0
   273
		test(TRealX(*(TReal32*)&subArray[ii])==TRealX(-h));
sl@0
   274
		//
sl@0
   275
		h=f;
sl@0
   276
		hh=ff;
sl@0
   277
		hh-=gg;
sl@0
   278
		test(TRealX(h-=g)==TRealX(TReal32(hh)));
sl@0
   279
		test(TRealX(h)==TRealX(TReal32(hh)));
sl@0
   280
		test(TRealX(*(TReal32*)&subArray[ii])==TRealX(h));
sl@0
   281
		}
sl@0
   282
	}
sl@0
   283
sl@0
   284
LOCAL_C void testMult()
sl@0
   285
//
sl@0
   286
//	Multiplication test
sl@0
   287
//
sl@0
   288
	{
sl@0
   289
	TReal32 f,g,h;
sl@0
   290
	TRealX ff,gg,hh;
sl@0
   291
	
sl@0
   292
	for (TInt ii=0; ii<sizeMult-1; ii++)
sl@0
   293
		{
sl@0
   294
		f=multInput[ii];
sl@0
   295
		g=multInput[ii+1];
sl@0
   296
		ff=TRealX(f);
sl@0
   297
		gg=TRealX(g);
sl@0
   298
		//
sl@0
   299
		test(f*g == g*f);
sl@0
   300
		//
sl@0
   301
		test(TRealX(f*g)==TRealX(TReal32(ff*gg)));
sl@0
   302
		test(TRealX(g*f)==TRealX(TReal32(gg*ff)));
sl@0
   303
		test(TRealX(*(TReal32*)&multArray[ii])==TRealX(f*g));
sl@0
   304
		test(TRealX(*(TReal32*)&multArray[ii])==TRealX(g*f));
sl@0
   305
		//
sl@0
   306
		h=f;		
sl@0
   307
		hh=ff;
sl@0
   308
		hh*=gg;
sl@0
   309
		test(TRealX(h*=g)==TRealX(TReal32(hh)));
sl@0
   310
		test(TRealX(h)==TRealX(TReal32(hh)));
sl@0
   311
		test(TRealX(*(TReal32*)&multArray[ii])==TRealX(h));
sl@0
   312
		//
sl@0
   313
		h=g;
sl@0
   314
		hh=gg;
sl@0
   315
		hh*=ff;
sl@0
   316
		test(TRealX(h*=f)==TRealX(TReal32(hh)));
sl@0
   317
		test(TRealX(h)==TRealX(TReal32(hh)));
sl@0
   318
		test(TRealX(*(TReal32*)&multArray[ii])==TRealX(h));
sl@0
   319
		}
sl@0
   320
	}
sl@0
   321
sl@0
   322
LOCAL_C void testDiv()
sl@0
   323
//
sl@0
   324
//	Division test
sl@0
   325
//
sl@0
   326
	{
sl@0
   327
	TReal32 f,g,h;
sl@0
   328
	TRealX ff,gg,hh;
sl@0
   329
	TInt count=0;
sl@0
   330
	
sl@0
   331
	// Panic: Divide by Zero
sl@0
   332
	// f=1.0;
sl@0
   333
	// g=0.0;
sl@0
   334
	// f/=g;
sl@0
   335
sl@0
   336
	for (TInt ii=0; ii<sizeDiv-1; ii++)
sl@0
   337
		{
sl@0
   338
		f=divInput[ii];
sl@0
   339
		g=divInput[ii+1];
sl@0
   340
		ff=TRealX(f);
sl@0
   341
		gg=TRealX(g);
sl@0
   342
		if (g!=0.0)
sl@0
   343
			{
sl@0
   344
			test(TRealX(f/g)==TRealX(TReal32(ff/gg)));
sl@0
   345
			test(TRealX(*(TReal32*)&divArray[count])==TRealX(f/g));
sl@0
   346
			//
sl@0
   347
			h=f;
sl@0
   348
			hh=ff;
sl@0
   349
			hh/=gg;
sl@0
   350
			test(TRealX(h/=g)==TRealX(TReal32(hh)));
sl@0
   351
			test(TRealX(h)==TRealX(TReal32(hh)));
sl@0
   352
			test(TRealX(*(TReal32*)&divArray[count])==TRealX(h));
sl@0
   353
			++count;
sl@0
   354
			}
sl@0
   355
		if (f!=0.0)
sl@0
   356
			{
sl@0
   357
			test(TRealX(g/f)==TRealX(TReal32(gg/ff)));
sl@0
   358
			h=g;
sl@0
   359
			hh=gg;
sl@0
   360
			hh/=ff;
sl@0
   361
			test(TRealX(h/=f)==TRealX(TReal32(hh)));
sl@0
   362
			test(h==TReal32(hh));
sl@0
   363
			}
sl@0
   364
		};
sl@0
   365
sl@0
   366
	//Additional test
sl@0
   367
	f=3.9999f;
sl@0
   368
	g=KMinTReal32;
sl@0
   369
	ff=TRealX(f);
sl@0
   370
	gg=TRealX(g);
sl@0
   371
	test(TRealX(f/g)==TRealX(TReal32(ff/gg)));
sl@0
   372
	h=f;
sl@0
   373
	hh=ff;
sl@0
   374
	hh/=gg;
sl@0
   375
	test(TRealX(h/=g)==TRealX(TReal32(hh)));
sl@0
   376
	test(TRealX(h)==TRealX(TReal32(hh)));
sl@0
   377
	}
sl@0
   378
sl@0
   379
#if defined (__WINS__) || defined (__X86__)
sl@0
   380
sl@0
   381
LOCAL_C	 void testArithmeticExceptionRaising()
sl@0
   382
//
sl@0
   383
// Test that UP_GCC.CPP raise exceptions correctly by calling functions from EMGCC32.CPP which
sl@0
   384
// are copies of those in UP_GCC.CPP.  To be used in debugger only.
sl@0
   385
// Added by AnnW, December 1996
sl@0
   386
//
sl@0
   387
	{
sl@0
   388
	TReal32 f,g,h;
sl@0
   389
sl@0
   390
	// Addition - possible errors are overflow, argument or none
sl@0
   391
	// NB no underflow
sl@0
   392
sl@0
   393
	f=NaNTReal32;
sl@0
   394
	h=__addsf3(f,f);	// argument
sl@0
   395
sl@0
   396
	f=KMaxTReal32;
sl@0
   397
	h=__addsf3(f,f);	// overflow
sl@0
   398
	
sl@0
   399
	f=1.0f;
sl@0
   400
	g=2.0f;
sl@0
   401
	h=__addsf3(f,g);	// none
sl@0
   402
	test(h==3.0f);
sl@0
   403
sl@0
   404
	// Subtraction - possible errors are overflow, argument or none
sl@0
   405
	// NB no underflow
sl@0
   406
sl@0
   407
	f=NaNTReal32;
sl@0
   408
	h=__subsf3(f,f);	// argument
sl@0
   409
sl@0
   410
	f=KMaxTReal32;
sl@0
   411
	g=-KMaxTReal32;
sl@0
   412
	h=__subsf3(f,g);	// overflow
sl@0
   413
  
sl@0
   414
	f=1.0f;
sl@0
   415
	g=2.0f;
sl@0
   416
	h=__subsf3(f,g);	// none
sl@0
   417
	test(h==-1.0f);
sl@0
   418
sl@0
   419
	// Multiplication - possible errors are argument, overflow, underflow or none
sl@0
   420
sl@0
   421
	f=NaNTReal32;
sl@0
   422
	h=__mulsf3(f,f);	// argument
sl@0
   423
sl@0
   424
	f=KMaxTReal32;
sl@0
   425
	g=2.0f;
sl@0
   426
	h=__mulsf3(f,g);	// overflow
sl@0
   427
sl@0
   428
	f=minDenormalTReal32;
sl@0
   429
	g=0.1f;
sl@0
   430
	h=__mulsf3(f,g);	// underflow
sl@0
   431
sl@0
   432
	f=1.0f;
sl@0
   433
	g=2.0f;
sl@0
   434
	h=__mulsf3(f,g);	// none
sl@0
   435
	test(h==2.0f);
sl@0
   436
sl@0
   437
	// Division - possible errors are overflow, underflow, divide by zero, argument or none
sl@0
   438
sl@0
   439
	f=KMaxTReal32;
sl@0
   440
	g=0.5f;
sl@0
   441
	h=__divsf3(f,g);	// overflow
sl@0
   442
sl@0
   443
	f=minDenormalTReal32;
sl@0
   444
	g=10.0f;
sl@0
   445
	h=__divsf3(f,g);	// underflow
sl@0
   446
	
sl@0
   447
	f=4.0f;
sl@0
   448
	g=0.0f;
sl@0
   449
	h=__divsf3(f,g);	// divide by zero
sl@0
   450
	
sl@0
   451
	f=0.0f;
sl@0
   452
	g=0.0f;
sl@0
   453
	h=__divsf3(f,g);	// argument
sl@0
   454
sl@0
   455
	f=1.0f;
sl@0
   456
	g=2.0f;
sl@0
   457
	h=__divsf3(f,g);	// none
sl@0
   458
	test(h==0.5f);
sl@0
   459
sl@0
   460
	// Converting double to float - possible errors are overflow, underflow, invalid operation or none
sl@0
   461
	TReal64 d;
sl@0
   462
sl@0
   463
	d=1.0E+50;
sl@0
   464
	f=__truncdfsf2(d);	// overflow
sl@0
   465
sl@0
   466
	d=1.0E-50;
sl@0
   467
	f=__truncdfsf2(d);	// underflow
sl@0
   468
sl@0
   469
	d=KNaNTReal64;
sl@0
   470
	f=__truncdfsf2(d);	// invalid operation
sl@0
   471
sl@0
   472
	d=4.0;	
sl@0
   473
	f=__truncdfsf2(d);	// none
sl@0
   474
	}
sl@0
   475
sl@0
   476
#endif
sl@0
   477
sl@0
   478
LOCAL_C void testUnary()
sl@0
   479
//
sl@0
   480
//	Unary operator tests
sl@0
   481
//
sl@0
   482
	{
sl@0
   483
	TReal32 f;
sl@0
   484
	TRealX g;
sl@0
   485
	
sl@0
   486
	for (TInt ii=0; ii<sizeUnary-1; ii++)
sl@0
   487
		{
sl@0
   488
		f=unaryInput[ii];
sl@0
   489
		g=TRealX(f);
sl@0
   490
		test(TRealX(-f)==TRealX(TReal32(-g)));
sl@0
   491
		test(TRealX(-f)==TRealX(0.0f-f));
sl@0
   492
		test(TRealX(+f)==TRealX(TReal32(g)));
sl@0
   493
		test(TRealX(+f)==TRealX(0.0f+f));
sl@0
   494
		test(TRealX(*(TReal32*)&unaryArray[ii])==TRealX(-f));
sl@0
   495
		}
sl@0
   496
	}
sl@0
   497
sl@0
   498
LOCAL_C void testEqualities(const TReal& aA, TOrder aOrder, const TReal& aB)
sl@0
   499
//
sl@0
   500
//	Test equality/inequality functions on aA and aB
sl@0
   501
//	aOrder specifies the operand's relative sizes
sl@0
   502
//
sl@0
   503
	{
sl@0
   504
sl@0
   505
	//	Tautologies
sl@0
   506
	test((aA>aA) ==FALSE);
sl@0
   507
	test((aA<aA) ==FALSE);
sl@0
   508
	test((aA>=aA)==TRUE);
sl@0
   509
	test((aA<=aA)==TRUE);
sl@0
   510
	test((aA==aA)==TRUE);
sl@0
   511
	test((aA!=aA)==FALSE);
sl@0
   512
	if (aOrder!=EEqual)
sl@0
   513
		{
sl@0
   514
		test((aA==aB)==FALSE);
sl@0
   515
  		test((aA!=aB)==TRUE);
sl@0
   516
		}
sl@0
   517
	if (aOrder==ELessThan)
sl@0
   518
		{
sl@0
   519
		test((aA<aB) ==TRUE);
sl@0
   520
		test((aA<=aB)==TRUE);
sl@0
   521
		test((aA>aB) ==FALSE);
sl@0
   522
		test((aA>=aB)==FALSE);
sl@0
   523
		}
sl@0
   524
	if (aOrder==EEqual)
sl@0
   525
		{
sl@0
   526
		test((aA==aB)==TRUE);
sl@0
   527
		test((aA!=aB)==FALSE);
sl@0
   528
		test((aA>=aB)==TRUE);
sl@0
   529
		test((aA<=aB)==TRUE);
sl@0
   530
		test((aA>aB)==FALSE);
sl@0
   531
		test((aA<aB)==FALSE);
sl@0
   532
		}
sl@0
   533
	if (aOrder==EGreaterThan)
sl@0
   534
		{
sl@0
   535
		test((aA>aB) ==TRUE);
sl@0
   536
		test((aA>=aB)==TRUE);
sl@0
   537
		test((aA<aB) ==FALSE);
sl@0
   538
		test((aA<=aB)==FALSE);
sl@0
   539
		}
sl@0
   540
	}
sl@0
   541
	 
sl@0
   542
LOCAL_C void testEqualities()
sl@0
   543
//
sl@0
   544
//	Test >, <, >=, <=, ==, !=
sl@0
   545
//
sl@0
   546
	{
sl@0
   547
	TInt i, size;
sl@0
   548
	TReal32 lessThanMax = KMaxTReal32-TReal32(1.0E+32);
sl@0
   549
	TReal32 greaterThanMin = 1.17550E-38f;
sl@0
   550
	TReal32 zero(0.0f);
sl@0
   551
	
sl@0
   552
	TReal32 positive[] =
sl@0
   553
	{KMinTReal32,5.3824705E-26f,1.0f,2387501.0f,5.3824705E+28f,KMaxTReal32};
sl@0
   554
sl@0
   555
	TReal32 large[] =
sl@0
   556
	{2.0f,KMaxTReal32,-lessThanMax,greaterThanMin,-KMinTReal32,10.4058482f,-10.4058482f,
sl@0
   557
	1.2443345E+14f,1.2443345E+14f,-1.3420344E-16f,132435.97f,5.0E-6f,9.6f,-8.0f}; 
sl@0
   558
	
sl@0
   559
	TReal32 small[] =
sl@0
   560
	{1.0f,lessThanMax,-KMaxTReal32,KMinTReal32,-greaterThanMin,10.4058474f,-10.4058496f,
sl@0
   561
	5.0E-10f,1.2443345E+10f,-5.0382470E+25f,-132435.97f,-5.1E-6f,8.0f,-9.6f};
sl@0
   562
	
sl@0
   563
	TReal32 equal[] =							  // Same as large[]
sl@0
   564
	{2.0f,KMaxTReal32,-lessThanMax,greaterThanMin,-KMinTReal32,10.4058482f,-10.4058482f,
sl@0
   565
	1.2443345E+14f,1.2443345E+14f,-1.3420344E-16f,132435.97f,5.0E-6f,9.6f,-8.0f}; 
sl@0
   566
sl@0
   567
sl@0
   568
	// Tests with zero
sl@0
   569
sl@0
   570
	size = sizeof(positive)/sizeof(TReal32);
sl@0
   571
	
sl@0
   572
	test.Start(_L("Zero"));
sl@0
   573
	testEqualities(zero, EEqual, zero);
sl@0
   574
	for (i=0; i<size; i++)
sl@0
   575
		{
sl@0
   576
		testEqualities(positive[i], EGreaterThan, zero);
sl@0
   577
		testEqualities(-positive[i], ELessThan, zero);
sl@0
   578
		testEqualities(zero, ELessThan, positive[i]);
sl@0
   579
		testEqualities(zero, EGreaterThan, -positive[i]);
sl@0
   580
		}
sl@0
   581
sl@0
   582
	// Test boundary and other numbers
sl@0
   583
	
sl@0
   584
	size = sizeof(large)/sizeof(TReal32);
sl@0
   585
	
sl@0
   586
	test.Next(_L("Nonzero"));
sl@0
   587
	for (i=0; i<size; i++)
sl@0
   588
		{
sl@0
   589
		testEqualities(large[i], EGreaterThan, small[i]);
sl@0
   590
		testEqualities(small[i], ELessThan, large[i]);
sl@0
   591
		testEqualities(large[i], EEqual, equal[i]);
sl@0
   592
		}
sl@0
   593
sl@0
   594
	test.End();
sl@0
   595
	}
sl@0
   596
sl@0
   597
LOCAL_C void testIncDec()
sl@0
   598
//
sl@0
   599
//	Test Pre/Post - increment/decrement
sl@0
   600
//
sl@0
   601
	{
sl@0
   602
sl@0
   603
	TInt ii;
sl@0
   604
	TReal32 f;
sl@0
   605
	TRealX g;
sl@0
   606
	
sl@0
   607
	test.Start(_L("Pre-increment"));
sl@0
   608
	
sl@0
   609
	for (ii=0; ii<sizeIncDec; ii++)
sl@0
   610
		{
sl@0
   611
		f=incDecInput[ii];
sl@0
   612
		g=TRealX(f);
sl@0
   613
		test(TRealX(f)==TRealX(TReal32(g)));
sl@0
   614
		test(TRealX(++f)==TRealX(TReal32(++g)));
sl@0
   615
		test(TRealX(*(TReal32*)&preIncArray1[ii])==TRealX(f));
sl@0
   616
		test(TRealX(f)==TRealX(TReal32(g)));
sl@0
   617
		test(TRealX(++f)==TRealX(TReal32(++g)));
sl@0
   618
		test(TRealX(*(TReal32*)&preIncArray2[ii])==TRealX(f));
sl@0
   619
		test(TRealX(f)==TRealX(TReal32(g)));
sl@0
   620
		}
sl@0
   621
	
sl@0
   622
	test.Next(_L("Post-increment"));
sl@0
   623
sl@0
   624
	for (ii=0; ii<sizeIncDec; ii++)
sl@0
   625
		{
sl@0
   626
		f=incDecInput[ii];
sl@0
   627
		g=TRealX(f);
sl@0
   628
		test(TRealX(f)==TRealX(TReal32(g)));
sl@0
   629
		test(TRealX(f++)==TRealX(TReal32(g++)));
sl@0
   630
		test(TRealX(*(TReal32*)&postIncArray1[ii])==TRealX(f));
sl@0
   631
		test(TRealX(f)==TRealX(TReal32(g)));
sl@0
   632
		test(TRealX(f++)==TRealX(TReal32(g++)));
sl@0
   633
		test(TRealX(*(TReal32*)&postIncArray2[ii])==TRealX(f));
sl@0
   634
		test(TRealX(f)==TRealX(TReal32(g)));
sl@0
   635
		}
sl@0
   636
	
sl@0
   637
	test.Next(_L("Pre-decrement"));
sl@0
   638
sl@0
   639
	for (ii=0; ii<sizeIncDec; ii++)
sl@0
   640
		{
sl@0
   641
		f=incDecInput[ii];
sl@0
   642
		g=TRealX(f);
sl@0
   643
		test(TRealX(f)==TRealX(TReal32(g)));
sl@0
   644
		test(TRealX(--f)==TRealX(TReal32(--g)));
sl@0
   645
		test(TRealX(*(TReal32*)&preDecArray1[ii])==TRealX(f));
sl@0
   646
		test(TRealX(f)==TRealX(TReal32(g)));
sl@0
   647
		test(TRealX(--f)==TRealX(TReal32(--g)));
sl@0
   648
		test(TRealX(*(TReal32*)&preDecArray2[ii])==TRealX(f));
sl@0
   649
		test(TRealX(f)==TRealX(TReal32(g)));
sl@0
   650
		}
sl@0
   651
	
sl@0
   652
	test.Next(_L("Post-decrement"));
sl@0
   653
sl@0
   654
	for	(ii=0; ii<sizeIncDec; ii++)
sl@0
   655
		{
sl@0
   656
		f=incDecInput[ii];
sl@0
   657
		g=TRealX(f);
sl@0
   658
		test(TRealX(f)==TRealX(TReal32(g)));
sl@0
   659
		test(TRealX(f--)==TRealX(TReal32(g--)));
sl@0
   660
		test(TRealX(*(TReal32*)&postDecArray1[ii])==TRealX(f));
sl@0
   661
		test(TRealX(f)==TRealX(TReal32(g)));
sl@0
   662
		test(TRealX(f--)==TRealX(TReal32(g--)));
sl@0
   663
		test(TRealX(*(TReal32*)&postDecArray2[ii])==TRealX(f));
sl@0
   664
		test(TRealX(f)==TRealX(TReal32(g)));
sl@0
   665
		}
sl@0
   666
	test.End();
sl@0
   667
	}
sl@0
   668
sl@0
   669
LOCAL_C void _matherr(TExcType aType)
sl@0
   670
	{
sl@0
   671
	test.Printf(_L("_matherr: Exception type %u handled\n"),TUint(aType));
sl@0
   672
	}
sl@0
   673
sl@0
   674
GLDEF_C TInt E32Main()
sl@0
   675
//
sl@0
   676
//	Test TReal32
sl@0
   677
//
sl@0
   678
    {	  
sl@0
   679
	
sl@0
   680
	test.Title();
sl@0
   681
sl@0
   682
	User::SetExceptionHandler(_matherr,KExceptionFpe);
sl@0
   683
sl@0
   684
	initSpecialValues();
sl@0
   685
sl@0
   686
	test.Start(_L("Conversion from TReal to TReal32"));
sl@0
   687
	testConvert();
sl@0
   688
	test.Next(_L("Addition"));
sl@0
   689
	testAdd();
sl@0
   690
	test.Next(_L("Subtraction"));	
sl@0
   691
	testSubt();
sl@0
   692
	test.Next(_L("Multiplication"));
sl@0
   693
	testMult();
sl@0
   694
	test.Next(_L("Division"));
sl@0
   695
	testDiv();
sl@0
   696
#if defined (__WINS__) || defined (__X86__)
sl@0
   697
	test.Next(_L("Arithmetic which emulates UP_GCC and raises an exception"));
sl@0
   698
	testArithmeticExceptionRaising();
sl@0
   699
#endif
sl@0
   700
	test.Next(_L("Unary Operators"));
sl@0
   701
	testUnary();
sl@0
   702
	test.Next(_L("Equalities and Inequalities"));
sl@0
   703
	testEqualities();
sl@0
   704
	test.Next(_L("Increment and Decrement"));
sl@0
   705
	testIncDec();
sl@0
   706
sl@0
   707
	test.End();
sl@0
   708
	return(KErrNone);
sl@0
   709
    }
sl@0
   710
sl@0
   711