|
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_gcc64.cpp |
|
15 // From UP_GCC.CPP, for emulating UP_GCC in T_R64.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 // DOES NOT CONVERT TO SPECIAL IF RETURNS |
|
29 // Added by AnnW, December 1996 |
|
30 // |
|
31 { |
|
32 |
|
33 TExcType excType=EExcGeneral; |
|
34 |
|
35 switch (aErrType) |
|
36 { |
|
37 case KErrArgument: // error due to invalid operation |
|
38 excType=EExcFloatInvalidOperation; |
|
39 break; |
|
40 case KErrDivideByZero: |
|
41 excType=EExcFloatDivideByZero; |
|
42 break; |
|
43 case KErrOverflow: |
|
44 excType=EExcFloatOverflow; |
|
45 break; |
|
46 case KErrUnderflow: |
|
47 excType=EExcFloatUnderflow; |
|
48 break; |
|
49 /* |
|
50 // also errors due to inexact result |
|
51 case KErrInexact: // const not defined yet |
|
52 excType=EExcFloatInexact; |
|
53 break; |
|
54 */ |
|
55 |
|
56 default: |
|
57 // Unknown error |
|
58 User::Panic(_L("USER-Math"),EMathUnknownError); |
|
59 } |
|
60 |
|
61 RThread thread; |
|
62 thread.RaiseException(excType); |
|
63 } |
|
64 |
|
65 GLDEF_C TReal64 __adddf3(TReal64 a1,TReal64 a2) |
|
66 // |
|
67 // Add two doubles |
|
68 // |
|
69 { |
|
70 |
|
71 TRealX x1=a1; |
|
72 TRealX x2=a2; |
|
73 |
|
74 TRealX res; |
|
75 TReal64 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 TReal64 __subdf3(TReal64 a1,TReal64 a2) |
|
85 // |
|
86 // Subtract two doubles |
|
87 // |
|
88 { |
|
89 |
|
90 TRealX x1=a1; |
|
91 TRealX x2=a2; |
|
92 |
|
93 TRealX res; |
|
94 TReal64 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 TReal64 __muldf3(TReal64 a1,TReal64 a2) |
|
104 // |
|
105 // Multiply two doubles |
|
106 // |
|
107 { |
|
108 |
|
109 TRealX x1=a1; |
|
110 TRealX x2=a2; |
|
111 |
|
112 TRealX res; |
|
113 TReal64 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((TReal64)res); |
|
121 } |
|
122 |
|
123 GLDEF_C TReal64 __divdf3(TReal64 a1,TReal64 a2) |
|
124 // |
|
125 // Divide two doubles |
|
126 // |
|
127 { |
|
128 |
|
129 TRealX x1=a1; |
|
130 TRealX x2=a2; |
|
131 |
|
132 TRealX res; |
|
133 TReal64 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((TReal64)res); |
|
141 } |