diff -r 000000000000 -r bde4ae8d615e os/kernelhwsrv/kerneltest/e32test/math/t_r32.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/os/kernelhwsrv/kerneltest/e32test/math/t_r32.cpp Fri Jun 15 03:10:57 2012 +0200 @@ -0,0 +1,711 @@ +// Copyright (c) 1995-2009 Nokia Corporation and/or its subsidiary(-ies). +// All rights reserved. +// This component and the accompanying materials are made available +// under the terms of the License "Eclipse Public License v1.0" +// which accompanies this distribution, and is available +// at the URL "http://www.eclipse.org/legal/epl-v10.html". +// +// Initial Contributors: +// Nokia Corporation - initial contribution. +// +// Contributors: +// +// Description: +// e32test\math\t_r32.cpp +// T_R32.CPP - Test routines for TReal32 +// Also note that these tests do not generally include testing of special values. This is done +// in T_R96 tests and conversions are tested thoroughly, so explicit tests are unnecessary here. +// Overview: +// Test functionality of operations on 32bit real numbers. +// API Information: +// TReal32. +// Details: +// - Test the conversion from TReal to TReal32 is as expected. +// - Check addition, subtraction and multiplication of 32-bit floating point +// numbers are as expected. +// - Check division of 32-bit floating-point numbers and verify that it is +// panicked when divided by zero. +// - Test arithmetic exceptions are raised for +// - overflow error during addition, subtraction. +// - overflow, underflow errors during multiplication. +// - overflow, underflow, divided by zero errors during division. +// - overflow, underflow, invalid operation errors during conversion +// from double to float. +// - Check unary operator, equalities and inequalities operators, pre/post +// increment, decrement operators with TReal32 are as expected. +// Platforms/Drives/Compatibility: +// All +// Assumptions/Requirement/Pre-requisites: +// Failures and causes: +// Base Port information: +// +// + +#include "t_math.h" +#include "t_real32.h" + +#if defined(__VC32__) +// Some symbols generated by the VC++ compiler for floating point stuff. +extern "C" { +GLDEF_D TInt _adj_fdiv_m32; +} +#endif + +// Data for tests from T_R32DTA.cpp +GLREF_D TReal32 addInput[]; +GLREF_D TReal32 subInput[]; +GLREF_D TReal32 multInput[]; +GLREF_D TReal32 divInput[]; +GLREF_D TReal32 unaryInput[]; +GLREF_D TReal32 incDecInput[]; +GLREF_D TInt sizeAdd; +GLREF_D TInt sizeSub; +GLREF_D TInt sizeMult; +GLREF_D TInt sizeDiv; +GLREF_D TInt sizeUnary; +GLREF_D TInt sizeIncDec; + +#if defined (__WINS__) || defined (__X86__) +// Functions from EMGCC32.CPP +GLREF_C TReal32 __addsf3(TReal32 a1,TReal32 a2); +GLREF_C TReal32 __subsf3(TReal32 a1,TReal32 a2); +GLREF_C TReal32 __mulsf3(TReal32 a1,TReal32 a2); +GLREF_C TReal32 __divsf3(TReal32 a1,TReal32 a2); +GLREF_C TReal32 __truncdfsf2(TReal64 a1); +#endif + +GLDEF_D TReal32 NaNTReal32; +GLDEF_D TReal32 posInfTReal32; +GLDEF_D TReal32 negInfTReal32; +GLDEF_D const TReal32 minDenormalTReal32=1.4E-45f; +GLDEF_D TReal NaNTReal; +GLDEF_D TReal posInfTReal; +GLDEF_D TReal negInfTReal; + +enum TOrder + { + ELessThan, + EEqual, + EGreaterThan + }; + +LOCAL_D RTest test(_L("T_R32")); + +LOCAL_C void initSpecialValues() +// +// Initialise special values +// + { + + SReal32 *p32=(SReal32*)&NaNTReal32; + p32->sign=0; + p32->exp=KTReal32SpecialExponent; + p32->man=0x7fffff; + + p32=(SReal32*)&posInfTReal32; + p32->sign=0; + p32->exp=KTReal32SpecialExponent; + p32->man=0; + + p32=(SReal32*)&negInfTReal32; + p32->sign=1; + p32->exp=KTReal32SpecialExponent; + p32->man=0; + + SReal64 *p64=(SReal64*)&NaNTReal; + p64->sign=0; + p64->exp=KTReal64SpecialExponent; + p64->lsm=0xffffffffu; + p64->msm=0xfffff; + + p64=(SReal64*)&posInfTReal; + p64->sign=0; + p64->exp=KTReal64SpecialExponent; + p64->lsm=0; + p64->msm=0; + + p64=(SReal64*)&negInfTReal; + p64->sign=1; + p64->exp=KTReal64SpecialExponent; + p64->lsm=0; + p64->msm=0; + } + +LOCAL_C void testConvert() +// +// Conversion tests +// + { + + TRealX f; + + TReal input[]= + { + KMaxTReal32inTReal,KMinTReal32inTReal,-KMaxTReal32inTReal,-KMinTReal32inTReal, + KMaxTReal32inTReal,KMinTReal32inTReal,-KMaxTReal32inTReal,-KMinTReal32inTReal, + 3.4027E+38,1.1755E-38,-3.4027E+38,-1.1755E-38, + 0.0,64.5,-64.5,1.54E+18,-1.54E+18,4.72E-22,-4.72E-22, + posInfTReal,negInfTReal,KNegZeroTReal, + 1.4E-45,-1.4E-45,2E-41,-2E-41,1E-38,-1E-38 + }; + + TReal32 expect[]= + { + KMaxTReal32,KMinTReal32,-KMaxTReal32,-KMinTReal32, + KMaxTReal32,KMinTReal32,-KMaxTReal32,-KMinTReal32, + 3.4027E+38f,1.17550E-38f,-3.40270E+38f,-1.17550E-38f, + 0.0f,64.5f,-64.5f,1.54E+18f,-1.54E+18f,4.72E-22f,-4.72E-22f, + posInfTReal32,negInfTReal32,KNegZeroTReal32, + 1.4E-45f,-1.4E-45f,2E-41f,-2E-41f,1E-38f,-1E-38f + }; + + TInt size=sizeof(input)/sizeof(TReal); + + for (TInt ii=0; iiaA) ==FALSE); + test((aA=aA)==TRUE); + test((aA<=aA)==TRUE); + test((aA==aA)==TRUE); + test((aA!=aA)==FALSE); + if (aOrder!=EEqual) + { + test((aA==aB)==FALSE); + test((aA!=aB)==TRUE); + } + if (aOrder==ELessThan) + { + test((aAaB) ==FALSE); + test((aA>=aB)==FALSE); + } + if (aOrder==EEqual) + { + test((aA==aB)==TRUE); + test((aA!=aB)==FALSE); + test((aA>=aB)==TRUE); + test((aA<=aB)==TRUE); + test((aA>aB)==FALSE); + test((aAaB) ==TRUE); + test((aA>=aB)==TRUE); + test((aA, <, >=, <=, ==, != +// + { + TInt i, size; + TReal32 lessThanMax = KMaxTReal32-TReal32(1.0E+32); + TReal32 greaterThanMin = 1.17550E-38f; + TReal32 zero(0.0f); + + TReal32 positive[] = + {KMinTReal32,5.3824705E-26f,1.0f,2387501.0f,5.3824705E+28f,KMaxTReal32}; + + TReal32 large[] = + {2.0f,KMaxTReal32,-lessThanMax,greaterThanMin,-KMinTReal32,10.4058482f,-10.4058482f, + 1.2443345E+14f,1.2443345E+14f,-1.3420344E-16f,132435.97f,5.0E-6f,9.6f,-8.0f}; + + TReal32 small[] = + {1.0f,lessThanMax,-KMaxTReal32,KMinTReal32,-greaterThanMin,10.4058474f,-10.4058496f, + 5.0E-10f,1.2443345E+10f,-5.0382470E+25f,-132435.97f,-5.1E-6f,8.0f,-9.6f}; + + TReal32 equal[] = // Same as large[] + {2.0f,KMaxTReal32,-lessThanMax,greaterThanMin,-KMinTReal32,10.4058482f,-10.4058482f, + 1.2443345E+14f,1.2443345E+14f,-1.3420344E-16f,132435.97f,5.0E-6f,9.6f,-8.0f}; + + + // Tests with zero + + size = sizeof(positive)/sizeof(TReal32); + + test.Start(_L("Zero")); + testEqualities(zero, EEqual, zero); + for (i=0; i