kerneltest/e32test/math/t_gcc32.cpp
changeset 0 a41df078684a
equal deleted inserted replaced
-1:000000000000 0:a41df078684a
       
     1 // Copyright (c) 1996-2009 Nokia Corporation and/or its subsidiary(-ies).
       
     2 // All rights reserved.
       
     3 // This component and the accompanying materials are made available
       
     4 // under the terms of the License "Eclipse Public License v1.0"
       
     5 // which accompanies this distribution, and is available
       
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     7 //
       
     8 // Initial Contributors:
       
     9 // Nokia Corporation - initial contribution.
       
    10 //
       
    11 // Contributors:
       
    12 //
       
    13 // Description:
       
    14 // e32test\math\t_gcc32.cpp
       
    15 // From UP_GCC.CPP, for emulating UP_GCC in T_R32.CPP tests
       
    16 // 
       
    17 //
       
    18 
       
    19 
       
    20 #include <e32def.h>
       
    21 #include <e32def_private.h>
       
    22 
       
    23 #include "t_math.h"
       
    24 
       
    25 LOCAL_C void MathException(TInt aErrType) 
       
    26 //
       
    27 // Decides on type of maths exception according to error and raises exception.
       
    28 // Added by AnnW, December 1996
       
    29 //
       
    30 	{
       
    31 
       
    32 	TExcType excType=EExcGeneral;
       
    33 
       
    34 	switch (aErrType)
       
    35 		{
       
    36 	case KErrArgument:				// error due to invalid operation
       
    37 		excType=EExcFloatInvalidOperation;
       
    38 		break;
       
    39 	case KErrDivideByZero:
       
    40 		excType=EExcFloatDivideByZero;
       
    41 		break;
       
    42 	case KErrOverflow:
       
    43 		excType=EExcFloatOverflow;
       
    44 		break;
       
    45 	case KErrUnderflow:
       
    46 		excType=EExcFloatUnderflow;
       
    47 		break;
       
    48 /*
       
    49 	// also errors due to inexact result
       
    50 	case KErrInexact:		// const not defined yet
       
    51 		excType=EExcFloatInexact;
       
    52 		break;
       
    53 */
       
    54 	
       
    55 	default:
       
    56 		// Unknown error
       
    57 		User::Panic(_L("USER-Math"),EMathUnknownError);
       
    58 		}
       
    59 
       
    60 //	RThread thread;
       
    61 	User::RaiseException(excType);
       
    62 //	thread.RaiseException(excType);
       
    63 	}
       
    64 
       
    65 GLDEF_C TReal32 __addsf3(TReal32 a1,TReal32 a2)
       
    66 //
       
    67 // Add two floats
       
    68 //
       
    69     {
       
    70 
       
    71     TRealX x1=a1;
       
    72     TRealX x2=a2;
       
    73 
       
    74 	TRealX res;
       
    75 	TReal32 trg;
       
    76 	x1.Add(res,x2);
       
    77 	TInt ret=res.GetTReal(trg);
       
    78 	if (ret!=KErrNone)
       
    79 		MathException(ret);
       
    80 
       
    81 	return(trg);
       
    82     }
       
    83 
       
    84 GLDEF_C TReal32 __subsf3(TReal32 a1,TReal32 a2)
       
    85 //
       
    86 // Subtract two floats
       
    87 //
       
    88     {
       
    89 
       
    90     TRealX x1=a1;
       
    91     TRealX x2=a2;
       
    92 
       
    93 	TRealX res;
       
    94 	TReal32 trg;
       
    95 	x1.Sub(res,x2);
       
    96 	TInt ret=res.GetTReal(trg);
       
    97 	if (ret!=KErrNone)
       
    98 		MathException(ret);
       
    99 
       
   100 	return(trg);
       
   101 	}
       
   102 
       
   103 GLDEF_C TReal32 __mulsf3(TReal32 a1,TReal32 a2)
       
   104 //
       
   105 // Multiply two floats
       
   106 //
       
   107     {
       
   108 
       
   109     TRealX x1=a1;
       
   110     TRealX x2=a2;
       
   111 
       
   112 	TRealX res;
       
   113 	TReal32 trg;
       
   114 	TInt ret=x1.Mult(res,x2);
       
   115 	if (ret==KErrNone)
       
   116 		ret=res.GetTReal(trg);
       
   117 	if (ret!=KErrNone)
       
   118 		MathException(ret);
       
   119 	
       
   120 	return((TReal32)res);
       
   121     }
       
   122 
       
   123 GLDEF_C TReal32 __divsf3(TReal32 a1,TReal32 a2)
       
   124 //
       
   125 // Divide two floats
       
   126 //
       
   127     {
       
   128 
       
   129     TRealX x1=a1;
       
   130     TRealX x2=a2;
       
   131 
       
   132 	TRealX res;
       
   133 	TReal32 trg;
       
   134 	TInt ret=x1.Div(res,x2);
       
   135 	if (ret==KErrNone)
       
   136 		ret=res.GetTReal(trg);
       
   137 	if (ret!=KErrNone)
       
   138 		MathException(ret);
       
   139 
       
   140 	return((TReal32)res);
       
   141     }
       
   142 
       
   143 GLDEF_C TReal32 __truncdfsf2(TReal64 a1)
       
   144 //
       
   145 // Convert a double to a float
       
   146 // Raises an exception if conversion results in an error
       
   147 //
       
   148     {
       
   149 
       
   150 	TRealX x1=a1;
       
   151 
       
   152 	TInt ret;
       
   153 	TReal32 trg;
       
   154 	if ((ret=x1.GetTReal(trg))!=KErrNone)
       
   155 		MathException(ret);
       
   156 
       
   157     return(trg);
       
   158     }
       
   159 
       
   160