author | Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com> |
Tue, 31 Aug 2010 16:34:26 +0300 | |
branch | RCL_3 |
changeset 43 | c1f20ce4abcf |
parent 0 | a41df078684a |
child 44 | 3e88ff8f41d5 |
permissions | -rw-r--r-- |
0 | 1 |
// Copyright (c) 1995-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_r32.cpp |
|
15 |
// T_R32.CPP - Test routines for TReal32 |
|
16 |
// Also note that these tests do not generally include testing of special values. This is done |
|
17 |
// in T_R96 tests and conversions are tested thoroughly, so explicit tests are unnecessary here. |
|
18 |
// Overview: |
|
19 |
// Test functionality of operations on 32bit real numbers. |
|
20 |
// API Information: |
|
21 |
// TReal32. |
|
22 |
// Details: |
|
23 |
// - Test the conversion from TReal to TReal32 is as expected. |
|
24 |
// - Check addition, subtraction and multiplication of 32-bit floating point |
|
25 |
// numbers are as expected. |
|
26 |
// - Check division of 32-bit floating-point numbers and verify that it is |
|
27 |
// panicked when divided by zero. |
|
28 |
// - Test arithmetic exceptions are raised for |
|
29 |
// - overflow error during addition, subtraction. |
|
30 |
// - overflow, underflow errors during multiplication. |
|
31 |
// - overflow, underflow, divided by zero errors during division. |
|
32 |
// - overflow, underflow, invalid operation errors during conversion |
|
33 |
// from double to float. |
|
34 |
// - Check unary operator, equalities and inequalities operators, pre/post |
|
35 |
// increment, decrement operators with TReal32 are as expected. |
|
36 |
// Platforms/Drives/Compatibility: |
|
37 |
// All |
|
38 |
// Assumptions/Requirement/Pre-requisites: |
|
39 |
// Failures and causes: |
|
40 |
// Base Port information: |
|
41 |
// |
|
42 |
// |
|
43 |
||
44 |
#include "t_math.h" |
|
45 |
#include "t_real32.h" |
|
46 |
||
47 |
#if defined(__VC32__) |
|
48 |
// Some symbols generated by the VC++ compiler for floating point stuff. |
|
49 |
extern "C" { |
|
50 |
GLDEF_D TInt _adj_fdiv_m32; |
|
51 |
} |
|
52 |
#endif |
|
53 |
||
54 |
// Data for tests from T_R32DTA.cpp |
|
55 |
GLREF_D TReal32 addInput[]; |
|
56 |
GLREF_D TReal32 subInput[]; |
|
57 |
GLREF_D TReal32 multInput[]; |
|
58 |
GLREF_D TReal32 divInput[]; |
|
59 |
GLREF_D TReal32 unaryInput[]; |
|
60 |
GLREF_D TReal32 incDecInput[]; |
|
61 |
GLREF_D TInt sizeAdd; |
|
62 |
GLREF_D TInt sizeSub; |
|
63 |
GLREF_D TInt sizeMult; |
|
64 |
GLREF_D TInt sizeDiv; |
|
65 |
GLREF_D TInt sizeUnary; |
|
66 |
GLREF_D TInt sizeIncDec; |
|
67 |
||
68 |
#if defined (__WINS__) || defined (__X86__) |
|
69 |
// Functions from EMGCC32.CPP |
|
70 |
GLREF_C TReal32 __addsf3(TReal32 a1,TReal32 a2); |
|
71 |
GLREF_C TReal32 __subsf3(TReal32 a1,TReal32 a2); |
|
72 |
GLREF_C TReal32 __mulsf3(TReal32 a1,TReal32 a2); |
|
73 |
GLREF_C TReal32 __divsf3(TReal32 a1,TReal32 a2); |
|
74 |
GLREF_C TReal32 __truncdfsf2(TReal64 a1); |
|
43
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
75 |
GLDEF_D const TReal32 minDenormalTReal32=1.4E-45f; |
0 | 76 |
#endif |
77 |
||
78 |
GLDEF_D TReal32 NaNTReal32; |
|
79 |
GLDEF_D TReal32 posInfTReal32; |
|
80 |
GLDEF_D TReal32 negInfTReal32; |
|
81 |
GLDEF_D TReal NaNTReal; |
|
82 |
GLDEF_D TReal posInfTReal; |
|
83 |
GLDEF_D TReal negInfTReal; |
|
84 |
||
85 |
enum TOrder |
|
86 |
{ |
|
87 |
ELessThan, |
|
88 |
EEqual, |
|
89 |
EGreaterThan |
|
90 |
}; |
|
91 |
||
92 |
LOCAL_D RTest test(_L("T_R32")); |
|
93 |
||
94 |
LOCAL_C void initSpecialValues() |
|
95 |
// |
|
96 |
// Initialise special values |
|
97 |
// |
|
98 |
{ |
|
99 |
||
100 |
SReal32 *p32=(SReal32*)&NaNTReal32; |
|
101 |
p32->sign=0; |
|
102 |
p32->exp=KTReal32SpecialExponent; |
|
103 |
p32->man=0x7fffff; |
|
104 |
||
105 |
p32=(SReal32*)&posInfTReal32; |
|
106 |
p32->sign=0; |
|
107 |
p32->exp=KTReal32SpecialExponent; |
|
108 |
p32->man=0; |
|
109 |
||
110 |
p32=(SReal32*)&negInfTReal32; |
|
111 |
p32->sign=1; |
|
112 |
p32->exp=KTReal32SpecialExponent; |
|
113 |
p32->man=0; |
|
114 |
||
115 |
SReal64 *p64=(SReal64*)&NaNTReal; |
|
116 |
p64->sign=0; |
|
117 |
p64->exp=KTReal64SpecialExponent; |
|
118 |
p64->lsm=0xffffffffu; |
|
119 |
p64->msm=0xfffff; |
|
120 |
||
121 |
p64=(SReal64*)&posInfTReal; |
|
122 |
p64->sign=0; |
|
123 |
p64->exp=KTReal64SpecialExponent; |
|
124 |
p64->lsm=0; |
|
125 |
p64->msm=0; |
|
126 |
||
127 |
p64=(SReal64*)&negInfTReal; |
|
128 |
p64->sign=1; |
|
129 |
p64->exp=KTReal64SpecialExponent; |
|
130 |
p64->lsm=0; |
|
131 |
p64->msm=0; |
|
132 |
} |
|
133 |
||
134 |
LOCAL_C void testConvert() |
|
135 |
// |
|
136 |
// Conversion tests |
|
137 |
// |
|
138 |
{ |
|
139 |
||
140 |
TRealX f; |
|
141 |
||
142 |
TReal input[]= |
|
143 |
{ |
|
144 |
KMaxTReal32inTReal,KMinTReal32inTReal,-KMaxTReal32inTReal,-KMinTReal32inTReal, |
|
145 |
KMaxTReal32inTReal,KMinTReal32inTReal,-KMaxTReal32inTReal,-KMinTReal32inTReal, |
|
146 |
3.4027E+38,1.1755E-38,-3.4027E+38,-1.1755E-38, |
|
147 |
0.0,64.5,-64.5,1.54E+18,-1.54E+18,4.72E-22,-4.72E-22, |
|
148 |
posInfTReal,negInfTReal,KNegZeroTReal, |
|
149 |
1.4E-45,-1.4E-45,2E-41,-2E-41,1E-38,-1E-38 |
|
150 |
}; |
|
151 |
||
152 |
TReal32 expect[]= |
|
153 |
{ |
|
154 |
KMaxTReal32,KMinTReal32,-KMaxTReal32,-KMinTReal32, |
|
155 |
KMaxTReal32,KMinTReal32,-KMaxTReal32,-KMinTReal32, |
|
156 |
3.4027E+38f,1.17550E-38f,-3.40270E+38f,-1.17550E-38f, |
|
157 |
0.0f,64.5f,-64.5f,1.54E+18f,-1.54E+18f,4.72E-22f,-4.72E-22f, |
|
158 |
posInfTReal32,negInfTReal32,KNegZeroTReal32, |
|
159 |
1.4E-45f,-1.4E-45f,2E-41f,-2E-41f,1E-38f,-1E-38f |
|
160 |
}; |
|
161 |
||
162 |
TInt size=sizeof(input)/sizeof(TReal); |
|
163 |
||
164 |
for (TInt ii=0; ii<size; ii++) |
|
165 |
{ |
|
166 |
f=TRealX(expect[ii]); |
|
167 |
test(f==TRealX(TReal32(input[ii]))); |
|
168 |
} |
|
169 |
||
170 |
// NaN |
|
171 |
// TReal a=NaNTReal; |
|
172 |
TReal32 b=NaNTReal32; |
|
173 |
f=TRealX(b); |
|
174 |
// test(f!=TRealX(TReal32(a))); |
|
175 |
test(f.IsNaN()); |
|
176 |
||
177 |
// See EON Software Defects Bug Report no. HA-287 |
|
178 |
// There is a bug in MSDev compiler which means comparing TReal32's directly |
|
179 |
// does not always work, hence... |
|
180 |
/* |
|
181 |
test(BitTest(TReal32(3.40270E+38),3.40270E+38f)); // this works |
|
182 |
// (BitTest() checks for all 32 bits being identical |
|
183 |
||
184 |
TReal32 a=TReal32(3.40270E+38); |
|
185 |
TReal32 b=3.40270E+38f; |
|
186 |
TReal64 c=3.40270E+38; |
|
187 |
TReal32 d=TReal32(c); |
|
188 |
||
189 |
test(a==b); // this works |
|
190 |
test(d==b); // this works |
|
191 |
test(TRealX(TReal32(c))==TRealX(b)); // this works |
|
192 |
test(TReal64(TReal32(c))==TReal64(b)); // this panics |
|
193 |
test(TReal32(c)==b); // this panics |
|
194 |
test(TReal32(3.40270E+38)==3.40270E+38f); // this panics |
|
195 |
||
196 |
// As expected, all these work fine under ARM. |
|
197 |
*/ |
|
198 |
} |
|
199 |
||
200 |
LOCAL_C void testAdd() |
|
201 |
// |
|
202 |
// Addition tests |
|
203 |
// |
|
204 |
{ |
|
205 |
TReal32 f,g,h; |
|
206 |
TRealX ff,gg,hh; |
|
207 |
||
208 |
for (TInt ii=0; ii<sizeAdd-1; ii++) |
|
209 |
{ |
|
210 |
f=addInput[ii]; |
|
211 |
g=addInput[ii+1]; |
|
212 |
ff=TRealX(f); |
|
213 |
gg=TRealX(g); |
|
214 |
// Test commute |
|
215 |
test(f+g == g+f); |
|
216 |
// Test PC real addition using fp-hardware same as TRealX addition |
|
217 |
test(TRealX(f+g)==TRealX(TReal32(ff+gg))); |
|
218 |
test(TRealX(g+f)==TRealX(TReal32(ff+gg))); |
|
219 |
// Test hex-encoded constants for TReal32s generated on PC using fp-hardware same as |
|
220 |
// TRealX addition |
|
221 |
test(TRealX(*(TReal32*)&addArray[ii])==TRealX(f+g)); |
|
222 |
test(TRealX(*(TReal32*)&addArray[ii])==TRealX(g+f)); |
|
223 |
// similarly to tests above ... |
|
224 |
h=g; |
|
225 |
hh=gg; |
|
226 |
hh+=ff; |
|
227 |
test(TRealX(h+=f)==TRealX(TReal32(hh))); |
|
228 |
test(TRealX(h)==TRealX(TReal32(hh))); |
|
229 |
test(TRealX(*(TReal32*)&addArray[ii])==TRealX(h)); |
|
230 |
// |
|
231 |
h=f; |
|
232 |
hh=ff; |
|
233 |
hh+=gg; |
|
234 |
test(TRealX(h+=g)==TRealX(TReal32(hh))); |
|
235 |
test(h==TReal32(hh)); |
|
236 |
test(TRealX(*(TReal32*)&addArray[ii])==TRealX(h)); |
|
237 |
} |
|
238 |
} |
|
239 |
||
240 |
LOCAL_C void testSubt() |
|
241 |
// |
|
242 |
// Subtraction tests |
|
243 |
// |
|
244 |
{ |
|
245 |
TReal32 f,g,h; |
|
246 |
TRealX ff,gg,hh; |
|
247 |
||
248 |
for (TInt ii=0; ii<sizeSub-1; ii++) |
|
249 |
{ |
|
250 |
f=subInput[ii]; |
|
251 |
g=subInput[ii+1]; |
|
252 |
ff=TRealX(f); |
|
253 |
gg=TRealX(g); |
|
254 |
// |
|
255 |
||
256 |
// This test fails on GCC (with -O1 switch). The reason is that |
|
257 |
// comparing two intermediate floats is unpredictable. |
|
258 |
// See http://www.parashift.com/c++-faq-lite/newbie.html#faq-29.18 |
|
259 |
#ifndef __GCC32__ |
|
260 |
test(f-g == -(g-f)); |
|
261 |
#endif |
|
262 |
// |
|
263 |
test(TRealX(f-g)==TRealX(TReal32(ff-gg))); |
|
264 |
test(TRealX(g-f)==TRealX(TReal32(gg-ff))); |
|
265 |
test(TRealX(*(TReal32*)&subArray[ii])==TRealX(f-g)); |
|
266 |
test(TRealX(*(TReal32*)&subArray[ii])==TRealX(-(g-f))); |
|
267 |
// |
|
268 |
h=g; |
|
269 |
hh=gg; |
|
270 |
hh-=ff; |
|
271 |
test(TRealX(h-=f)==TRealX(TReal32(hh))); |
|
272 |
test(TRealX(h)==TRealX(TReal32(hh))); |
|
273 |
test(TRealX(*(TReal32*)&subArray[ii])==TRealX(-h)); |
|
274 |
// |
|
275 |
h=f; |
|
276 |
hh=ff; |
|
277 |
hh-=gg; |
|
278 |
test(TRealX(h-=g)==TRealX(TReal32(hh))); |
|
279 |
test(TRealX(h)==TRealX(TReal32(hh))); |
|
280 |
test(TRealX(*(TReal32*)&subArray[ii])==TRealX(h)); |
|
281 |
} |
|
282 |
} |
|
283 |
||
284 |
LOCAL_C void testMult() |
|
285 |
// |
|
286 |
// Multiplication test |
|
287 |
// |
|
288 |
{ |
|
289 |
TReal32 f,g,h; |
|
290 |
TRealX ff,gg,hh; |
|
291 |
||
292 |
for (TInt ii=0; ii<sizeMult-1; ii++) |
|
293 |
{ |
|
294 |
f=multInput[ii]; |
|
295 |
g=multInput[ii+1]; |
|
296 |
ff=TRealX(f); |
|
297 |
gg=TRealX(g); |
|
298 |
// |
|
299 |
test(f*g == g*f); |
|
300 |
// |
|
301 |
test(TRealX(f*g)==TRealX(TReal32(ff*gg))); |
|
302 |
test(TRealX(g*f)==TRealX(TReal32(gg*ff))); |
|
303 |
test(TRealX(*(TReal32*)&multArray[ii])==TRealX(f*g)); |
|
304 |
test(TRealX(*(TReal32*)&multArray[ii])==TRealX(g*f)); |
|
305 |
// |
|
306 |
h=f; |
|
307 |
hh=ff; |
|
308 |
hh*=gg; |
|
309 |
test(TRealX(h*=g)==TRealX(TReal32(hh))); |
|
310 |
test(TRealX(h)==TRealX(TReal32(hh))); |
|
311 |
test(TRealX(*(TReal32*)&multArray[ii])==TRealX(h)); |
|
312 |
// |
|
313 |
h=g; |
|
314 |
hh=gg; |
|
315 |
hh*=ff; |
|
316 |
test(TRealX(h*=f)==TRealX(TReal32(hh))); |
|
317 |
test(TRealX(h)==TRealX(TReal32(hh))); |
|
318 |
test(TRealX(*(TReal32*)&multArray[ii])==TRealX(h)); |
|
319 |
} |
|
320 |
} |
|
321 |
||
322 |
LOCAL_C void testDiv() |
|
323 |
// |
|
324 |
// Division test |
|
325 |
// |
|
326 |
{ |
|
327 |
TReal32 f,g,h; |
|
328 |
TRealX ff,gg,hh; |
|
329 |
TInt count=0; |
|
330 |
||
331 |
// Panic: Divide by Zero |
|
332 |
// f=1.0; |
|
333 |
// g=0.0; |
|
334 |
// f/=g; |
|
335 |
||
336 |
for (TInt ii=0; ii<sizeDiv-1; ii++) |
|
337 |
{ |
|
338 |
f=divInput[ii]; |
|
339 |
g=divInput[ii+1]; |
|
340 |
ff=TRealX(f); |
|
341 |
gg=TRealX(g); |
|
342 |
if (g!=0.0) |
|
343 |
{ |
|
344 |
test(TRealX(f/g)==TRealX(TReal32(ff/gg))); |
|
345 |
test(TRealX(*(TReal32*)&divArray[count])==TRealX(f/g)); |
|
346 |
// |
|
347 |
h=f; |
|
348 |
hh=ff; |
|
349 |
hh/=gg; |
|
350 |
test(TRealX(h/=g)==TRealX(TReal32(hh))); |
|
351 |
test(TRealX(h)==TRealX(TReal32(hh))); |
|
352 |
test(TRealX(*(TReal32*)&divArray[count])==TRealX(h)); |
|
353 |
++count; |
|
354 |
} |
|
355 |
if (f!=0.0) |
|
356 |
{ |
|
357 |
test(TRealX(g/f)==TRealX(TReal32(gg/ff))); |
|
358 |
h=g; |
|
359 |
hh=gg; |
|
360 |
hh/=ff; |
|
361 |
test(TRealX(h/=f)==TRealX(TReal32(hh))); |
|
362 |
test(h==TReal32(hh)); |
|
363 |
} |
|
364 |
}; |
|
365 |
||
366 |
//Additional test |
|
367 |
f=3.9999f; |
|
368 |
g=KMinTReal32; |
|
369 |
ff=TRealX(f); |
|
370 |
gg=TRealX(g); |
|
371 |
test(TRealX(f/g)==TRealX(TReal32(ff/gg))); |
|
372 |
h=f; |
|
373 |
hh=ff; |
|
374 |
hh/=gg; |
|
375 |
test(TRealX(h/=g)==TRealX(TReal32(hh))); |
|
376 |
test(TRealX(h)==TRealX(TReal32(hh))); |
|
377 |
} |
|
378 |
||
379 |
#if defined (__WINS__) || defined (__X86__) |
|
380 |
||
381 |
LOCAL_C void testArithmeticExceptionRaising() |
|
382 |
// |
|
383 |
// Test that UP_GCC.CPP raise exceptions correctly by calling functions from EMGCC32.CPP which |
|
384 |
// are copies of those in UP_GCC.CPP. To be used in debugger only. |
|
385 |
// Added by AnnW, December 1996 |
|
386 |
// |
|
387 |
{ |
|
388 |
TReal32 f,g,h; |
|
389 |
||
390 |
// Addition - possible errors are overflow, argument or none |
|
391 |
// NB no underflow |
|
392 |
||
393 |
f=NaNTReal32; |
|
394 |
h=__addsf3(f,f); // argument |
|
395 |
||
396 |
f=KMaxTReal32; |
|
397 |
h=__addsf3(f,f); // overflow |
|
398 |
||
399 |
f=1.0f; |
|
400 |
g=2.0f; |
|
401 |
h=__addsf3(f,g); // none |
|
402 |
test(h==3.0f); |
|
403 |
||
404 |
// Subtraction - possible errors are overflow, argument or none |
|
405 |
// NB no underflow |
|
406 |
||
407 |
f=NaNTReal32; |
|
408 |
h=__subsf3(f,f); // argument |
|
409 |
||
410 |
f=KMaxTReal32; |
|
411 |
g=-KMaxTReal32; |
|
412 |
h=__subsf3(f,g); // overflow |
|
413 |
||
414 |
f=1.0f; |
|
415 |
g=2.0f; |
|
416 |
h=__subsf3(f,g); // none |
|
417 |
test(h==-1.0f); |
|
418 |
||
419 |
// Multiplication - possible errors are argument, overflow, underflow or none |
|
420 |
||
421 |
f=NaNTReal32; |
|
422 |
h=__mulsf3(f,f); // argument |
|
423 |
||
424 |
f=KMaxTReal32; |
|
425 |
g=2.0f; |
|
426 |
h=__mulsf3(f,g); // overflow |
|
427 |
||
428 |
f=minDenormalTReal32; |
|
429 |
g=0.1f; |
|
430 |
h=__mulsf3(f,g); // underflow |
|
431 |
||
432 |
f=1.0f; |
|
433 |
g=2.0f; |
|
434 |
h=__mulsf3(f,g); // none |
|
435 |
test(h==2.0f); |
|
436 |
||
437 |
// Division - possible errors are overflow, underflow, divide by zero, argument or none |
|
438 |
||
439 |
f=KMaxTReal32; |
|
440 |
g=0.5f; |
|
441 |
h=__divsf3(f,g); // overflow |
|
442 |
||
443 |
f=minDenormalTReal32; |
|
444 |
g=10.0f; |
|
445 |
h=__divsf3(f,g); // underflow |
|
446 |
||
447 |
f=4.0f; |
|
448 |
g=0.0f; |
|
449 |
h=__divsf3(f,g); // divide by zero |
|
450 |
||
451 |
f=0.0f; |
|
452 |
g=0.0f; |
|
453 |
h=__divsf3(f,g); // argument |
|
454 |
||
455 |
f=1.0f; |
|
456 |
g=2.0f; |
|
457 |
h=__divsf3(f,g); // none |
|
458 |
test(h==0.5f); |
|
459 |
||
460 |
// Converting double to float - possible errors are overflow, underflow, invalid operation or none |
|
461 |
TReal64 d; |
|
462 |
||
463 |
d=1.0E+50; |
|
464 |
f=__truncdfsf2(d); // overflow |
|
465 |
||
466 |
d=1.0E-50; |
|
467 |
f=__truncdfsf2(d); // underflow |
|
468 |
||
469 |
d=KNaNTReal64; |
|
470 |
f=__truncdfsf2(d); // invalid operation |
|
471 |
||
472 |
d=4.0; |
|
473 |
f=__truncdfsf2(d); // none |
|
474 |
} |
|
475 |
||
476 |
#endif |
|
477 |
||
478 |
LOCAL_C void testUnary() |
|
479 |
// |
|
480 |
// Unary operator tests |
|
481 |
// |
|
482 |
{ |
|
483 |
TReal32 f; |
|
484 |
TRealX g; |
|
485 |
||
486 |
for (TInt ii=0; ii<sizeUnary-1; ii++) |
|
487 |
{ |
|
488 |
f=unaryInput[ii]; |
|
489 |
g=TRealX(f); |
|
490 |
test(TRealX(-f)==TRealX(TReal32(-g))); |
|
491 |
test(TRealX(-f)==TRealX(0.0f-f)); |
|
492 |
test(TRealX(+f)==TRealX(TReal32(g))); |
|
493 |
test(TRealX(+f)==TRealX(0.0f+f)); |
|
494 |
test(TRealX(*(TReal32*)&unaryArray[ii])==TRealX(-f)); |
|
495 |
} |
|
496 |
} |
|
497 |
||
498 |
LOCAL_C void testEqualities(const TReal& aA, TOrder aOrder, const TReal& aB) |
|
499 |
// |
|
500 |
// Test equality/inequality functions on aA and aB |
|
501 |
// aOrder specifies the operand's relative sizes |
|
502 |
// |
|
503 |
{ |
|
504 |
||
505 |
// Tautologies |
|
506 |
test((aA>aA) ==FALSE); |
|
507 |
test((aA<aA) ==FALSE); |
|
508 |
test((aA>=aA)==TRUE); |
|
509 |
test((aA<=aA)==TRUE); |
|
510 |
test((aA==aA)==TRUE); |
|
511 |
test((aA!=aA)==FALSE); |
|
512 |
if (aOrder!=EEqual) |
|
513 |
{ |
|
514 |
test((aA==aB)==FALSE); |
|
515 |
test((aA!=aB)==TRUE); |
|
516 |
} |
|
517 |
if (aOrder==ELessThan) |
|
518 |
{ |
|
519 |
test((aA<aB) ==TRUE); |
|
520 |
test((aA<=aB)==TRUE); |
|
521 |
test((aA>aB) ==FALSE); |
|
522 |
test((aA>=aB)==FALSE); |
|
523 |
} |
|
524 |
if (aOrder==EEqual) |
|
525 |
{ |
|
526 |
test((aA==aB)==TRUE); |
|
527 |
test((aA!=aB)==FALSE); |
|
528 |
test((aA>=aB)==TRUE); |
|
529 |
test((aA<=aB)==TRUE); |
|
530 |
test((aA>aB)==FALSE); |
|
531 |
test((aA<aB)==FALSE); |
|
532 |
} |
|
533 |
if (aOrder==EGreaterThan) |
|
534 |
{ |
|
535 |
test((aA>aB) ==TRUE); |
|
536 |
test((aA>=aB)==TRUE); |
|
537 |
test((aA<aB) ==FALSE); |
|
538 |
test((aA<=aB)==FALSE); |
|
539 |
} |
|
540 |
} |
|
541 |
||
542 |
LOCAL_C void testEqualities() |
|
543 |
// |
|
544 |
// Test >, <, >=, <=, ==, != |
|
545 |
// |
|
546 |
{ |
|
547 |
TInt i, size; |
|
548 |
TReal32 lessThanMax = KMaxTReal32-TReal32(1.0E+32); |
|
549 |
TReal32 greaterThanMin = 1.17550E-38f; |
|
550 |
TReal32 zero(0.0f); |
|
551 |
||
552 |
TReal32 positive[] = |
|
553 |
{KMinTReal32,5.3824705E-26f,1.0f,2387501.0f,5.3824705E+28f,KMaxTReal32}; |
|
554 |
||
555 |
TReal32 large[] = |
|
556 |
{2.0f,KMaxTReal32,-lessThanMax,greaterThanMin,-KMinTReal32,10.4058482f,-10.4058482f, |
|
557 |
1.2443345E+14f,1.2443345E+14f,-1.3420344E-16f,132435.97f,5.0E-6f,9.6f,-8.0f}; |
|
558 |
||
559 |
TReal32 small[] = |
|
560 |
{1.0f,lessThanMax,-KMaxTReal32,KMinTReal32,-greaterThanMin,10.4058474f,-10.4058496f, |
|
561 |
5.0E-10f,1.2443345E+10f,-5.0382470E+25f,-132435.97f,-5.1E-6f,8.0f,-9.6f}; |
|
562 |
||
563 |
TReal32 equal[] = // Same as large[] |
|
564 |
{2.0f,KMaxTReal32,-lessThanMax,greaterThanMin,-KMinTReal32,10.4058482f,-10.4058482f, |
|
565 |
1.2443345E+14f,1.2443345E+14f,-1.3420344E-16f,132435.97f,5.0E-6f,9.6f,-8.0f}; |
|
566 |
||
567 |
||
568 |
// Tests with zero |
|
569 |
||
570 |
size = sizeof(positive)/sizeof(TReal32); |
|
571 |
||
572 |
test.Start(_L("Zero")); |
|
573 |
testEqualities(zero, EEqual, zero); |
|
574 |
for (i=0; i<size; i++) |
|
575 |
{ |
|
576 |
testEqualities(positive[i], EGreaterThan, zero); |
|
577 |
testEqualities(-positive[i], ELessThan, zero); |
|
578 |
testEqualities(zero, ELessThan, positive[i]); |
|
579 |
testEqualities(zero, EGreaterThan, -positive[i]); |
|
580 |
} |
|
581 |
||
582 |
// Test boundary and other numbers |
|
583 |
||
584 |
size = sizeof(large)/sizeof(TReal32); |
|
585 |
||
586 |
test.Next(_L("Nonzero")); |
|
587 |
for (i=0; i<size; i++) |
|
588 |
{ |
|
589 |
testEqualities(large[i], EGreaterThan, small[i]); |
|
590 |
testEqualities(small[i], ELessThan, large[i]); |
|
591 |
testEqualities(large[i], EEqual, equal[i]); |
|
592 |
} |
|
593 |
||
594 |
test.End(); |
|
595 |
} |
|
596 |
||
597 |
LOCAL_C void testIncDec() |
|
598 |
// |
|
599 |
// Test Pre/Post - increment/decrement |
|
600 |
// |
|
601 |
{ |
|
602 |
||
603 |
TInt ii; |
|
604 |
TReal32 f; |
|
605 |
TRealX g; |
|
606 |
||
607 |
test.Start(_L("Pre-increment")); |
|
608 |
||
609 |
for (ii=0; ii<sizeIncDec; ii++) |
|
610 |
{ |
|
611 |
f=incDecInput[ii]; |
|
612 |
g=TRealX(f); |
|
613 |
test(TRealX(f)==TRealX(TReal32(g))); |
|
614 |
test(TRealX(++f)==TRealX(TReal32(++g))); |
|
615 |
test(TRealX(*(TReal32*)&preIncArray1[ii])==TRealX(f)); |
|
616 |
test(TRealX(f)==TRealX(TReal32(g))); |
|
617 |
test(TRealX(++f)==TRealX(TReal32(++g))); |
|
618 |
test(TRealX(*(TReal32*)&preIncArray2[ii])==TRealX(f)); |
|
619 |
test(TRealX(f)==TRealX(TReal32(g))); |
|
620 |
} |
|
621 |
||
622 |
test.Next(_L("Post-increment")); |
|
623 |
||
624 |
for (ii=0; ii<sizeIncDec; ii++) |
|
625 |
{ |
|
626 |
f=incDecInput[ii]; |
|
627 |
g=TRealX(f); |
|
628 |
test(TRealX(f)==TRealX(TReal32(g))); |
|
629 |
test(TRealX(f++)==TRealX(TReal32(g++))); |
|
630 |
test(TRealX(*(TReal32*)&postIncArray1[ii])==TRealX(f)); |
|
631 |
test(TRealX(f)==TRealX(TReal32(g))); |
|
632 |
test(TRealX(f++)==TRealX(TReal32(g++))); |
|
633 |
test(TRealX(*(TReal32*)&postIncArray2[ii])==TRealX(f)); |
|
634 |
test(TRealX(f)==TRealX(TReal32(g))); |
|
635 |
} |
|
636 |
||
637 |
test.Next(_L("Pre-decrement")); |
|
638 |
||
639 |
for (ii=0; ii<sizeIncDec; ii++) |
|
640 |
{ |
|
641 |
f=incDecInput[ii]; |
|
642 |
g=TRealX(f); |
|
643 |
test(TRealX(f)==TRealX(TReal32(g))); |
|
644 |
test(TRealX(--f)==TRealX(TReal32(--g))); |
|
645 |
test(TRealX(*(TReal32*)&preDecArray1[ii])==TRealX(f)); |
|
646 |
test(TRealX(f)==TRealX(TReal32(g))); |
|
647 |
test(TRealX(--f)==TRealX(TReal32(--g))); |
|
648 |
test(TRealX(*(TReal32*)&preDecArray2[ii])==TRealX(f)); |
|
649 |
test(TRealX(f)==TRealX(TReal32(g))); |
|
650 |
} |
|
651 |
||
652 |
test.Next(_L("Post-decrement")); |
|
653 |
||
654 |
for (ii=0; ii<sizeIncDec; ii++) |
|
655 |
{ |
|
656 |
f=incDecInput[ii]; |
|
657 |
g=TRealX(f); |
|
658 |
test(TRealX(f)==TRealX(TReal32(g))); |
|
659 |
test(TRealX(f--)==TRealX(TReal32(g--))); |
|
660 |
test(TRealX(*(TReal32*)&postDecArray1[ii])==TRealX(f)); |
|
661 |
test(TRealX(f)==TRealX(TReal32(g))); |
|
662 |
test(TRealX(f--)==TRealX(TReal32(g--))); |
|
663 |
test(TRealX(*(TReal32*)&postDecArray2[ii])==TRealX(f)); |
|
664 |
test(TRealX(f)==TRealX(TReal32(g))); |
|
665 |
} |
|
666 |
test.End(); |
|
667 |
} |
|
668 |
||
669 |
LOCAL_C void _matherr(TExcType aType) |
|
670 |
{ |
|
671 |
test.Printf(_L("_matherr: Exception type %u handled\n"),TUint(aType)); |
|
672 |
} |
|
673 |
||
674 |
GLDEF_C TInt E32Main() |
|
675 |
// |
|
676 |
// Test TReal32 |
|
677 |
// |
|
678 |
{ |
|
679 |
||
680 |
test.Title(); |
|
681 |
||
682 |
User::SetExceptionHandler(_matherr,KExceptionFpe); |
|
683 |
||
684 |
initSpecialValues(); |
|
685 |
||
686 |
test.Start(_L("Conversion from TReal to TReal32")); |
|
687 |
testConvert(); |
|
688 |
test.Next(_L("Addition")); |
|
689 |
testAdd(); |
|
690 |
test.Next(_L("Subtraction")); |
|
691 |
testSubt(); |
|
692 |
test.Next(_L("Multiplication")); |
|
693 |
testMult(); |
|
694 |
test.Next(_L("Division")); |
|
695 |
testDiv(); |
|
696 |
#if defined (__WINS__) || defined (__X86__) |
|
697 |
test.Next(_L("Arithmetic which emulates UP_GCC and raises an exception")); |
|
698 |
testArithmeticExceptionRaising(); |
|
699 |
#endif |
|
700 |
test.Next(_L("Unary Operators")); |
|
701 |
testUnary(); |
|
702 |
test.Next(_L("Equalities and Inequalities")); |
|
703 |
testEqualities(); |
|
704 |
test.Next(_L("Increment and Decrement")); |
|
705 |
testIncDec(); |
|
706 |
||
707 |
test.End(); |
|
708 |
return(KErrNone); |
|
709 |
} |
|
710 |
||
711 |