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