sl@0
|
1 |
// Copyright (c) 1995-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 |
// e32\euser\us_gcc.cpp
|
sl@0
|
15 |
//
|
sl@0
|
16 |
//
|
sl@0
|
17 |
|
sl@0
|
18 |
#include "us_std.h"
|
sl@0
|
19 |
#include <e32math.h>
|
sl@0
|
20 |
|
sl@0
|
21 |
extern "C" {
|
sl@0
|
22 |
|
sl@0
|
23 |
EXPORT_C TInt64 __fixsfdi(TReal32 a1)
|
sl@0
|
24 |
//
|
sl@0
|
25 |
// Convert float to long long
|
sl@0
|
26 |
//
|
sl@0
|
27 |
{
|
sl@0
|
28 |
const TRealX f(a1);
|
sl@0
|
29 |
const TInt64 ret = f;
|
sl@0
|
30 |
return ret;
|
sl@0
|
31 |
}
|
sl@0
|
32 |
|
sl@0
|
33 |
} // end of extern "C" declaration
|
sl@0
|
34 |
|
sl@0
|
35 |
#ifndef __REALS_MACHINE_CODED__
|
sl@0
|
36 |
LOCAL_C void MathException(TInt aErrType)
|
sl@0
|
37 |
//
|
sl@0
|
38 |
// Decides on type of maths exception according to error and raises exception.
|
sl@0
|
39 |
// Added by AnnW, December 1996
|
sl@0
|
40 |
//
|
sl@0
|
41 |
{
|
sl@0
|
42 |
|
sl@0
|
43 |
TExcType excType=EExcGeneral;
|
sl@0
|
44 |
|
sl@0
|
45 |
switch (aErrType)
|
sl@0
|
46 |
{
|
sl@0
|
47 |
case KErrArgument: // error due to invalid operation
|
sl@0
|
48 |
excType=EExcFloatInvalidOperation;
|
sl@0
|
49 |
break;
|
sl@0
|
50 |
case KErrDivideByZero:
|
sl@0
|
51 |
excType=EExcFloatDivideByZero;
|
sl@0
|
52 |
break;
|
sl@0
|
53 |
case KErrOverflow:
|
sl@0
|
54 |
excType=EExcFloatOverflow;
|
sl@0
|
55 |
break;
|
sl@0
|
56 |
case KErrUnderflow:
|
sl@0
|
57 |
excType=EExcFloatUnderflow;
|
sl@0
|
58 |
break;
|
sl@0
|
59 |
/*
|
sl@0
|
60 |
// also errors due to inexact result
|
sl@0
|
61 |
case KErrInexact: // const not defined yet
|
sl@0
|
62 |
excType=EExcFloatInexact;
|
sl@0
|
63 |
break;
|
sl@0
|
64 |
*/
|
sl@0
|
65 |
|
sl@0
|
66 |
default:
|
sl@0
|
67 |
// Unknown error
|
sl@0
|
68 |
Panic(EMathUnknownError);
|
sl@0
|
69 |
}
|
sl@0
|
70 |
|
sl@0
|
71 |
User::RaiseException(excType);
|
sl@0
|
72 |
}
|
sl@0
|
73 |
|
sl@0
|
74 |
EXPORT_C TReal32 __addsf3(TReal32 a1,TReal32 a2)
|
sl@0
|
75 |
//
|
sl@0
|
76 |
// Add two floats
|
sl@0
|
77 |
//
|
sl@0
|
78 |
{
|
sl@0
|
79 |
|
sl@0
|
80 |
TRealX x1=a1;
|
sl@0
|
81 |
TRealX x2=a2;
|
sl@0
|
82 |
|
sl@0
|
83 |
TRealX res;
|
sl@0
|
84 |
TReal32 trg;
|
sl@0
|
85 |
x1.Add(res,x2); // need not check error because no underflow and others will not be lost in conversion
|
sl@0
|
86 |
TInt ret=res.GetTReal(trg);
|
sl@0
|
87 |
if (ret!=KErrNone)
|
sl@0
|
88 |
MathException(ret);
|
sl@0
|
89 |
|
sl@0
|
90 |
return(trg);
|
sl@0
|
91 |
}
|
sl@0
|
92 |
|
sl@0
|
93 |
EXPORT_C TReal64 __adddf3(TReal64 a1,TReal64 a2)
|
sl@0
|
94 |
//
|
sl@0
|
95 |
// Add two doubles
|
sl@0
|
96 |
//
|
sl@0
|
97 |
{
|
sl@0
|
98 |
|
sl@0
|
99 |
TRealX x1=a1;
|
sl@0
|
100 |
TRealX x2=a2;
|
sl@0
|
101 |
|
sl@0
|
102 |
TRealX res;
|
sl@0
|
103 |
TReal64 trg;
|
sl@0
|
104 |
x1.Add(res,x2); // need not check error because no underflow and others will not be lost in conversion
|
sl@0
|
105 |
TInt ret=res.GetTReal(trg);
|
sl@0
|
106 |
if (ret!=KErrNone)
|
sl@0
|
107 |
MathException(ret);
|
sl@0
|
108 |
|
sl@0
|
109 |
return(trg);
|
sl@0
|
110 |
}
|
sl@0
|
111 |
|
sl@0
|
112 |
EXPORT_C TReal32 __subsf3(TReal32 a1,TReal32 a2)
|
sl@0
|
113 |
//
|
sl@0
|
114 |
// Subtract two floats
|
sl@0
|
115 |
//
|
sl@0
|
116 |
{
|
sl@0
|
117 |
|
sl@0
|
118 |
TRealX x1=a1;
|
sl@0
|
119 |
TRealX x2=a2;
|
sl@0
|
120 |
|
sl@0
|
121 |
TRealX res;
|
sl@0
|
122 |
TReal32 trg;
|
sl@0
|
123 |
x1.Sub(res,x2); // need not check error because no underflow and others will not be lost in conversion
|
sl@0
|
124 |
TInt ret=res.GetTReal(trg);
|
sl@0
|
125 |
if (ret!=KErrNone)
|
sl@0
|
126 |
MathException(ret);
|
sl@0
|
127 |
|
sl@0
|
128 |
return(trg);
|
sl@0
|
129 |
}
|
sl@0
|
130 |
|
sl@0
|
131 |
EXPORT_C TReal64 __subdf3(TReal64 a1,TReal64 a2)
|
sl@0
|
132 |
//
|
sl@0
|
133 |
// Subtract two doubles
|
sl@0
|
134 |
//
|
sl@0
|
135 |
{
|
sl@0
|
136 |
|
sl@0
|
137 |
TRealX x1=a1;
|
sl@0
|
138 |
TRealX x2=a2;
|
sl@0
|
139 |
|
sl@0
|
140 |
TRealX res;
|
sl@0
|
141 |
TReal64 trg;
|
sl@0
|
142 |
x1.Sub(res,x2); // need not check error because no underflow and others will not be lost in conversion
|
sl@0
|
143 |
TInt ret=res.GetTReal(trg);
|
sl@0
|
144 |
if (ret!=KErrNone)
|
sl@0
|
145 |
MathException(ret);
|
sl@0
|
146 |
|
sl@0
|
147 |
return(trg);
|
sl@0
|
148 |
}
|
sl@0
|
149 |
|
sl@0
|
150 |
EXPORT_C TInt __cmpsf3(TReal32 a1,TReal32 a2)
|
sl@0
|
151 |
//
|
sl@0
|
152 |
// Compare two floats
|
sl@0
|
153 |
//
|
sl@0
|
154 |
{
|
sl@0
|
155 |
|
sl@0
|
156 |
TRealX x1=a1;
|
sl@0
|
157 |
TRealX x2=a2;
|
sl@0
|
158 |
if (x1<x2)
|
sl@0
|
159 |
return(-1);
|
sl@0
|
160 |
if (x1>x2)
|
sl@0
|
161 |
return(1);
|
sl@0
|
162 |
return(0);
|
sl@0
|
163 |
}
|
sl@0
|
164 |
|
sl@0
|
165 |
EXPORT_C TInt __cmpdf3(TReal64 a1,TReal64 a2)
|
sl@0
|
166 |
//
|
sl@0
|
167 |
// Compare two doubles
|
sl@0
|
168 |
//
|
sl@0
|
169 |
{
|
sl@0
|
170 |
|
sl@0
|
171 |
TRealX x1=a1;
|
sl@0
|
172 |
TRealX x2=a2;
|
sl@0
|
173 |
if (x1<x2)
|
sl@0
|
174 |
return(-1);
|
sl@0
|
175 |
if (x1>x2)
|
sl@0
|
176 |
return(1);
|
sl@0
|
177 |
return(0);
|
sl@0
|
178 |
}
|
sl@0
|
179 |
|
sl@0
|
180 |
EXPORT_C TInt __eqsf2(TReal32 a1,TReal32 a2)
|
sl@0
|
181 |
//
|
sl@0
|
182 |
// Compare if two floats are equal
|
sl@0
|
183 |
//
|
sl@0
|
184 |
{
|
sl@0
|
185 |
|
sl@0
|
186 |
TRealX x1=a1;
|
sl@0
|
187 |
TRealX x2=a2;
|
sl@0
|
188 |
return (x1==x2 ? 0 : 1);
|
sl@0
|
189 |
}
|
sl@0
|
190 |
|
sl@0
|
191 |
EXPORT_C TInt __eqdf2(TReal64 a1,TReal64 a2)
|
sl@0
|
192 |
//
|
sl@0
|
193 |
// Compare if two doubles are equal
|
sl@0
|
194 |
//
|
sl@0
|
195 |
{
|
sl@0
|
196 |
|
sl@0
|
197 |
TRealX x1=a1;
|
sl@0
|
198 |
TRealX x2=a2;
|
sl@0
|
199 |
return (x1==x2 ? 0 : 1);
|
sl@0
|
200 |
}
|
sl@0
|
201 |
|
sl@0
|
202 |
EXPORT_C TInt __nesf2(TReal32 a1,TReal32 a2)
|
sl@0
|
203 |
//
|
sl@0
|
204 |
// Compare if two floats are not equal
|
sl@0
|
205 |
//
|
sl@0
|
206 |
{
|
sl@0
|
207 |
|
sl@0
|
208 |
TRealX x1=a1;
|
sl@0
|
209 |
TRealX x2=a2;
|
sl@0
|
210 |
return(x1!=x2 ? 1 : 0);
|
sl@0
|
211 |
}
|
sl@0
|
212 |
|
sl@0
|
213 |
EXPORT_C TInt __nedf2(TReal64 a1,TReal64 a2)
|
sl@0
|
214 |
//
|
sl@0
|
215 |
// Compare if two doubles are not equal
|
sl@0
|
216 |
//
|
sl@0
|
217 |
{
|
sl@0
|
218 |
|
sl@0
|
219 |
TRealX x1=a1;
|
sl@0
|
220 |
TRealX x2=a2;
|
sl@0
|
221 |
return(x1!=x2 ? 1 : 0);
|
sl@0
|
222 |
}
|
sl@0
|
223 |
|
sl@0
|
224 |
EXPORT_C TInt __gtsf2(TReal32 a1,TReal32 a2)
|
sl@0
|
225 |
//
|
sl@0
|
226 |
// Compare if one float is greater than another
|
sl@0
|
227 |
//
|
sl@0
|
228 |
{
|
sl@0
|
229 |
|
sl@0
|
230 |
TRealX x1=a1;
|
sl@0
|
231 |
TRealX x2=a2;
|
sl@0
|
232 |
return(x1>x2 ? +1 : -1);
|
sl@0
|
233 |
}
|
sl@0
|
234 |
|
sl@0
|
235 |
EXPORT_C TInt __gtdf2(TReal64 a1,TReal64 a2)
|
sl@0
|
236 |
//
|
sl@0
|
237 |
// Compare if one double is greater than another
|
sl@0
|
238 |
//
|
sl@0
|
239 |
{
|
sl@0
|
240 |
|
sl@0
|
241 |
TRealX x1=a1;
|
sl@0
|
242 |
TRealX x2=a2;
|
sl@0
|
243 |
return(x1>x2 ? +1 : -1);
|
sl@0
|
244 |
}
|
sl@0
|
245 |
|
sl@0
|
246 |
EXPORT_C TInt __gesf2(TReal32 a1,TReal32 a2)
|
sl@0
|
247 |
//
|
sl@0
|
248 |
// Compare if one float is greater than or equal to another
|
sl@0
|
249 |
//
|
sl@0
|
250 |
{
|
sl@0
|
251 |
|
sl@0
|
252 |
TRealX x1=a1;
|
sl@0
|
253 |
TRealX x2=a2;
|
sl@0
|
254 |
return(x1>=x2 ? 1 : -1);
|
sl@0
|
255 |
}
|
sl@0
|
256 |
|
sl@0
|
257 |
EXPORT_C TInt __gedf2(TReal64 a1,TReal64 a2)
|
sl@0
|
258 |
//
|
sl@0
|
259 |
// Compare if one double is greater than or equal to another
|
sl@0
|
260 |
//
|
sl@0
|
261 |
{
|
sl@0
|
262 |
|
sl@0
|
263 |
TRealX x1=a1;
|
sl@0
|
264 |
TRealX x2=a2;
|
sl@0
|
265 |
return(x1>=x2 ? 1 : -1);
|
sl@0
|
266 |
}
|
sl@0
|
267 |
|
sl@0
|
268 |
EXPORT_C TInt __ltsf2(TReal32 a1,TReal32 a2)
|
sl@0
|
269 |
//
|
sl@0
|
270 |
// Compare if one float is less than another
|
sl@0
|
271 |
//
|
sl@0
|
272 |
{
|
sl@0
|
273 |
|
sl@0
|
274 |
TRealX x1=a1;
|
sl@0
|
275 |
TRealX x2=a2;
|
sl@0
|
276 |
return(x1<x2 ? -1 : +1);
|
sl@0
|
277 |
}
|
sl@0
|
278 |
|
sl@0
|
279 |
EXPORT_C TInt __ltdf2(TReal64 a1,TReal64 a2)
|
sl@0
|
280 |
//
|
sl@0
|
281 |
// Compare if one double is less than another
|
sl@0
|
282 |
//
|
sl@0
|
283 |
{
|
sl@0
|
284 |
|
sl@0
|
285 |
TRealX x1=a1;
|
sl@0
|
286 |
TRealX x2=a2;
|
sl@0
|
287 |
return(x1<x2 ? -1 : +1);
|
sl@0
|
288 |
}
|
sl@0
|
289 |
|
sl@0
|
290 |
EXPORT_C TInt __lesf2(TReal32 a1,TReal32 a2)
|
sl@0
|
291 |
//
|
sl@0
|
292 |
// Compare if one float is less than or equal to another
|
sl@0
|
293 |
//
|
sl@0
|
294 |
{
|
sl@0
|
295 |
|
sl@0
|
296 |
TRealX x1=a1;
|
sl@0
|
297 |
TRealX x2=a2;
|
sl@0
|
298 |
return(x1<=x2 ? -1 : +1);
|
sl@0
|
299 |
}
|
sl@0
|
300 |
|
sl@0
|
301 |
EXPORT_C TInt __ledf2(TReal64 a1,TReal64 a2)
|
sl@0
|
302 |
//
|
sl@0
|
303 |
// Compare if one double is less than or equal to another
|
sl@0
|
304 |
//
|
sl@0
|
305 |
{
|
sl@0
|
306 |
|
sl@0
|
307 |
TRealX x1=a1;
|
sl@0
|
308 |
TRealX x2=a2;
|
sl@0
|
309 |
return(x1<=x2 ? -1 : +1);
|
sl@0
|
310 |
}
|
sl@0
|
311 |
|
sl@0
|
312 |
EXPORT_C TReal32 __mulsf3(TReal32 a1,TReal32 a2)
|
sl@0
|
313 |
//
|
sl@0
|
314 |
// Multiply two floats
|
sl@0
|
315 |
//
|
sl@0
|
316 |
{
|
sl@0
|
317 |
|
sl@0
|
318 |
TRealX x1=a1;
|
sl@0
|
319 |
TRealX x2=a2;
|
sl@0
|
320 |
|
sl@0
|
321 |
TRealX res;
|
sl@0
|
322 |
TReal32 trg;
|
sl@0
|
323 |
TInt ret=x1.Mult(res,x2);
|
sl@0
|
324 |
if (ret==KErrNone) // must check this because if underflow, error is lost in conversion
|
sl@0
|
325 |
ret=res.GetTReal(trg);
|
sl@0
|
326 |
if (ret!=KErrNone)
|
sl@0
|
327 |
MathException(ret);
|
sl@0
|
328 |
|
sl@0
|
329 |
return((TReal32)res);
|
sl@0
|
330 |
}
|
sl@0
|
331 |
|
sl@0
|
332 |
EXPORT_C TReal64 __muldf3(TReal64 a1,TReal64 a2)
|
sl@0
|
333 |
//
|
sl@0
|
334 |
// Multiply two doubles
|
sl@0
|
335 |
//
|
sl@0
|
336 |
{
|
sl@0
|
337 |
|
sl@0
|
338 |
TRealX x1=a1;
|
sl@0
|
339 |
TRealX x2=a2;
|
sl@0
|
340 |
|
sl@0
|
341 |
TRealX res;
|
sl@0
|
342 |
TReal64 trg;
|
sl@0
|
343 |
TInt ret=x1.Mult(res,x2);
|
sl@0
|
344 |
if (ret==KErrNone) // must check this because if underflow, error is lost in conversion
|
sl@0
|
345 |
ret=res.GetTReal(trg);
|
sl@0
|
346 |
if (ret!=KErrNone)
|
sl@0
|
347 |
MathException(ret);
|
sl@0
|
348 |
|
sl@0
|
349 |
return((TReal64)res);
|
sl@0
|
350 |
}
|
sl@0
|
351 |
|
sl@0
|
352 |
EXPORT_C TReal32 __divsf3(TReal32 a1,TReal32 a2)
|
sl@0
|
353 |
//
|
sl@0
|
354 |
// Divide two floats
|
sl@0
|
355 |
//
|
sl@0
|
356 |
{
|
sl@0
|
357 |
|
sl@0
|
358 |
TRealX x1=a1;
|
sl@0
|
359 |
TRealX x2=a2;
|
sl@0
|
360 |
|
sl@0
|
361 |
TRealX res;
|
sl@0
|
362 |
TReal32 trg;
|
sl@0
|
363 |
TInt ret=x1.Div(res,x2);
|
sl@0
|
364 |
if (ret==KErrNone) // must check this because if underflow, error is lost in conversion
|
sl@0
|
365 |
ret=res.GetTReal(trg);
|
sl@0
|
366 |
if (ret!=KErrNone)
|
sl@0
|
367 |
MathException(ret);
|
sl@0
|
368 |
|
sl@0
|
369 |
return((TReal32)res);
|
sl@0
|
370 |
}
|
sl@0
|
371 |
|
sl@0
|
372 |
EXPORT_C TReal64 __divdf3(TReal64 a1,TReal64 a2)
|
sl@0
|
373 |
//
|
sl@0
|
374 |
// Divide two doubles
|
sl@0
|
375 |
//
|
sl@0
|
376 |
{
|
sl@0
|
377 |
|
sl@0
|
378 |
TRealX x1=a1;
|
sl@0
|
379 |
TRealX x2=a2;
|
sl@0
|
380 |
|
sl@0
|
381 |
TRealX res;
|
sl@0
|
382 |
TReal64 trg;
|
sl@0
|
383 |
TInt ret=x1.Div(res,x2);
|
sl@0
|
384 |
if (ret==KErrNone) // must check this because if underflow, error is lost in conversion
|
sl@0
|
385 |
ret=res.GetTReal(trg);
|
sl@0
|
386 |
if (ret!=KErrNone)
|
sl@0
|
387 |
MathException(ret);
|
sl@0
|
388 |
|
sl@0
|
389 |
return((TReal64)res);
|
sl@0
|
390 |
}
|
sl@0
|
391 |
|
sl@0
|
392 |
EXPORT_C TReal32 __negsf2(TReal32 a1)
|
sl@0
|
393 |
//
|
sl@0
|
394 |
// Negate a float
|
sl@0
|
395 |
//
|
sl@0
|
396 |
{
|
sl@0
|
397 |
|
sl@0
|
398 |
TRealX x1=a1;
|
sl@0
|
399 |
return((TReal32)-x1);
|
sl@0
|
400 |
}
|
sl@0
|
401 |
|
sl@0
|
402 |
EXPORT_C TReal64 __negdf2(TReal64 a1)
|
sl@0
|
403 |
//
|
sl@0
|
404 |
// Negate a double
|
sl@0
|
405 |
//
|
sl@0
|
406 |
{
|
sl@0
|
407 |
|
sl@0
|
408 |
TRealX x1=a1;
|
sl@0
|
409 |
return((TReal64)-x1);
|
sl@0
|
410 |
}
|
sl@0
|
411 |
|
sl@0
|
412 |
EXPORT_C TReal32 __floatsisf(TInt a1)
|
sl@0
|
413 |
//
|
sl@0
|
414 |
// Convert int to float
|
sl@0
|
415 |
//
|
sl@0
|
416 |
{
|
sl@0
|
417 |
|
sl@0
|
418 |
return((TReal32)TRealX(a1));
|
sl@0
|
419 |
}
|
sl@0
|
420 |
|
sl@0
|
421 |
EXPORT_C TReal64 __floatsidf(TInt a1)
|
sl@0
|
422 |
//
|
sl@0
|
423 |
// Convert int to double
|
sl@0
|
424 |
//
|
sl@0
|
425 |
{
|
sl@0
|
426 |
|
sl@0
|
427 |
return((TReal64)TRealX(a1));
|
sl@0
|
428 |
}
|
sl@0
|
429 |
|
sl@0
|
430 |
EXPORT_C TInt __fixsfsi(TReal32 a1)
|
sl@0
|
431 |
//
|
sl@0
|
432 |
// Convert float to int
|
sl@0
|
433 |
//
|
sl@0
|
434 |
{
|
sl@0
|
435 |
|
sl@0
|
436 |
return((TInt)TRealX(a1));
|
sl@0
|
437 |
}
|
sl@0
|
438 |
|
sl@0
|
439 |
EXPORT_C TInt __fixdfsi(TReal64 a1)
|
sl@0
|
440 |
//
|
sl@0
|
441 |
// Convert double to int
|
sl@0
|
442 |
//
|
sl@0
|
443 |
{
|
sl@0
|
444 |
|
sl@0
|
445 |
return((TInt)TRealX(a1));
|
sl@0
|
446 |
}
|
sl@0
|
447 |
|
sl@0
|
448 |
EXPORT_C TReal64 __extendsfdf2(TReal32 a1)
|
sl@0
|
449 |
//
|
sl@0
|
450 |
// Convert a float to a double
|
sl@0
|
451 |
//
|
sl@0
|
452 |
{
|
sl@0
|
453 |
|
sl@0
|
454 |
return((TReal64)TRealX(a1));
|
sl@0
|
455 |
}
|
sl@0
|
456 |
|
sl@0
|
457 |
EXPORT_C TReal32 __truncdfsf2(TReal64 a1)
|
sl@0
|
458 |
//
|
sl@0
|
459 |
// Convert a double to a float
|
sl@0
|
460 |
// Raises an exception if conversion results in an error
|
sl@0
|
461 |
//
|
sl@0
|
462 |
{
|
sl@0
|
463 |
|
sl@0
|
464 |
TRealX x1=a1;
|
sl@0
|
465 |
|
sl@0
|
466 |
TInt ret;
|
sl@0
|
467 |
TReal32 trg;
|
sl@0
|
468 |
if ((ret=x1.GetTReal(trg))!=KErrNone)
|
sl@0
|
469 |
MathException(ret);
|
sl@0
|
470 |
|
sl@0
|
471 |
return(trg);
|
sl@0
|
472 |
}
|
sl@0
|
473 |
#endif //__REALS_MACHINE_CODED__
|