sl@0
|
1 |
// Copyright (c) 1996-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_gcc32.cpp
|
sl@0
|
15 |
// From UP_GCC.CPP, for emulating UP_GCC in T_R32.CPP tests
|
sl@0
|
16 |
//
|
sl@0
|
17 |
//
|
sl@0
|
18 |
|
sl@0
|
19 |
|
sl@0
|
20 |
#include <e32def.h>
|
sl@0
|
21 |
#include <e32def_private.h>
|
sl@0
|
22 |
|
sl@0
|
23 |
#include "t_math.h"
|
sl@0
|
24 |
|
sl@0
|
25 |
LOCAL_C void MathException(TInt aErrType)
|
sl@0
|
26 |
//
|
sl@0
|
27 |
// Decides on type of maths exception according to error and raises exception.
|
sl@0
|
28 |
// Added by AnnW, December 1996
|
sl@0
|
29 |
//
|
sl@0
|
30 |
{
|
sl@0
|
31 |
|
sl@0
|
32 |
TExcType excType=EExcGeneral;
|
sl@0
|
33 |
|
sl@0
|
34 |
switch (aErrType)
|
sl@0
|
35 |
{
|
sl@0
|
36 |
case KErrArgument: // error due to invalid operation
|
sl@0
|
37 |
excType=EExcFloatInvalidOperation;
|
sl@0
|
38 |
break;
|
sl@0
|
39 |
case KErrDivideByZero:
|
sl@0
|
40 |
excType=EExcFloatDivideByZero;
|
sl@0
|
41 |
break;
|
sl@0
|
42 |
case KErrOverflow:
|
sl@0
|
43 |
excType=EExcFloatOverflow;
|
sl@0
|
44 |
break;
|
sl@0
|
45 |
case KErrUnderflow:
|
sl@0
|
46 |
excType=EExcFloatUnderflow;
|
sl@0
|
47 |
break;
|
sl@0
|
48 |
/*
|
sl@0
|
49 |
// also errors due to inexact result
|
sl@0
|
50 |
case KErrInexact: // const not defined yet
|
sl@0
|
51 |
excType=EExcFloatInexact;
|
sl@0
|
52 |
break;
|
sl@0
|
53 |
*/
|
sl@0
|
54 |
|
sl@0
|
55 |
default:
|
sl@0
|
56 |
// Unknown error
|
sl@0
|
57 |
User::Panic(_L("USER-Math"),EMathUnknownError);
|
sl@0
|
58 |
}
|
sl@0
|
59 |
|
sl@0
|
60 |
// RThread thread;
|
sl@0
|
61 |
User::RaiseException(excType);
|
sl@0
|
62 |
// thread.RaiseException(excType);
|
sl@0
|
63 |
}
|
sl@0
|
64 |
|
sl@0
|
65 |
GLDEF_C TReal32 __addsf3(TReal32 a1,TReal32 a2)
|
sl@0
|
66 |
//
|
sl@0
|
67 |
// Add two floats
|
sl@0
|
68 |
//
|
sl@0
|
69 |
{
|
sl@0
|
70 |
|
sl@0
|
71 |
TRealX x1=a1;
|
sl@0
|
72 |
TRealX x2=a2;
|
sl@0
|
73 |
|
sl@0
|
74 |
TRealX res;
|
sl@0
|
75 |
TReal32 trg;
|
sl@0
|
76 |
x1.Add(res,x2);
|
sl@0
|
77 |
TInt ret=res.GetTReal(trg);
|
sl@0
|
78 |
if (ret!=KErrNone)
|
sl@0
|
79 |
MathException(ret);
|
sl@0
|
80 |
|
sl@0
|
81 |
return(trg);
|
sl@0
|
82 |
}
|
sl@0
|
83 |
|
sl@0
|
84 |
GLDEF_C TReal32 __subsf3(TReal32 a1,TReal32 a2)
|
sl@0
|
85 |
//
|
sl@0
|
86 |
// Subtract two floats
|
sl@0
|
87 |
//
|
sl@0
|
88 |
{
|
sl@0
|
89 |
|
sl@0
|
90 |
TRealX x1=a1;
|
sl@0
|
91 |
TRealX x2=a2;
|
sl@0
|
92 |
|
sl@0
|
93 |
TRealX res;
|
sl@0
|
94 |
TReal32 trg;
|
sl@0
|
95 |
x1.Sub(res,x2);
|
sl@0
|
96 |
TInt ret=res.GetTReal(trg);
|
sl@0
|
97 |
if (ret!=KErrNone)
|
sl@0
|
98 |
MathException(ret);
|
sl@0
|
99 |
|
sl@0
|
100 |
return(trg);
|
sl@0
|
101 |
}
|
sl@0
|
102 |
|
sl@0
|
103 |
GLDEF_C TReal32 __mulsf3(TReal32 a1,TReal32 a2)
|
sl@0
|
104 |
//
|
sl@0
|
105 |
// Multiply two floats
|
sl@0
|
106 |
//
|
sl@0
|
107 |
{
|
sl@0
|
108 |
|
sl@0
|
109 |
TRealX x1=a1;
|
sl@0
|
110 |
TRealX x2=a2;
|
sl@0
|
111 |
|
sl@0
|
112 |
TRealX res;
|
sl@0
|
113 |
TReal32 trg;
|
sl@0
|
114 |
TInt ret=x1.Mult(res,x2);
|
sl@0
|
115 |
if (ret==KErrNone)
|
sl@0
|
116 |
ret=res.GetTReal(trg);
|
sl@0
|
117 |
if (ret!=KErrNone)
|
sl@0
|
118 |
MathException(ret);
|
sl@0
|
119 |
|
sl@0
|
120 |
return((TReal32)res);
|
sl@0
|
121 |
}
|
sl@0
|
122 |
|
sl@0
|
123 |
GLDEF_C TReal32 __divsf3(TReal32 a1,TReal32 a2)
|
sl@0
|
124 |
//
|
sl@0
|
125 |
// Divide two floats
|
sl@0
|
126 |
//
|
sl@0
|
127 |
{
|
sl@0
|
128 |
|
sl@0
|
129 |
TRealX x1=a1;
|
sl@0
|
130 |
TRealX x2=a2;
|
sl@0
|
131 |
|
sl@0
|
132 |
TRealX res;
|
sl@0
|
133 |
TReal32 trg;
|
sl@0
|
134 |
TInt ret=x1.Div(res,x2);
|
sl@0
|
135 |
if (ret==KErrNone)
|
sl@0
|
136 |
ret=res.GetTReal(trg);
|
sl@0
|
137 |
if (ret!=KErrNone)
|
sl@0
|
138 |
MathException(ret);
|
sl@0
|
139 |
|
sl@0
|
140 |
return((TReal32)res);
|
sl@0
|
141 |
}
|
sl@0
|
142 |
|
sl@0
|
143 |
GLDEF_C TReal32 __truncdfsf2(TReal64 a1)
|
sl@0
|
144 |
//
|
sl@0
|
145 |
// Convert a double to a float
|
sl@0
|
146 |
// Raises an exception if conversion results in an error
|
sl@0
|
147 |
//
|
sl@0
|
148 |
{
|
sl@0
|
149 |
|
sl@0
|
150 |
TRealX x1=a1;
|
sl@0
|
151 |
|
sl@0
|
152 |
TInt ret;
|
sl@0
|
153 |
TReal32 trg;
|
sl@0
|
154 |
if ((ret=x1.GetTReal(trg))!=KErrNone)
|
sl@0
|
155 |
MathException(ret);
|
sl@0
|
156 |
|
sl@0
|
157 |
return(trg);
|
sl@0
|
158 |
}
|
sl@0
|
159 |
|
sl@0
|
160 |
|