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_r64.cpp
|
sl@0
|
15 |
// T_R64.CPP - Test routines for TReal64
|
sl@0
|
16 |
// Also note that these tests do not generally include testing of special values. This is done
|
sl@0
|
17 |
// in T_R96 tests and conversions are tested thoroughly, so explicit tests are unnecessary here.
|
sl@0
|
18 |
//
|
sl@0
|
19 |
//
|
sl@0
|
20 |
|
sl@0
|
21 |
#include "t_math.h"
|
sl@0
|
22 |
#include "t_vals.h"
|
sl@0
|
23 |
#include "t_real64.h"
|
sl@0
|
24 |
|
sl@0
|
25 |
// Data for tests from T_R64DTA.cpp
|
sl@0
|
26 |
GLREF_D TReal64 addInput[];
|
sl@0
|
27 |
GLREF_D TReal64 subInput[];
|
sl@0
|
28 |
GLREF_D TReal64 multInput[];
|
sl@0
|
29 |
GLREF_D TReal64 divInput[];
|
sl@0
|
30 |
GLREF_D TReal64 divDenormalInput[];
|
sl@0
|
31 |
GLREF_D TReal64 unaryInput[];
|
sl@0
|
32 |
GLREF_D TReal64 incDecInput[];
|
sl@0
|
33 |
GLREF_D TInt sizeAdd;
|
sl@0
|
34 |
GLREF_D TInt sizeSub;
|
sl@0
|
35 |
GLREF_D TInt sizeMult;
|
sl@0
|
36 |
GLREF_D TInt sizeDiv;
|
sl@0
|
37 |
GLREF_D TInt sizeDivDenormal;
|
sl@0
|
38 |
GLREF_D TInt sizeUnary;
|
sl@0
|
39 |
GLREF_D TInt sizeIncDec;
|
sl@0
|
40 |
|
sl@0
|
41 |
#if defined (__WINS__) || defined (__X86__)
|
sl@0
|
42 |
// Functions from EMGCC64.CPP
|
sl@0
|
43 |
GLREF_C TReal64 __adddf3(TReal64 a1,TReal64 a2);
|
sl@0
|
44 |
GLREF_C TReal64 __subdf3(TReal64 a1,TReal64 a2);
|
sl@0
|
45 |
GLREF_C TReal64 __muldf3(TReal64 a1,TReal64 a2);
|
sl@0
|
46 |
GLREF_C TReal64 __divdf3(TReal64 a1,TReal64 a2);
|
sl@0
|
47 |
#endif
|
sl@0
|
48 |
|
sl@0
|
49 |
// Special numbers for arithmetic tests
|
sl@0
|
50 |
GLDEF_D TReal64 endsInFour;
|
sl@0
|
51 |
GLDEF_D TReal64 arg1;
|
sl@0
|
52 |
GLDEF_D TReal64 arg2;
|
sl@0
|
53 |
GLDEF_D TReal64 arg3;
|
sl@0
|
54 |
GLDEF_D const TReal64 KMinDenormalTReal64=5E-324;
|
sl@0
|
55 |
GLDEF_D const TReal KNaNTReal=TReal(KNaNTReal64);
|
sl@0
|
56 |
GLDEF_D const TReal KPosInfTReal=TReal(KPosInfTReal64);;
|
sl@0
|
57 |
GLDEF_D const TReal KNegInfTReal=TReal(KNegInfTReal64);;
|
sl@0
|
58 |
GLDEF_D const TReal KMinDenormalTReal=5E-324;
|
sl@0
|
59 |
|
sl@0
|
60 |
enum TOrder
|
sl@0
|
61 |
{
|
sl@0
|
62 |
ELessThan,
|
sl@0
|
63 |
EEqual,
|
sl@0
|
64 |
EGreaterThan
|
sl@0
|
65 |
};
|
sl@0
|
66 |
|
sl@0
|
67 |
LOCAL_D RTest test(_L("T_R64"));
|
sl@0
|
68 |
|
sl@0
|
69 |
#if defined (__WINS__) || defined (__X86__)
|
sl@0
|
70 |
|
sl@0
|
71 |
LOCAL_C void testConstants()
|
sl@0
|
72 |
//
|
sl@0
|
73 |
// Checks that constants are defined as expected in WINS, in case low and high words are swapped
|
sl@0
|
74 |
//
|
sl@0
|
75 |
{
|
sl@0
|
76 |
|
sl@0
|
77 |
test(TRealX(TReal32(KMinTReal32in64))==TRealX(KMinTReal32));
|
sl@0
|
78 |
test(TRealX(TReal32(KMaxTReal32in64))==TRealX(KMaxTReal32));
|
sl@0
|
79 |
}
|
sl@0
|
80 |
|
sl@0
|
81 |
#endif
|
sl@0
|
82 |
|
sl@0
|
83 |
LOCAL_C void initSpecialValues()
|
sl@0
|
84 |
//
|
sl@0
|
85 |
// Initialise special values, etc
|
sl@0
|
86 |
//
|
sl@0
|
87 |
{
|
sl@0
|
88 |
|
sl@0
|
89 |
SReal64* p64=(SReal64*)&endsInFour;
|
sl@0
|
90 |
p64->sign=0;
|
sl@0
|
91 |
p64->exp=1020;
|
sl@0
|
92 |
p64->msm=0;
|
sl@0
|
93 |
p64->lsm=0x4;
|
sl@0
|
94 |
|
sl@0
|
95 |
p64=(SReal64*)&arg1;
|
sl@0
|
96 |
p64->sign=0;
|
sl@0
|
97 |
p64->exp=1075;
|
sl@0
|
98 |
p64->msm=0x20000;
|
sl@0
|
99 |
p64->lsm=0;
|
sl@0
|
100 |
|
sl@0
|
101 |
p64=(SReal64*)&arg2;
|
sl@0
|
102 |
p64->sign=0;
|
sl@0
|
103 |
p64->exp=1075;
|
sl@0
|
104 |
p64->msm=0;
|
sl@0
|
105 |
p64->lsm=0x2a;
|
sl@0
|
106 |
|
sl@0
|
107 |
p64=(SReal64*)&arg3;
|
sl@0
|
108 |
p64->sign=0;
|
sl@0
|
109 |
p64->exp=970;
|
sl@0
|
110 |
p64->msm=0xc71c7;
|
sl@0
|
111 |
p64->lsm=0x1c71c71c;
|
sl@0
|
112 |
}
|
sl@0
|
113 |
|
sl@0
|
114 |
LOCAL_C void testConvert()
|
sl@0
|
115 |
//
|
sl@0
|
116 |
// Test conversion from TReal to TReal64
|
sl@0
|
117 |
// N.B. Conversions between TRealX and TReal64 are tested by t_r96.cpp
|
sl@0
|
118 |
//
|
sl@0
|
119 |
{
|
sl@0
|
120 |
|
sl@0
|
121 |
const TReal input[]=
|
sl@0
|
122 |
{
|
sl@0
|
123 |
KMaxTReal,KMinTReal,-KMaxTReal,-KMinTReal,
|
sl@0
|
124 |
1.7976931348622E+308,-1.7976931348622E+308,2.2250738585073E-308,-2.2250738585073E-308,
|
sl@0
|
125 |
KMaxTReal32inTReal,KMinTReal32inTReal,-KMaxTReal32inTReal,-KMinTReal32inTReal,
|
sl@0
|
126 |
0.0,64.5,-64.5,1.54E+180,-1.54E+180,4.72E-225,-4.72E-225,
|
sl@0
|
127 |
KNegZeroTReal,KPosInfTReal,KNegInfTReal,KMinDenormalTReal,
|
sl@0
|
128 |
1.2345E-318,-2.4682E-321,1.0E-323,-2.0E-308
|
sl@0
|
129 |
};
|
sl@0
|
130 |
|
sl@0
|
131 |
const TReal64 expect[]=
|
sl@0
|
132 |
{
|
sl@0
|
133 |
KMaxTReal64,KMinTReal64,-KMaxTReal64,-KMinTReal64,
|
sl@0
|
134 |
1.7976931348622E+308,-1.7976931348622E+308,2.2250738585073E-308,-2.2250738585073E-308,
|
sl@0
|
135 |
KMaxTReal32in64,KMinTReal32in64,-KMaxTReal32in64,-KMinTReal32in64,
|
sl@0
|
136 |
0.0,64.5,-64.5,1.54E+180,-1.54E+180,4.72E-225,-4.72E-225,
|
sl@0
|
137 |
KNegZeroTReal64,KPosInfTReal64,KNegInfTReal64,KMinDenormalTReal64,
|
sl@0
|
138 |
1.2345E-318,-2.4682E-321,1.0E-323,-2.0E-308
|
sl@0
|
139 |
};
|
sl@0
|
140 |
|
sl@0
|
141 |
TInt size = sizeof(input)/sizeof(TReal);
|
sl@0
|
142 |
TRealX f;
|
sl@0
|
143 |
|
sl@0
|
144 |
for (TInt ii=0; ii<size; ii++)
|
sl@0
|
145 |
{
|
sl@0
|
146 |
f=TRealX(TReal64(TRealX(input[ii])));
|
sl@0
|
147 |
test(f==TRealX(expect[ii]));
|
sl@0
|
148 |
}
|
sl@0
|
149 |
|
sl@0
|
150 |
// NaN
|
sl@0
|
151 |
TReal a=KNaNTReal;
|
sl@0
|
152 |
// TReal64 b=KNaNTReal64;
|
sl@0
|
153 |
f=TRealX(TReal64(TRealX(a)));
|
sl@0
|
154 |
// test(f!=TRealX(b));
|
sl@0
|
155 |
test(f.IsNaN());
|
sl@0
|
156 |
}
|
sl@0
|
157 |
|
sl@0
|
158 |
LOCAL_C void testAdd()
|
sl@0
|
159 |
//
|
sl@0
|
160 |
// Addition tests
|
sl@0
|
161 |
//
|
sl@0
|
162 |
{
|
sl@0
|
163 |
TReal64 f,g,h,y;
|
sl@0
|
164 |
TRealX ff,gg,hh;
|
sl@0
|
165 |
|
sl@0
|
166 |
for (TInt ii=0; ii<sizeAdd-1; ii++)
|
sl@0
|
167 |
{
|
sl@0
|
168 |
f=addInput[ii];
|
sl@0
|
169 |
g=addInput[ii+1];
|
sl@0
|
170 |
ff=TRealX(f);
|
sl@0
|
171 |
gg=TRealX(g);
|
sl@0
|
172 |
// Test commute
|
sl@0
|
173 |
test(f+g == g+f);
|
sl@0
|
174 |
// Test PC real addition using fp-hardware same as TRealX addition
|
sl@0
|
175 |
h=f+g;
|
sl@0
|
176 |
hh=ff+gg;
|
sl@0
|
177 |
y=(TReal64)hh; // need to do this since TRealX has too much precision
|
sl@0
|
178 |
test(y==h);
|
sl@0
|
179 |
h=g+f;
|
sl@0
|
180 |
hh=gg+ff;
|
sl@0
|
181 |
y=(TReal64)hh; // need to do this since TRealX has too much precision
|
sl@0
|
182 |
test(y==h);
|
sl@0
|
183 |
// Test hex-encoded constants for TReal64s generated on PC using fp-hardware same as
|
sl@0
|
184 |
// TRealX addition
|
sl@0
|
185 |
test(*(TReal64*)&addArray[ii]==f+g);
|
sl@0
|
186 |
test(*(TReal64*)&addArray[ii]==g+f);
|
sl@0
|
187 |
// similarly to tests above ...
|
sl@0
|
188 |
h=g;
|
sl@0
|
189 |
hh=gg;
|
sl@0
|
190 |
h+=f;
|
sl@0
|
191 |
hh+=ff;
|
sl@0
|
192 |
test(h==(TReal64)hh);
|
sl@0
|
193 |
test(*(TReal64*)&addArray[ii]==h);
|
sl@0
|
194 |
//
|
sl@0
|
195 |
h=f;
|
sl@0
|
196 |
hh=ff;
|
sl@0
|
197 |
h+=g;
|
sl@0
|
198 |
hh+=gg;
|
sl@0
|
199 |
test(h==(TReal64)hh);
|
sl@0
|
200 |
test(*(TReal64*)&addArray[ii]==h);
|
sl@0
|
201 |
}
|
sl@0
|
202 |
}
|
sl@0
|
203 |
|
sl@0
|
204 |
LOCAL_C void testSub()
|
sl@0
|
205 |
//
|
sl@0
|
206 |
// Subtraction tests - see notes in addition test above
|
sl@0
|
207 |
//
|
sl@0
|
208 |
{
|
sl@0
|
209 |
TReal64 f,g,h;
|
sl@0
|
210 |
TRealX ff,gg,hh;
|
sl@0
|
211 |
|
sl@0
|
212 |
for (TInt ii=0; ii<sizeSub-1; ii++)
|
sl@0
|
213 |
{
|
sl@0
|
214 |
f=subInput[ii];
|
sl@0
|
215 |
g=subInput[ii+1];
|
sl@0
|
216 |
ff=TRealX(f);
|
sl@0
|
217 |
gg=TRealX(g);
|
sl@0
|
218 |
//
|
sl@0
|
219 |
test(f-g == -(g-f));
|
sl@0
|
220 |
//
|
sl@0
|
221 |
test(TRealX(f-g)==ff-gg);
|
sl@0
|
222 |
test(TRealX(g-f)==gg-ff);
|
sl@0
|
223 |
test(*(TReal64*)&subArray[ii]==f-g);
|
sl@0
|
224 |
test(*(TReal64*)&subArray[ii]==-(g-f));
|
sl@0
|
225 |
//
|
sl@0
|
226 |
h=g;
|
sl@0
|
227 |
hh=gg;
|
sl@0
|
228 |
test(TRealX(h-=f)==(hh-=ff));
|
sl@0
|
229 |
test(TRealX(h)==hh);
|
sl@0
|
230 |
test(*(TReal64*)&subArray[ii]==-h);
|
sl@0
|
231 |
//
|
sl@0
|
232 |
h=f;
|
sl@0
|
233 |
hh=ff;
|
sl@0
|
234 |
test(TRealX(h-=g)==(hh-=gg));
|
sl@0
|
235 |
test(TRealX(h)==hh);
|
sl@0
|
236 |
test(*(TReal64*)&subArray[ii]==h);
|
sl@0
|
237 |
}
|
sl@0
|
238 |
}
|
sl@0
|
239 |
|
sl@0
|
240 |
LOCAL_C void testMult()
|
sl@0
|
241 |
//
|
sl@0
|
242 |
// Multiplication test
|
sl@0
|
243 |
//
|
sl@0
|
244 |
{
|
sl@0
|
245 |
TReal64 f,g,h;
|
sl@0
|
246 |
TRealX ff,gg,hh;
|
sl@0
|
247 |
|
sl@0
|
248 |
for (TInt ii=0; ii<sizeMult-1; ii++)
|
sl@0
|
249 |
{
|
sl@0
|
250 |
f=multInput[ii];
|
sl@0
|
251 |
g=multInput[ii+1];
|
sl@0
|
252 |
ff=TRealX(f);
|
sl@0
|
253 |
gg=TRealX(g);
|
sl@0
|
254 |
//
|
sl@0
|
255 |
test(f*g == g*f);
|
sl@0
|
256 |
//
|
sl@0
|
257 |
test(TRealX(f*g)==ff*gg);
|
sl@0
|
258 |
test(TRealX(g*f)==gg*ff);
|
sl@0
|
259 |
test(*(TReal64*)&multArray[ii]==f*g);
|
sl@0
|
260 |
test(*(TReal64*)&multArray[ii]==g*f);
|
sl@0
|
261 |
//
|
sl@0
|
262 |
h=f;
|
sl@0
|
263 |
hh=ff;
|
sl@0
|
264 |
test(TRealX(h*=g)==(hh*=gg));
|
sl@0
|
265 |
test(TRealX(h)==hh);
|
sl@0
|
266 |
test(*(TReal64*)&multArray[ii]==h);
|
sl@0
|
267 |
//
|
sl@0
|
268 |
h=g;
|
sl@0
|
269 |
hh=gg;
|
sl@0
|
270 |
test(TRealX(h*=f)==(hh*=ff));
|
sl@0
|
271 |
test(TRealX(h)==hh);
|
sl@0
|
272 |
test(*(TReal64*)&multArray[ii]==h);
|
sl@0
|
273 |
}
|
sl@0
|
274 |
}
|
sl@0
|
275 |
|
sl@0
|
276 |
LOCAL_C void testDiv()
|
sl@0
|
277 |
//
|
sl@0
|
278 |
// Division tests
|
sl@0
|
279 |
//
|
sl@0
|
280 |
{
|
sl@0
|
281 |
TReal64 f,g,h;
|
sl@0
|
282 |
TRealX ff,gg,hh;
|
sl@0
|
283 |
TInt count=0;
|
sl@0
|
284 |
|
sl@0
|
285 |
// Panic (under ARM) - Divide by Zero - run in DEBUG build as a check only
|
sl@0
|
286 |
//f=1.0;
|
sl@0
|
287 |
//g=0.0;
|
sl@0
|
288 |
//f/=g;
|
sl@0
|
289 |
|
sl@0
|
290 |
for (TInt ii=0; ii<sizeDiv-1; ii++)
|
sl@0
|
291 |
{
|
sl@0
|
292 |
f=divInput[ii];
|
sl@0
|
293 |
g=divInput[ii+1];
|
sl@0
|
294 |
ff=TRealX(f);
|
sl@0
|
295 |
gg=TRealX(g);
|
sl@0
|
296 |
if (g!=0.0)
|
sl@0
|
297 |
{
|
sl@0
|
298 |
test(TRealX(f/g)==ff/gg);
|
sl@0
|
299 |
test(*(TReal64*)&divArray[count]==f/g);
|
sl@0
|
300 |
//
|
sl@0
|
301 |
h=f;
|
sl@0
|
302 |
hh=ff;
|
sl@0
|
303 |
test(TRealX(h/=g)==(hh/=gg));
|
sl@0
|
304 |
test(TRealX(h)==hh);
|
sl@0
|
305 |
test(*(TReal64*)&divArray[count]==h);
|
sl@0
|
306 |
++count;
|
sl@0
|
307 |
}
|
sl@0
|
308 |
if (f!=0.0)
|
sl@0
|
309 |
{
|
sl@0
|
310 |
test(TRealX(g/f)==gg/ff);
|
sl@0
|
311 |
//
|
sl@0
|
312 |
h=g;
|
sl@0
|
313 |
hh=gg;
|
sl@0
|
314 |
test(TRealX(h/=f)==(hh/=ff));
|
sl@0
|
315 |
test(TRealX(h)==hh);
|
sl@0
|
316 |
}
|
sl@0
|
317 |
}
|
sl@0
|
318 |
|
sl@0
|
319 |
gg=TRealX(arg2)/TRealX(arg3);
|
sl@0
|
320 |
|
sl@0
|
321 |
//Additional test
|
sl@0
|
322 |
f=3.999999999999999;
|
sl@0
|
323 |
g=KMinTReal64;
|
sl@0
|
324 |
ff=TRealX(f);
|
sl@0
|
325 |
gg=TRealX(g);
|
sl@0
|
326 |
test(TRealX(f/g)==ff/gg);
|
sl@0
|
327 |
h=f;
|
sl@0
|
328 |
test(TRealX(h/=g)==ff/gg);
|
sl@0
|
329 |
test(TRealX(h)==ff/gg);
|
sl@0
|
330 |
}
|
sl@0
|
331 |
|
sl@0
|
332 |
#if defined (__WINS__) || defined (__X86__)
|
sl@0
|
333 |
|
sl@0
|
334 |
LOCAL_C void testArithmeticExceptionRaising()
|
sl@0
|
335 |
//
|
sl@0
|
336 |
// Test that UP_GCC.CPP raise exceptions correctly by calling functions from EMGCC64.CPP which
|
sl@0
|
337 |
// are copies of those in UP_GCC.CPP. To be used in debugger only.
|
sl@0
|
338 |
// Added by AnnW, December 1996
|
sl@0
|
339 |
//
|
sl@0
|
340 |
{
|
sl@0
|
341 |
TReal64 f,g,h;
|
sl@0
|
342 |
|
sl@0
|
343 |
// Addition - possible errors are argument, overflow, or none
|
sl@0
|
344 |
// NB cannot achieve underflow now denormals in use
|
sl@0
|
345 |
|
sl@0
|
346 |
f=KNaNTReal64;
|
sl@0
|
347 |
h=__adddf3(f,f); // argument
|
sl@0
|
348 |
|
sl@0
|
349 |
f=KMaxTReal64;
|
sl@0
|
350 |
h=__adddf3(f,f); // overflow
|
sl@0
|
351 |
|
sl@0
|
352 |
f=1.0;
|
sl@0
|
353 |
g=2.0;
|
sl@0
|
354 |
h=__adddf3(f,g); // none
|
sl@0
|
355 |
test(h==3.0);
|
sl@0
|
356 |
|
sl@0
|
357 |
// Subtraction - possible errors are argumnet, overflow or none
|
sl@0
|
358 |
// NB cannot achieve underflow now denormals in use
|
sl@0
|
359 |
|
sl@0
|
360 |
f=KNaNTReal64;
|
sl@0
|
361 |
h=__subdf3(f,f); // argument
|
sl@0
|
362 |
|
sl@0
|
363 |
f=KMaxTReal64;
|
sl@0
|
364 |
g=-KMaxTReal64;
|
sl@0
|
365 |
h=__subdf3(f,g); // overflow
|
sl@0
|
366 |
|
sl@0
|
367 |
f=1.0;
|
sl@0
|
368 |
g=2.0;
|
sl@0
|
369 |
h=__subdf3(f,g); // none
|
sl@0
|
370 |
test(h==-1.0);
|
sl@0
|
371 |
|
sl@0
|
372 |
// Multiplication - possible errors are argument, overflow, underflow or none
|
sl@0
|
373 |
|
sl@0
|
374 |
f=KNaNTReal64;
|
sl@0
|
375 |
h=__muldf3(f,f); // argument
|
sl@0
|
376 |
|
sl@0
|
377 |
f=KMaxTReal64;
|
sl@0
|
378 |
g=2.0;
|
sl@0
|
379 |
h=__muldf3(f,g); // overflow
|
sl@0
|
380 |
|
sl@0
|
381 |
f=KMinDenormalTReal64;
|
sl@0
|
382 |
g=0.1;
|
sl@0
|
383 |
h=__muldf3(f,g); // underflow
|
sl@0
|
384 |
|
sl@0
|
385 |
f=1.0;
|
sl@0
|
386 |
g=2.0;
|
sl@0
|
387 |
h=__muldf3(f,g); // none
|
sl@0
|
388 |
test(h==2.0);
|
sl@0
|
389 |
|
sl@0
|
390 |
// Division - possible errors are overflow, underflow, divide by zero, argument or none
|
sl@0
|
391 |
|
sl@0
|
392 |
f=KMaxTReal64;
|
sl@0
|
393 |
g=0.5;
|
sl@0
|
394 |
h=__divdf3(f,g); // overflow
|
sl@0
|
395 |
|
sl@0
|
396 |
f=KMinDenormalTReal64;
|
sl@0
|
397 |
g=10.0;
|
sl@0
|
398 |
h=__divdf3(f,g); // underflow
|
sl@0
|
399 |
|
sl@0
|
400 |
f=4.0;
|
sl@0
|
401 |
g=0.0;
|
sl@0
|
402 |
h=__divdf3(f,g); // divide by zero
|
sl@0
|
403 |
|
sl@0
|
404 |
f=0.0;
|
sl@0
|
405 |
g=0.0;
|
sl@0
|
406 |
h=__divdf3(f,g); // argument
|
sl@0
|
407 |
|
sl@0
|
408 |
f=1.0;
|
sl@0
|
409 |
g=2.0;
|
sl@0
|
410 |
h=__divdf3(f,g); // none
|
sl@0
|
411 |
test(h==0.5);
|
sl@0
|
412 |
}
|
sl@0
|
413 |
|
sl@0
|
414 |
#endif
|
sl@0
|
415 |
|
sl@0
|
416 |
LOCAL_C void testUnary()
|
sl@0
|
417 |
//
|
sl@0
|
418 |
// Unary operator tests
|
sl@0
|
419 |
//
|
sl@0
|
420 |
{
|
sl@0
|
421 |
TReal64 f;
|
sl@0
|
422 |
TRealX g;
|
sl@0
|
423 |
|
sl@0
|
424 |
for (TInt ii=0; ii<sizeUnary-1; ii++)
|
sl@0
|
425 |
{
|
sl@0
|
426 |
f=unaryInput[ii];
|
sl@0
|
427 |
g=TRealX(f);
|
sl@0
|
428 |
test(TRealX(-f)==-g);
|
sl@0
|
429 |
test(TRealX(-f)==TRealX(0-f));
|
sl@0
|
430 |
test(TRealX(+f)==g);
|
sl@0
|
431 |
test(TRealX(+f)==TRealX(0+f));
|
sl@0
|
432 |
test(*(TReal64*)&unaryArray[ii]==-f);
|
sl@0
|
433 |
}
|
sl@0
|
434 |
}
|
sl@0
|
435 |
|
sl@0
|
436 |
LOCAL_C void testEqualities(const TReal& aA, TOrder aOrder, const TReal& aB)
|
sl@0
|
437 |
//
|
sl@0
|
438 |
// Test equality/inequality functions on aA and aB
|
sl@0
|
439 |
// aOrder specifies the operand's relative sizes
|
sl@0
|
440 |
//
|
sl@0
|
441 |
{
|
sl@0
|
442 |
// Tautologies
|
sl@0
|
443 |
test((aA>aA) ==FALSE);
|
sl@0
|
444 |
test((aA<aA) ==FALSE);
|
sl@0
|
445 |
test((aA>=aA)==TRUE);
|
sl@0
|
446 |
test((aA<=aA)==TRUE);
|
sl@0
|
447 |
test((aA==aA)==TRUE);
|
sl@0
|
448 |
test((aA!=aA)==FALSE);
|
sl@0
|
449 |
|
sl@0
|
450 |
if (aOrder!=EEqual)
|
sl@0
|
451 |
{
|
sl@0
|
452 |
test((aA==aB)==FALSE);
|
sl@0
|
453 |
test((aA!=aB)==TRUE);
|
sl@0
|
454 |
}
|
sl@0
|
455 |
|
sl@0
|
456 |
if (aOrder==ELessThan)
|
sl@0
|
457 |
{
|
sl@0
|
458 |
test((aA<aB) ==TRUE);
|
sl@0
|
459 |
test((aA<=aB)==TRUE);
|
sl@0
|
460 |
test((aA>aB) ==FALSE);
|
sl@0
|
461 |
test((aA>=aB)==FALSE);
|
sl@0
|
462 |
}
|
sl@0
|
463 |
|
sl@0
|
464 |
if (aOrder==EEqual)
|
sl@0
|
465 |
{
|
sl@0
|
466 |
test((aA==aB)==TRUE);
|
sl@0
|
467 |
test((aA!=aB)==FALSE);
|
sl@0
|
468 |
test((aA>=aB)==TRUE);
|
sl@0
|
469 |
test((aA<=aB)==TRUE);
|
sl@0
|
470 |
test((aA>aB)==FALSE);
|
sl@0
|
471 |
test((aA<aB)==FALSE);
|
sl@0
|
472 |
}
|
sl@0
|
473 |
|
sl@0
|
474 |
if (aOrder==EGreaterThan)
|
sl@0
|
475 |
{
|
sl@0
|
476 |
test((aA>aB) ==TRUE);
|
sl@0
|
477 |
test((aA>=aB)==TRUE);
|
sl@0
|
478 |
test((aA<aB) ==FALSE);
|
sl@0
|
479 |
test((aA<=aB)==FALSE);
|
sl@0
|
480 |
}
|
sl@0
|
481 |
}
|
sl@0
|
482 |
|
sl@0
|
483 |
LOCAL_C void testEqualities()
|
sl@0
|
484 |
//
|
sl@0
|
485 |
// Test >, <, >=, <=, ==, !=
|
sl@0
|
486 |
//
|
sl@0
|
487 |
{
|
sl@0
|
488 |
TInt i, size;
|
sl@0
|
489 |
TReal64 lessThanMax = KMaxTReal64-TReal64(1.0E+294);
|
sl@0
|
490 |
TReal64 greaterThanMin = TReal64(2.225075E-308);
|
sl@0
|
491 |
TReal64 zero(0.0);
|
sl@0
|
492 |
|
sl@0
|
493 |
TReal64 positive[] =
|
sl@0
|
494 |
{KMinTReal64,5.3824705392348592E-138,1.0,2387501,5.3824705392348592E+138,KMaxTReal64};
|
sl@0
|
495 |
|
sl@0
|
496 |
TReal64 large[] =
|
sl@0
|
497 |
{2.0,KMaxTReal64,-lessThanMax,greaterThanMin,-KMinTReal64,10.40584821945060,-10.40584821945058,
|
sl@0
|
498 |
1.244334567201E+105,1.244334567201E+105,-1.3420344230402E-106,132435.97865,5.0E-16,9.6,-8.0};
|
sl@0
|
499 |
|
sl@0
|
500 |
TReal64 small[] =
|
sl@0
|
501 |
{1.0,lessThanMax,-KMaxTReal64,KMinTReal64,-greaterThanMin,10.40584821945058,-10.40584821945060,
|
sl@0
|
502 |
50E-100,1.244334567201E+104,-5.03824705392348592E+58,-132435.97865,-5.1E-16,8.0,-9.6};
|
sl@0
|
503 |
|
sl@0
|
504 |
TReal64 equal[] = // Same as large[]
|
sl@0
|
505 |
{2.0,KMaxTReal64,-lessThanMax,greaterThanMin,-KMinTReal64,10.40584821945060,-10.40584821945058,
|
sl@0
|
506 |
1.244334567201E+105,1.244334567201E+105,-1.3420344230402E-106,132435.97865,5.0E-16,9.6,-8.0};
|
sl@0
|
507 |
|
sl@0
|
508 |
// Tests with zero
|
sl@0
|
509 |
|
sl@0
|
510 |
size = sizeof(positive)/sizeof(TReal64);
|
sl@0
|
511 |
|
sl@0
|
512 |
test.Start(_L("Zero"));
|
sl@0
|
513 |
testEqualities(zero, EEqual, zero);
|
sl@0
|
514 |
for (i=0; i<size; i++)
|
sl@0
|
515 |
{
|
sl@0
|
516 |
testEqualities(positive[i], EGreaterThan, zero);
|
sl@0
|
517 |
testEqualities(-positive[i], ELessThan, zero);
|
sl@0
|
518 |
testEqualities(zero, ELessThan, positive[i]);
|
sl@0
|
519 |
testEqualities(zero, EGreaterThan, -positive[i]);
|
sl@0
|
520 |
}
|
sl@0
|
521 |
|
sl@0
|
522 |
// Test boundary and other numbers
|
sl@0
|
523 |
|
sl@0
|
524 |
size = sizeof(large)/sizeof(TReal64);
|
sl@0
|
525 |
|
sl@0
|
526 |
test.Next(_L("Nonzero"));
|
sl@0
|
527 |
for (i=0; i<size; i++)
|
sl@0
|
528 |
{
|
sl@0
|
529 |
testEqualities(large[i], EGreaterThan, small[i]);
|
sl@0
|
530 |
testEqualities(small[i], ELessThan, large[i]);
|
sl@0
|
531 |
testEqualities(large[i], EEqual, equal[i]);
|
sl@0
|
532 |
}
|
sl@0
|
533 |
|
sl@0
|
534 |
test.End();
|
sl@0
|
535 |
}
|
sl@0
|
536 |
|
sl@0
|
537 |
LOCAL_C void testIncDec()
|
sl@0
|
538 |
//
|
sl@0
|
539 |
// Test Pre/Post-increment/decrement
|
sl@0
|
540 |
//
|
sl@0
|
541 |
{
|
sl@0
|
542 |
TInt ii;
|
sl@0
|
543 |
TReal64 f;
|
sl@0
|
544 |
TRealX g;
|
sl@0
|
545 |
|
sl@0
|
546 |
test.Start(_L("Pre-increment"));
|
sl@0
|
547 |
|
sl@0
|
548 |
for (ii=0; ii<sizeIncDec; ii++)
|
sl@0
|
549 |
{
|
sl@0
|
550 |
f=incDecInput[ii];
|
sl@0
|
551 |
g=TRealX(f);
|
sl@0
|
552 |
test(TRealX(f)==g);
|
sl@0
|
553 |
test(TRealX(++f)==(++g));
|
sl@0
|
554 |
test(*(TReal64*)&preIncArray1[ii]==f);
|
sl@0
|
555 |
test(TRealX(f)==g);
|
sl@0
|
556 |
test(TRealX(++f)==(++g));
|
sl@0
|
557 |
test(*(TReal64*)&preIncArray2[ii]==f);
|
sl@0
|
558 |
test(TRealX(f)==g);
|
sl@0
|
559 |
}
|
sl@0
|
560 |
|
sl@0
|
561 |
test.Next(_L("Post-increment"));
|
sl@0
|
562 |
|
sl@0
|
563 |
for (ii=0; ii<sizeIncDec; ii++)
|
sl@0
|
564 |
{
|
sl@0
|
565 |
f=incDecInput[ii];
|
sl@0
|
566 |
g=TRealX(f);
|
sl@0
|
567 |
test(TRealX(f)==g);
|
sl@0
|
568 |
test(TRealX(f++)==(g++));
|
sl@0
|
569 |
test(*(TReal64*)&postIncArray1[ii]==f);
|
sl@0
|
570 |
test(TRealX(f)==g);
|
sl@0
|
571 |
test(TRealX(f++)==(g++));
|
sl@0
|
572 |
test(*(TReal64*)&postIncArray2[ii]==f);
|
sl@0
|
573 |
test(TRealX(f)==g);
|
sl@0
|
574 |
}
|
sl@0
|
575 |
|
sl@0
|
576 |
test.Next(_L("Pre-decrement"));
|
sl@0
|
577 |
|
sl@0
|
578 |
for (ii=0; ii<sizeIncDec; ii++)
|
sl@0
|
579 |
{
|
sl@0
|
580 |
f=incDecInput[ii];
|
sl@0
|
581 |
g=TRealX(f);
|
sl@0
|
582 |
test(TRealX(f)==g);
|
sl@0
|
583 |
test(TRealX(--f)==(--g));
|
sl@0
|
584 |
test(*(TReal64*)&preDecArray1[ii]==f);
|
sl@0
|
585 |
test(TRealX(f)==g);
|
sl@0
|
586 |
test(TRealX(--f)==(--g));
|
sl@0
|
587 |
test(*(TReal64*)&preDecArray2[ii]==f);
|
sl@0
|
588 |
test(TRealX(f)==g);
|
sl@0
|
589 |
}
|
sl@0
|
590 |
|
sl@0
|
591 |
test.Next(_L("Post-decrement"));
|
sl@0
|
592 |
|
sl@0
|
593 |
for (ii=0; ii<sizeIncDec; ii++)
|
sl@0
|
594 |
{
|
sl@0
|
595 |
f=incDecInput[ii];
|
sl@0
|
596 |
g=TRealX(f);
|
sl@0
|
597 |
test(TRealX(f)==g);
|
sl@0
|
598 |
test(TRealX(f--)==(g--));
|
sl@0
|
599 |
test(*(TReal64*)&postDecArray1[ii]==f);
|
sl@0
|
600 |
test(TRealX(f)==g);
|
sl@0
|
601 |
test(TRealX(f--)==(g--));
|
sl@0
|
602 |
test(*(TReal64*)&postDecArray2[ii]==f);
|
sl@0
|
603 |
test(TRealX(f)==g);
|
sl@0
|
604 |
}
|
sl@0
|
605 |
test.End();
|
sl@0
|
606 |
}
|
sl@0
|
607 |
|
sl@0
|
608 |
LOCAL_C void _matherr(TExcType aType)
|
sl@0
|
609 |
//
|
sl@0
|
610 |
// Dummy function to handle exceptions
|
sl@0
|
611 |
//
|
sl@0
|
612 |
{
|
sl@0
|
613 |
|
sl@0
|
614 |
test.Printf(_L("_matherr: Exception type %u handled\n"),TUint(aType));
|
sl@0
|
615 |
}
|
sl@0
|
616 |
|
sl@0
|
617 |
|
sl@0
|
618 |
GLDEF_C TInt E32Main()
|
sl@0
|
619 |
//
|
sl@0
|
620 |
// Test TReal64
|
sl@0
|
621 |
//
|
sl@0
|
622 |
{
|
sl@0
|
623 |
|
sl@0
|
624 |
test.Title();
|
sl@0
|
625 |
|
sl@0
|
626 |
#if defined (__X86__)
|
sl@0
|
627 |
TInt16 cw=0;
|
sl@0
|
628 |
_asm fstcw cw;
|
sl@0
|
629 |
test.Printf(_L("control word = 0x%x\n"),cw);
|
sl@0
|
630 |
cw=0x27f; // WINS value
|
sl@0
|
631 |
_asm fldcw cw;
|
sl@0
|
632 |
#endif
|
sl@0
|
633 |
|
sl@0
|
634 |
// Set exceptions to be handled
|
sl@0
|
635 |
RThread myThread;
|
sl@0
|
636 |
myThread.SetExceptionHandler(_matherr,KExceptionFpe);
|
sl@0
|
637 |
|
sl@0
|
638 |
initSpecialValues();
|
sl@0
|
639 |
|
sl@0
|
640 |
#if defined (__WINS__) || defined (__X86__)
|
sl@0
|
641 |
test.Start(_L("Checking double words not swapped..."));
|
sl@0
|
642 |
testConstants();
|
sl@0
|
643 |
test.Next(_L("Conversion from TReal to TReal64"));
|
sl@0
|
644 |
testConvert();
|
sl@0
|
645 |
#else
|
sl@0
|
646 |
test.Start(_L("Conversion from TReal to TReal64"));
|
sl@0
|
647 |
testConvert();
|
sl@0
|
648 |
#endif
|
sl@0
|
649 |
test.Next(_L("Conversion from TReal to TReal64"));
|
sl@0
|
650 |
testConvert();
|
sl@0
|
651 |
test.Next(_L("Addition"));
|
sl@0
|
652 |
testAdd();
|
sl@0
|
653 |
test.Next(_L("Subtraction"));
|
sl@0
|
654 |
testSub();
|
sl@0
|
655 |
test.Next(_L("Multiplication"));
|
sl@0
|
656 |
testMult();
|
sl@0
|
657 |
test.Next(_L("Division"));
|
sl@0
|
658 |
testDiv();
|
sl@0
|
659 |
#if defined (__WINS__) || defined (__X86__)
|
sl@0
|
660 |
test.Next(_L("Arithmetic which emulates UP_GCC and raises an exception"));
|
sl@0
|
661 |
testArithmeticExceptionRaising();
|
sl@0
|
662 |
#endif
|
sl@0
|
663 |
test.Next(_L("Unary Operations"));
|
sl@0
|
664 |
testUnary();
|
sl@0
|
665 |
test.Next(_L("Equalities and Inequalities"));
|
sl@0
|
666 |
testEqualities();
|
sl@0
|
667 |
test.Next(_L("Increment and Decrement"));
|
sl@0
|
668 |
testIncDec();
|
sl@0
|
669 |
|
sl@0
|
670 |
test.End();
|
sl@0
|
671 |
return(KErrNone);
|
sl@0
|
672 |
}
|
sl@0
|
673 |
|
sl@0
|
674 |
|