sl@0: // Copyright (c) 1996-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_gcc32.cpp sl@0: // From UP_GCC.CPP, for emulating UP_GCC in T_R32.CPP tests sl@0: // sl@0: // sl@0: sl@0: sl@0: #include sl@0: #include sl@0: sl@0: #include "t_math.h" sl@0: sl@0: LOCAL_C void MathException(TInt aErrType) sl@0: // sl@0: // Decides on type of maths exception according to error and raises exception. sl@0: // Added by AnnW, December 1996 sl@0: // sl@0: { sl@0: sl@0: TExcType excType=EExcGeneral; sl@0: sl@0: switch (aErrType) sl@0: { sl@0: case KErrArgument: // error due to invalid operation sl@0: excType=EExcFloatInvalidOperation; sl@0: break; sl@0: case KErrDivideByZero: sl@0: excType=EExcFloatDivideByZero; sl@0: break; sl@0: case KErrOverflow: sl@0: excType=EExcFloatOverflow; sl@0: break; sl@0: case KErrUnderflow: sl@0: excType=EExcFloatUnderflow; sl@0: break; sl@0: /* sl@0: // also errors due to inexact result sl@0: case KErrInexact: // const not defined yet sl@0: excType=EExcFloatInexact; sl@0: break; sl@0: */ sl@0: sl@0: default: sl@0: // Unknown error sl@0: User::Panic(_L("USER-Math"),EMathUnknownError); sl@0: } sl@0: sl@0: // RThread thread; sl@0: User::RaiseException(excType); sl@0: // thread.RaiseException(excType); sl@0: } sl@0: sl@0: GLDEF_C TReal32 __addsf3(TReal32 a1,TReal32 a2) sl@0: // sl@0: // Add two floats sl@0: // sl@0: { sl@0: sl@0: TRealX x1=a1; sl@0: TRealX x2=a2; sl@0: sl@0: TRealX res; sl@0: TReal32 trg; sl@0: x1.Add(res,x2); sl@0: TInt ret=res.GetTReal(trg); sl@0: if (ret!=KErrNone) sl@0: MathException(ret); sl@0: sl@0: return(trg); sl@0: } sl@0: sl@0: GLDEF_C TReal32 __subsf3(TReal32 a1,TReal32 a2) sl@0: // sl@0: // Subtract two floats sl@0: // sl@0: { sl@0: sl@0: TRealX x1=a1; sl@0: TRealX x2=a2; sl@0: sl@0: TRealX res; sl@0: TReal32 trg; sl@0: x1.Sub(res,x2); sl@0: TInt ret=res.GetTReal(trg); sl@0: if (ret!=KErrNone) sl@0: MathException(ret); sl@0: sl@0: return(trg); sl@0: } sl@0: sl@0: GLDEF_C TReal32 __mulsf3(TReal32 a1,TReal32 a2) sl@0: // sl@0: // Multiply two floats sl@0: // sl@0: { sl@0: sl@0: TRealX x1=a1; sl@0: TRealX x2=a2; sl@0: sl@0: TRealX res; sl@0: TReal32 trg; sl@0: TInt ret=x1.Mult(res,x2); sl@0: if (ret==KErrNone) sl@0: ret=res.GetTReal(trg); sl@0: if (ret!=KErrNone) sl@0: MathException(ret); sl@0: sl@0: return((TReal32)res); sl@0: } sl@0: sl@0: GLDEF_C TReal32 __divsf3(TReal32 a1,TReal32 a2) sl@0: // sl@0: // Divide two floats sl@0: // sl@0: { sl@0: sl@0: TRealX x1=a1; sl@0: TRealX x2=a2; sl@0: sl@0: TRealX res; sl@0: TReal32 trg; sl@0: TInt ret=x1.Div(res,x2); sl@0: if (ret==KErrNone) sl@0: ret=res.GetTReal(trg); sl@0: if (ret!=KErrNone) sl@0: MathException(ret); sl@0: sl@0: return((TReal32)res); sl@0: } sl@0: sl@0: GLDEF_C TReal32 __truncdfsf2(TReal64 a1) sl@0: // sl@0: // Convert a double to a float sl@0: // Raises an exception if conversion results in an error sl@0: // sl@0: { sl@0: sl@0: TRealX x1=a1; sl@0: sl@0: TInt ret; sl@0: TReal32 trg; sl@0: if ((ret=x1.GetTReal(trg))!=KErrNone) sl@0: MathException(ret); sl@0: sl@0: return(trg); sl@0: } sl@0: sl@0: