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_math.cpp
|
|
15 |
// T_MATH.CPP - Test routines for the maths functions
|
|
16 |
// NB When considering the accuracy of the results (i.e. the tolerance used in testApprox()) it
|
|
17 |
// should be remembered that the results expected are not always given to full precision and so
|
|
18 |
// the results obtained are mostly as accurate as can be expected.
|
|
19 |
// Overview:
|
|
20 |
// Test functionality of the Math library.
|
|
21 |
// API Information:
|
|
22 |
// Math.
|
|
23 |
// Details:
|
|
24 |
// - Test math's trigonometric, powers, roots, logs, modulo, sqrt, exp,
|
|
25 |
// Int, Frac, rounding for range of input values are as expected.
|
|
26 |
// - Test the returned error values are as expected when illegal math's
|
|
27 |
// operations are done.
|
|
28 |
// - Check the return value is KErrTotalLossOfPrecision when incorrect values
|
|
29 |
// is passed to modulo function.
|
|
30 |
// - Test for success when the same variable for both operands in some
|
|
31 |
// Math functions are used.
|
|
32 |
// Platforms/Drives/Compatibility:
|
|
33 |
// All.
|
|
34 |
// Assumptions/Requirement/Pre-requisites:
|
|
35 |
// Failures and causes:
|
|
36 |
// Base Port information:
|
|
37 |
//
|
|
38 |
//
|
|
39 |
|
|
40 |
#include "t_math.h"
|
|
41 |
#include "t_vals.h"
|
|
42 |
|
|
43 |
LOCAL_D RTest test(_L("T_MATH"));
|
|
44 |
|
|
45 |
LOCAL_D TInt64 rseed = MAKE_TINT64(123456789,987654321);
|
|
46 |
|
|
47 |
typedef struct
|
|
48 |
{
|
|
49 |
TReal num; // input number
|
|
50 |
TReal res; // expected result
|
|
51 |
} SQRT_TEST;
|
|
52 |
|
|
53 |
LOCAL_D SQRT_TEST testsqrt[]=
|
|
54 |
{
|
|
55 |
{0.0,0.0}, // zero
|
|
56 |
{KNegZeroTReal64,KNegZeroTReal64},
|
|
57 |
{1.0,1.0},
|
|
58 |
{.64,.8},
|
|
59 |
{.81,.9},
|
|
60 |
{9,3},
|
|
61 |
{25,5},
|
|
62 |
{10000,100},
|
|
63 |
{400,20},
|
|
64 |
{6.25,2.5},
|
|
65 |
{1E-98,1E-49},
|
|
66 |
{1E-98,1E-49},
|
|
67 |
{1E98,1E49},
|
|
68 |
{1.0000000001,1.00000000005}
|
|
69 |
};
|
|
70 |
|
|
71 |
typedef struct
|
|
72 |
{
|
|
73 |
TReal num; // input number
|
|
74 |
TReal res; // expected result
|
|
75 |
} TESTLN;
|
|
76 |
|
|
77 |
LOCAL_D TESTLN testln[]=
|
|
78 |
{
|
|
79 |
{.001,-6.9077552789821317},
|
|
80 |
{.002,-6.2146080984221917},
|
|
81 |
{.023,-3.7722610630529874},
|
|
82 |
{.004,-5.5214609178622464},
|
|
83 |
{.050,-2.9957322735539910},
|
|
84 |
{.100,-2.3025850929940457},
|
|
85 |
{.150,-1.8971199848858813},
|
|
86 |
{.200,-1.6094379124341004},
|
|
87 |
{.250,-1.3862943611198906},
|
|
88 |
{.300,-1.2039728043259360},
|
|
89 |
{.350,-1.0498221244986777},
|
|
90 |
{.400,-0.9162907318741551},
|
|
91 |
{.450,-0.7985076962177716},
|
|
92 |
{.500,-0.6931471805599453},
|
|
93 |
{.550,-0.5978370007556204},
|
|
94 |
{.600,-0.5108256237659907},
|
|
95 |
{.650,-0.4307829160924543},
|
|
96 |
{.700,-0.3566749439387324},
|
|
97 |
{.750,-0.2876820724517809},
|
|
98 |
{.980,-0.0202027073175194},
|
|
99 |
{.985,-0.0151136378100482},
|
|
100 |
{.990,-0.0100503358535014},
|
|
101 |
{.995,-0.0050125418235443},
|
|
102 |
{.088,-2.4304184645039306},
|
|
103 |
{1,0}
|
|
104 |
};
|
|
105 |
|
|
106 |
typedef struct
|
|
107 |
{
|
|
108 |
TReal val; // value for which the exponent is to be found
|
|
109 |
TReal result; // result
|
|
110 |
} EXP;
|
|
111 |
|
|
112 |
LOCAL_D EXP testexp[]=
|
|
113 |
{
|
|
114 |
{4E-20,1.0},
|
|
115 |
{5.4E-20,1.0},
|
|
116 |
{0.0,1.0},
|
|
117 |
{5E-324,1.0},
|
|
118 |
};
|
|
119 |
|
|
120 |
typedef struct
|
|
121 |
{
|
|
122 |
TReal number; // number to be raised to a power
|
|
123 |
TReal power; // power
|
|
124 |
TReal result; // result
|
|
125 |
} POWER;
|
|
126 |
|
|
127 |
LOCAL_D POWER testpow[]=
|
|
128 |
{
|
|
129 |
{45,3,91125.0},
|
|
130 |
{-2,4,16},
|
|
131 |
{2,-3,0.125},
|
|
132 |
{-2,3,-8},
|
|
133 |
{16,20,1.208925819614628E+24},
|
|
134 |
};
|
|
135 |
|
|
136 |
// Added by AnnW, October 1996
|
|
137 |
LOCAL_D const POWER testpowexact[]=
|
|
138 |
{
|
|
139 |
{0.0,1.0,0.0},
|
|
140 |
{0,7,0},
|
|
141 |
{0.0,16.0,0.0},
|
|
142 |
{0.0,3.9271E-17,0.0},
|
|
143 |
{-2,0,1},
|
|
144 |
{1,0,1},
|
|
145 |
{1.545243,0,1},
|
|
146 |
{4.8,0.0,1.0},
|
|
147 |
{195.0,0.0,1.0},
|
|
148 |
{1.0E-7,0.0,1.0},
|
|
149 |
{1.0,2.0,1.0},
|
|
150 |
{1.0,1.0E-6,1.0},
|
|
151 |
{1.0,1.0E+10,1.0},
|
|
152 |
{-1.0,2.0,1.0},
|
|
153 |
{-1.0,1.0000000001E+10,-1.0},
|
|
154 |
{-1.0,1.0E+10,1.0},
|
|
155 |
{1.593704102953967e+3,1.0,1.593704102953967e+3},
|
|
156 |
{1.234567E+50,1.0,1.234567E+50},
|
|
157 |
{1.2345678901234567E+146,1.0,1.2345678901234567E+146},
|
|
158 |
{-7.6543210987654321E-53,1.0,-7.6543210987654321E-53},
|
|
159 |
{0.0,2.0,0.0},
|
|
160 |
{KNegZeroTReal64,4.0,0.0},
|
|
161 |
{KPosInfTReal64,-2.0,0.0},
|
|
162 |
{KNegInfTReal64,-2.0,0.0},
|
|
163 |
{2.0,KNegInfTReal64,0.0},
|
|
164 |
{-2.0,KNegInfTReal64,0.0},
|
|
165 |
{0.5,KPosInfTReal64,0.0},
|
|
166 |
{-0.5,KPosInfTReal64,0.0},
|
|
167 |
{KPosInfTReal64,-5.0,0.0},
|
|
168 |
{KPosInfTReal64,-6.0,0.0},
|
|
169 |
{KNegInfTReal64,KNegInfTReal64,0.0},
|
|
170 |
{KPosInfTReal64,KNegInfTReal64,0.0},
|
|
171 |
};
|
|
172 |
|
|
173 |
// Check ISO requirements on Pow()
|
|
174 |
//
|
|
175 |
typedef struct
|
|
176 |
{
|
|
177 |
TReal number; // number to be raised to a power
|
|
178 |
TReal power; // power
|
|
179 |
TInt rc; // return value from Pow()
|
|
180 |
TReal result; // numerical result
|
|
181 |
} POWERISO;
|
|
182 |
|
|
183 |
const TReal KPosZeroTReal64 = 0.0;
|
|
184 |
|
|
185 |
LOCAL_D const POWERISO testpow_iso[] =
|
|
186 |
{
|
|
187 |
// pow(+/-0, y) returns +/-INF and raises the ''divide-by-zero''
|
|
188 |
// floating-point exception for y an odd integer < 0
|
|
189 |
{ KPosZeroTReal64, -3.0, KErrOverflow, KPosInfTReal64 }, // 0
|
|
190 |
{ KNegZeroTReal64, -3.0, KErrOverflow, KNegInfTReal64 }, // 1
|
|
191 |
|
|
192 |
// pow(+/-0, y) returns +INF and raises the ''divide-by-zero''
|
|
193 |
// floating-point exception for y < 0 and not an odd integer
|
|
194 |
{ KPosZeroTReal64, -2.0, KErrOverflow, KPosInfTReal64 }, // 2
|
|
195 |
{ KNegZeroTReal64, -2.0, KErrOverflow, KPosInfTReal64 }, // 3
|
|
196 |
|
|
197 |
// pow(+/-0, y) returns +/-0 for y an odd integer > 0
|
|
198 |
{ KPosZeroTReal64, 3.0, KErrNone, KPosZeroTReal64 }, // 4
|
|
199 |
{ KNegZeroTReal64, 3.0, KErrNone, KNegZeroTReal64 }, // 5
|
|
200 |
|
|
201 |
// pow(+/-0, y) returns +0 for y > 0 and not an odd integer
|
|
202 |
{ KPosZeroTReal64, 2.0, KErrNone, KPosZeroTReal64 }, // 6
|
|
203 |
{ KNegZeroTReal64, 2.0, KErrNone, KPosZeroTReal64 }, // 7
|
|
204 |
|
|
205 |
// pow(-1, +/-INF) returns 1
|
|
206 |
{ -1.0, KPosInfTReal64, KErrNone, 1.0 }, // 8
|
|
207 |
{ -1.0, KNegInfTReal64, KErrNone, 1.0 }, // 9
|
|
208 |
|
|
209 |
// pow(+1, y) returns 1 for any y, even a NaN
|
|
210 |
{ 1.0, 1.0, KErrNone, 1.0 }, // 10
|
|
211 |
{ 1.0, 10.0, KErrNone, 1.0 }, // 11
|
|
212 |
{ 1.0, -1.0, KErrNone, 1.0 }, // 12
|
|
213 |
{ 1.0, -10.0, KErrNone, 1.0 }, // 13
|
|
214 |
{ 1.0, 0.5, KErrNone, 1.0 }, // 14
|
|
215 |
{ 1.0, -0.5, KErrNone, 1.0 }, // 15
|
|
216 |
{ 1.0, KPosInfTReal64, KErrNone, 1.0 }, // 16
|
|
217 |
{ 1.0, KNegInfTReal64, KErrNone, 1.0 }, // 17
|
|
218 |
{ 1.0, KNaNTReal64, KErrNone, 1.0 }, // 18
|
|
219 |
|
|
220 |
// pow(x, +/-0) returns 1 for any x, even a NaN
|
|
221 |
{ 1.0, KPosZeroTReal64, KErrNone, 1.0 }, // 19
|
|
222 |
{ 1.0, KNegZeroTReal64, KErrNone, 1.0 }, // 20
|
|
223 |
{ 2.0, KPosZeroTReal64, KErrNone, 1.0 }, // 21
|
|
224 |
{ 2.0, KNegZeroTReal64, KErrNone, 1.0 }, // 22
|
|
225 |
{ 0.5, KPosZeroTReal64, KErrNone, 1.0 }, // 23
|
|
226 |
{ 0.5, KNegZeroTReal64, KErrNone, 1.0 }, // 24
|
|
227 |
{ -1.0, KPosZeroTReal64, KErrNone, 1.0 }, // 25
|
|
228 |
{ -1.0, KNegZeroTReal64, KErrNone, 1.0 }, // 26
|
|
229 |
{ -2.0, KPosZeroTReal64, KErrNone, 1.0 }, // 27
|
|
230 |
{ -2.0, KNegZeroTReal64, KErrNone, 1.0 }, // 28
|
|
231 |
{ -0.5, KPosZeroTReal64, KErrNone, 1.0 }, // 29
|
|
232 |
{ -0.5, KNegZeroTReal64, KErrNone, 1.0 }, // 30
|
|
233 |
{ KPosZeroTReal64, KPosZeroTReal64, KErrNone, 1.0 }, // 31
|
|
234 |
{ KPosZeroTReal64, KNegZeroTReal64, KErrNone, 1.0 }, // 32
|
|
235 |
{ KNegZeroTReal64, KPosZeroTReal64, KErrNone, 1.0 }, // 33
|
|
236 |
{ KNegZeroTReal64, KNegZeroTReal64, KErrNone, 1.0 }, // 34
|
|
237 |
{ KPosInfTReal64, KPosZeroTReal64, KErrNone, 1.0 }, // 35
|
|
238 |
{ KPosInfTReal64, KNegZeroTReal64, KErrNone, 1.0 }, // 36
|
|
239 |
{ KNegInfTReal64, KPosZeroTReal64, KErrNone, 1.0 }, // 37
|
|
240 |
{ KNegInfTReal64, KNegZeroTReal64, KErrNone, 1.0 }, // 38
|
|
241 |
{ KNaNTReal64, KPosZeroTReal64, KErrNone, 1.0 }, // 39
|
|
242 |
{ KNaNTReal64, KNegZeroTReal64, KErrNone, 1.0 }, // 40
|
|
243 |
|
|
244 |
// pow(x, y) returns a NaN and raises the ''invalid'' floating-point
|
|
245 |
// exception for finite x < 0 and finite non-integer y
|
|
246 |
{ -1.0, 1.5, KErrArgument, KNaNTReal64 }, // 41
|
|
247 |
|
|
248 |
// pow(x, -INF) returns +INF for |x| < 1
|
|
249 |
{ 0.5, KNegInfTReal64, KErrOverflow, KPosInfTReal64 }, // 42
|
|
250 |
{ -0.5, KNegInfTReal64, KErrOverflow, KPosInfTReal64 }, // 43
|
|
251 |
|
|
252 |
// pow(x, -INF) returns +0 for |x| > 1
|
|
253 |
{ 2, KNegInfTReal64, KErrNone, KPosZeroTReal64 }, // 44
|
|
254 |
{ -2, KNegInfTReal64, KErrNone, KPosZeroTReal64 }, // 45
|
|
255 |
{ 4.5, KNegInfTReal64, KErrNone, KPosZeroTReal64 }, // 46
|
|
256 |
{ -4.5, KNegInfTReal64, KErrNone, KPosZeroTReal64 }, // 47
|
|
257 |
|
|
258 |
// pow(x, +INF) returns +0 for |x| < 1
|
|
259 |
{ .5, KPosInfTReal64, KErrNone, KPosZeroTReal64 }, // 48
|
|
260 |
{ -.5, KPosInfTReal64, KErrNone, KPosZeroTReal64 }, // 49
|
|
261 |
|
|
262 |
// pow(x, +INF) returns +INF for |x| > 1
|
|
263 |
{ 2, KPosInfTReal64, KErrOverflow, KPosInfTReal64 }, // 50
|
|
264 |
{ -2, KPosInfTReal64, KErrOverflow, KPosInfTReal64 }, // 51
|
|
265 |
{ 4.5, KPosInfTReal64, KErrOverflow, KPosInfTReal64 }, // 52
|
|
266 |
{ -4.5, KPosInfTReal64, KErrOverflow, KPosInfTReal64 }, // 53
|
|
267 |
|
|
268 |
// pow(-INF, y) returns -0 for y an odd integer < 0
|
|
269 |
{ KNegInfTReal64, -1, KErrNone, KNegZeroTReal64 }, // 54
|
|
270 |
{ KNegInfTReal64, -5, KErrNone, KNegZeroTReal64 }, // 55
|
|
271 |
|
|
272 |
// pow(-INF, y) returns +0 for y < 0 and not an odd integer
|
|
273 |
{ KNegInfTReal64, -2, KErrNone, KPosZeroTReal64 }, // 56
|
|
274 |
{ KNegInfTReal64, -5.5, KErrNone, KPosZeroTReal64 }, // 57
|
|
275 |
|
|
276 |
// pow(-INF, y) returns -INF for y an odd integer > 0
|
|
277 |
{ KNegInfTReal64, 1, KErrOverflow, KNegInfTReal64 }, // 58
|
|
278 |
{ KNegInfTReal64, 5, KErrOverflow, KNegInfTReal64 }, // 59
|
|
279 |
|
|
280 |
// pow(-INF, y) returns +INF for y > 0 and not an odd integer
|
|
281 |
{ KNegInfTReal64, 2, KErrOverflow, KPosInfTReal64 }, // 60
|
|
282 |
{ KNegInfTReal64, 5.5, KErrOverflow, KPosInfTReal64 }, // 61
|
|
283 |
|
|
284 |
// pow(+INF, y) returns +0 for y < 0
|
|
285 |
{ KPosInfTReal64, -1, KErrNone, KPosZeroTReal64 }, // 62
|
|
286 |
{ KPosInfTReal64, -2, KErrNone, KPosZeroTReal64 }, // 63
|
|
287 |
{ KPosInfTReal64, -5, KErrNone, KPosZeroTReal64 }, // 64
|
|
288 |
{ KPosInfTReal64, -5.5, KErrNone, KPosZeroTReal64 }, // 65
|
|
289 |
|
|
290 |
// pow(+INF, y) returns +INF for y > 0
|
|
291 |
{ KPosInfTReal64, 1, KErrOverflow, KPosInfTReal64 }, // 66
|
|
292 |
{ KPosInfTReal64, 2, KErrOverflow, KPosInfTReal64 }, // 67
|
|
293 |
{ KPosInfTReal64, 5, KErrOverflow, KPosInfTReal64 }, // 68
|
|
294 |
{ KPosInfTReal64, 5.5, KErrOverflow, KPosInfTReal64 }, // 69
|
|
295 |
};
|
|
296 |
|
|
297 |
struct POW10_TEST
|
|
298 |
{
|
|
299 |
TInt num; // input number
|
|
300 |
TReal res; // expected result
|
|
301 |
};
|
|
302 |
|
|
303 |
LOCAL_D POW10_TEST pow10teste[]=
|
|
304 |
{
|
|
305 |
{300,1.0E300},
|
|
306 |
{-162,1.0E-162},
|
|
307 |
{-300,1.0E-300},
|
|
308 |
{-99,1.0E-99},
|
|
309 |
// };
|
|
310 |
|
|
311 |
//LOCAL_D POW10_TEST pow10testa[]=
|
|
312 |
// {
|
|
313 |
{99,1.0E99},
|
|
314 |
{283,1.0E283},
|
|
315 |
{-89,1.0E-89},
|
|
316 |
{-200,1.0E-200},
|
|
317 |
{-43,1.0E-43},
|
|
318 |
{24,1.0E24},
|
|
319 |
{-310,K1EMinus310Real64},
|
|
320 |
{-323,K1EMinus323Real64}
|
|
321 |
};
|
|
322 |
|
|
323 |
typedef struct
|
|
324 |
{
|
|
325 |
TReal num; // input number
|
|
326 |
TReal res; // expected result
|
|
327 |
} TESTSINE;
|
|
328 |
|
|
329 |
#pragma warning ( disable : 4204 ) // non-constant aggregate initializer
|
|
330 |
LOCAL_D TESTSINE testsin[]=
|
|
331 |
{
|
|
332 |
{0.5,0.4794255386042029}, // These were found using S3a
|
|
333 |
{1.2,0.9320390859672263},
|
|
334 |
{1.6,0.9995736030415051},
|
|
335 |
{28.6,-0.3199399618841981},
|
|
336 |
{-18.3,0.5223085896267315},
|
|
337 |
{KPi/4,0.7071067811865474},
|
|
338 |
{3*KPi/4,0.7071067811865474},
|
|
339 |
{5*KPi/4,-0.7071067811865474},
|
|
340 |
{-KPi/4,-0.7071067811865474},
|
|
341 |
{KPi/3,0.8660254037844387},
|
|
342 |
{-KPi/3,-0.8660254037844387},
|
|
343 |
{KPi/6,0.5},
|
|
344 |
{-KPi/6,-0.5},
|
|
345 |
{150*KDegToRad,0.5},
|
|
346 |
{210*KDegToRad,-0.5},
|
|
347 |
// {KPi+1.0E-15,-7.657143961860984E-16}, // loss of significance will limit accuracy here
|
|
348 |
// 2*(KPi+1.0E-15),1.5314287923721969e-15}
|
|
349 |
};
|
|
350 |
|
|
351 |
typedef struct
|
|
352 |
{
|
|
353 |
TReal num; // input number
|
|
354 |
TReal res; // expected result
|
|
355 |
} TESTCOSINE;
|
|
356 |
|
|
357 |
LOCAL_D TESTCOSINE testcos[]=
|
|
358 |
{
|
|
359 |
{0.5,0.8775825618903727}, // These were found using S3a
|
|
360 |
{1.2,0.3623577544766734},
|
|
361 |
{1.6,-0.0291995223012888},
|
|
362 |
{28.6,-0.9474378189567576},
|
|
363 |
{-18.3,0.8527565521308730},
|
|
364 |
{KPi/4,0.7071067811865474},
|
|
365 |
{3*KPi/4,-0.7071067811865474},
|
|
366 |
{5*KPi/4,-0.7071067811865474},
|
|
367 |
{-KPi/4,0.7071067811865474},
|
|
368 |
{KPi/6,0.8660254037844387},
|
|
369 |
{5*KPi/6,-0.8660254037844387},
|
|
370 |
{KPi/3,0.5},
|
|
371 |
{4*KPi/3,-0.5},
|
|
372 |
{120*KDegToRad,-0.5},
|
|
373 |
{300*KDegToRad,0.5},
|
|
374 |
{KPi+1.0E-15,-1.0},
|
|
375 |
{2*(KPi+1.0E-15),1.0}
|
|
376 |
};
|
|
377 |
|
|
378 |
typedef struct
|
|
379 |
{
|
|
380 |
TReal angle; // angle for which the tangent is to be found
|
|
381 |
TReal result; // result
|
|
382 |
} TAN;
|
|
383 |
|
|
384 |
LOCAL_D TAN testtan[]=
|
|
385 |
{
|
|
386 |
{KPi/4,1.0},
|
|
387 |
{-KPi/4,-1.0},
|
|
388 |
{45*KDegToRad,1.0},
|
|
389 |
{KPi/3,1.732050807568877}, // Added by AnnW - Calculated on S3a
|
|
390 |
{2*KPi/3,-1.732050807568878}, //
|
|
391 |
{KPi/6,0.5773502691896257}, //
|
|
392 |
{-KPi/6,-0.5773502691896257}, //
|
|
393 |
{89*KDegToRad,57.28996163075913}, // these two should be the same!
|
|
394 |
{91*KDegToRad,-57.28996163075955}, //
|
|
395 |
{4E-123,4E-123},
|
|
396 |
{-4E-123,-4E-123},
|
|
397 |
};
|
|
398 |
|
|
399 |
typedef struct
|
|
400 |
{
|
|
401 |
TReal num; // input number
|
|
402 |
TReal res; // expected result
|
|
403 |
} TESTASC;
|
|
404 |
|
|
405 |
LOCAL_D TESTASC testas[]=
|
|
406 |
{
|
|
407 |
{.75,.848062078981},
|
|
408 |
{.82,.961411018764},
|
|
409 |
{.87,1.055202320549},
|
|
410 |
{.89,1.097345169523},
|
|
411 |
{.90,1.119769514999},
|
|
412 |
{.92,1.168080485214},
|
|
413 |
{.94,1.222630305522},
|
|
414 |
{.96,1.287002217587},
|
|
415 |
{.99,1.429256853470},
|
|
416 |
{1.0,1.570796326795},
|
|
417 |
{0.0,0},
|
|
418 |
{-1.0, -90.0*KDegToRad},
|
|
419 |
{0.5,30.0*KDegToRad}
|
|
420 |
};
|
|
421 |
|
|
422 |
typedef struct
|
|
423 |
{
|
|
424 |
TReal num1; // Divisor
|
|
425 |
TReal num2; // Divand
|
|
426 |
TReal res; // expected result
|
|
427 |
} TESTATAN2;
|
|
428 |
|
|
429 |
LOCAL_D TESTATAN2 testat2[]=
|
|
430 |
{
|
|
431 |
{5E-49,7E306,0.0}, // underflow, zero returned
|
|
432 |
{5E49,7E-306,KPiBy2}, // overflow, pi/2 returned
|
|
433 |
{0.45,0.5,0.732815101787},
|
|
434 |
{0.12,0.3,0.380506377112},
|
|
435 |
{0.3,0.0,KPiBy2}, // overflow, pi/2 returned
|
|
436 |
{-0.3,0.0,-KPiBy2}, // overflow, -pi/2 returned
|
|
437 |
{0.0,0.3,0.0},
|
|
438 |
};
|
|
439 |
#pragma warning ( default : 4204 )
|
|
440 |
|
|
441 |
typedef struct
|
|
442 |
{
|
|
443 |
TReal num; // input number
|
|
444 |
TReal res; // expected result
|
|
445 |
} INT_TEST;
|
|
446 |
|
|
447 |
LOCAL_D INT_TEST testint1[]=
|
|
448 |
{
|
|
449 |
{1.0,1.0},
|
|
450 |
{1.47934,1.0},
|
|
451 |
{-72.86345,-72.0},
|
|
452 |
{-734.9999,-734.0},
|
|
453 |
{4855.9974,4855.0},
|
|
454 |
{232478.35,232478.0},
|
|
455 |
{0.029345,0.0},
|
|
456 |
{0.9437,0.0},
|
|
457 |
{-0.2634,0.0},
|
|
458 |
{-0.98976,0.0},
|
|
459 |
{32769.36946,32769.0},
|
|
460 |
{-32774.997937,-32774.0},
|
|
461 |
{8738465.38749,8738465.0},
|
|
462 |
{-2348645.34965,-2348645.0},
|
|
463 |
{2147483655.7565,2147483655.0},
|
|
464 |
{-2147483657.89453,-2147483657.0},
|
|
465 |
{2374843546.34E2,2374843546.34E2},
|
|
466 |
{34780656.37643E12,34780656.37643E12},
|
|
467 |
{-2374843546.34E2,-2374843546.34E2},
|
|
468 |
{-34780656.37643E12,-34780656.37643E12},
|
|
469 |
{468650.3874E47,468650.3874E47},
|
|
470 |
{-4965.5987636E34,-4965.5987636E34},
|
|
471 |
};
|
|
472 |
|
|
473 |
typedef struct
|
|
474 |
{
|
|
475 |
TReal num; // input number
|
|
476 |
TInt16 res; // expected result
|
|
477 |
} INTI_TEST;
|
|
478 |
|
|
479 |
LOCAL_D INTI_TEST testint2[]=
|
|
480 |
{
|
|
481 |
{1.0,1},
|
|
482 |
{1.47934,1},
|
|
483 |
{-72.86345,-72},
|
|
484 |
{-734.9999,-734},
|
|
485 |
{4855.9974,4855},
|
|
486 |
{0.029345,0},
|
|
487 |
{0.9437,0},
|
|
488 |
{-0.2634,0},
|
|
489 |
{-0.98976,0},
|
|
490 |
{3234.56,3234},
|
|
491 |
{4698.435,4698},
|
|
492 |
{-32767.47658,-32767},
|
|
493 |
{32767.9830857,32767},
|
|
494 |
{-32768.47658,-32767-1}
|
|
495 |
};
|
|
496 |
|
|
497 |
typedef struct
|
|
498 |
{
|
|
499 |
TReal num; // input number
|
|
500 |
TInt32 res; // expected result
|
|
501 |
} INTL_TEST;
|
|
502 |
|
|
503 |
LOCAL_D INTL_TEST testint3[]=
|
|
504 |
{
|
|
505 |
{1.0,1l},
|
|
506 |
{1.47934,1l},
|
|
507 |
{-72.86345,-72l},
|
|
508 |
{-734.9999,-734l},
|
|
509 |
{4855.9974,4855l},
|
|
510 |
{0.029345,0l},
|
|
511 |
{0.9437,0l},
|
|
512 |
{-0.2634,0l},
|
|
513 |
{-0.98976,0l},
|
|
514 |
{3234.56,3234l},
|
|
515 |
{4698.435,4698l},
|
|
516 |
{-32767.47658,-32767l},
|
|
517 |
{32767.9830857,32767l},
|
|
518 |
{32769.36946,32769l},
|
|
519 |
{-32774.997937,-32774l},
|
|
520 |
{64835903.74605,64835903l},
|
|
521 |
{-46652024.393,-46652024l},
|
|
522 |
{2147483647.34576,2147483647l},
|
|
523 |
{-2147483647.9501,-2147483647l},
|
|
524 |
{-2147483648.00,0x80000000l},
|
|
525 |
{-2147483648.6843,0x80000000l}
|
|
526 |
};
|
|
527 |
|
|
528 |
typedef struct
|
|
529 |
{
|
|
530 |
TReal num; // input number
|
|
531 |
TReal res; // expected result
|
|
532 |
} FRAC_TEST;
|
|
533 |
|
|
534 |
LOCAL_D FRAC_TEST testfrac[]=
|
|
535 |
{
|
|
536 |
{0.0,0.0},
|
|
537 |
{KNegZeroTReal64,0.0},
|
|
538 |
{1.0,0.0},
|
|
539 |
{1.47934,.47934},
|
|
540 |
{-72.86345,-.86345},
|
|
541 |
{-734.9999,-.9999},
|
|
542 |
{4855.9974,.9974},
|
|
543 |
{232478.35,.35},
|
|
544 |
{0.029345,.029345},
|
|
545 |
{0.9437,0.9437},
|
|
546 |
{-0.2634,-.2634},
|
|
547 |
{-0.98976,-.98976},
|
|
548 |
{32769.36946,.36946},
|
|
549 |
{-32774.997937,-0.997937},
|
|
550 |
{8738465.38749,0.38749},
|
|
551 |
{-2348645.34965,-0.34965},
|
|
552 |
{2147483655.7565,0.7565},
|
|
553 |
{-2147483657.89453,-.89453},
|
|
554 |
{2374843546.34E2,0.0},
|
|
555 |
{34780656.37643E12,0.0},
|
|
556 |
{-2374843546.34E2,0.0},
|
|
557 |
{-34780656.37643E12,0.0},
|
|
558 |
{468650.3874E47,0.0},
|
|
559 |
{-4965.5987636E34,0.0}
|
|
560 |
};
|
|
561 |
|
|
562 |
typedef struct
|
|
563 |
{
|
|
564 |
TReal num; // input number
|
|
565 |
TReal mod; // modulo
|
|
566 |
TReal res; // expected result
|
|
567 |
} MOD_TEST;
|
|
568 |
|
|
569 |
LOCAL_D MOD_TEST testmod[]=
|
|
570 |
{
|
|
571 |
{4.0,2.0,0.0},
|
|
572 |
{3.0,2.0,1.0},
|
|
573 |
{56.847,2.3,1.647},
|
|
574 |
{-65.6478,.65,-.6478},
|
|
575 |
{-6858.78432,-87.5323,-31.26492},
|
|
576 |
{7665.140215,-34.98,4.520215},
|
|
577 |
{.4645,1.0,0.4645},
|
|
578 |
{-.246,1.0,-.246},
|
|
579 |
{1.0,KPosInfTReal64,1.0},
|
|
580 |
{1.0,KNegInfTReal64,1.0},
|
|
581 |
{1.0E17,8.0,0.0},
|
|
582 |
//
|
|
583 |
{1.0,3.0,1.0}, //0
|
|
584 |
{2.0,3.0,2.0},
|
|
585 |
{4.0,3.0,1.0},
|
|
586 |
{8.0,3.0,2.0},
|
|
587 |
{16.0,3.0,1.0},
|
|
588 |
{32.0,3.0,2.0},
|
|
589 |
{64.0,3.0,1.0},
|
|
590 |
{128.0,3.0,2.0},
|
|
591 |
{256.0,3.0,1.0},
|
|
592 |
{512.0,3.0,2.0},
|
|
593 |
{1024.0,3.0,1.0}, //10
|
|
594 |
{2048.0,3.0,2.0},
|
|
595 |
{4096.0,3.0,1.0},
|
|
596 |
{8192.0,3.0,2.0},
|
|
597 |
{16384.0,3.0,1.0},
|
|
598 |
{32768.0,3.0,2.0},
|
|
599 |
{65536.0,3.0,1.0},
|
|
600 |
{131072.0,3.0,2.0},
|
|
601 |
{262144.0,3.0,1.0},
|
|
602 |
{524288.0,3.0,2.0},
|
|
603 |
{1048576.0,3.0,1.0}, //20
|
|
604 |
{2097152.0,3.0,2.0},
|
|
605 |
{4194304.0,3.0,1.0},
|
|
606 |
{8388608.0,3.0,2.0},
|
|
607 |
{16777216.0,3.0,1.0},
|
|
608 |
{33554432.0,3.0,2.0},
|
|
609 |
{67108864.0,3.0,1.0},
|
|
610 |
{134217728.0,3.0,2.0},
|
|
611 |
{268435456.0,3.0,1.0},
|
|
612 |
{536870912.0,3.0,2.0},
|
|
613 |
{1073741824.0,3.0,1.0}, //30
|
|
614 |
{2147483648.0,3.0,2.0},
|
|
615 |
{4294967296.0,3.0,1.0},
|
|
616 |
{8589934592.0,3.0,2.0},
|
|
617 |
{17179869184.0,3.0,1.0},
|
|
618 |
{34359738368.0,3.0,2.0},
|
|
619 |
{68719476736.0,3.0,1.0},
|
|
620 |
{137438953472.0,3.0,2.0},
|
|
621 |
{274877906944.0,3.0,1.0},
|
|
622 |
{549755813888.0,3.0,2.0},
|
|
623 |
{1099511627776.0,3.0,1.0}, //40
|
|
624 |
{2199023255552.0,3.0,2.0},
|
|
625 |
{4398046511104.0,3.0,1.0},
|
|
626 |
{8796093022208.0,3.0,2.0},
|
|
627 |
{17592186044416.0,3.0,1.0},
|
|
628 |
{35184372088832.0,3.0,2.0},
|
|
629 |
{70368744177664.0,3.0,1.0},
|
|
630 |
{140737488355328.0,3.0,2.0},
|
|
631 |
{281474976710656.0,3.0,1.0},
|
|
632 |
{562949953421312.0,3.0,2.0},
|
|
633 |
{1125899906842624.0,3.0,1.0}, //50
|
|
634 |
{2251799813685248.0,3.0,2.0},
|
|
635 |
{4503599627370496.0,3.0,1.0},
|
|
636 |
{9007199254740992.0,3.0,2.0},
|
|
637 |
{18014398509481984.0,3.0,1.0},
|
|
638 |
{6.626176E-34,299792458.0,6.626176E-34},
|
|
639 |
{-1.6022E-19,6.022045E23,-1.6022E-19},
|
|
640 |
{0.0,2.71828182845904524,0.0}
|
|
641 |
};
|
|
642 |
|
|
643 |
// expected result is unused in following - will be zero in all cases
|
|
644 |
LOCAL_D MOD_TEST testmod2[]=
|
|
645 |
{
|
|
646 |
{1.0E17,7.9,0.0},
|
|
647 |
{1.0E100,4.0,0.0},
|
|
648 |
{KMaxTReal64,5.0,0.0},
|
|
649 |
{-KMaxTReal64,5.0,0.0},
|
|
650 |
{0.125,1.0E-17,0.0},
|
|
651 |
{36028797019963968.0,2.0,0.0}, // 2**55,2**1
|
|
652 |
//
|
|
653 |
{36028797019963968.0,3.0,0.0}, //55
|
|
654 |
{72057594039927936.0,3.0,0.0},
|
|
655 |
{144115188079855872.0,3.0,0.0},
|
|
656 |
{288230376159711744.0,3.0,0.0},
|
|
657 |
};
|
|
658 |
|
|
659 |
TInt testApprox(TReal aFound,TReal aExpect,TReal aTol)
|
|
660 |
//
|
|
661 |
// Tests relative error, i.e. whether (aFound-aExpect)/aFound <= aTol
|
|
662 |
//
|
|
663 |
{
|
|
664 |
|
|
665 |
TRealX diff,check,l,r,t;
|
|
666 |
l.Set(aFound);
|
|
667 |
r.Set(aExpect);
|
|
668 |
t.Set(aTol);
|
|
669 |
if (l.Mult(check,t)==KErrUnderflow)
|
|
670 |
{
|
|
671 |
l*=TRealX(1.0E20);
|
|
672 |
r*=TRealX(1.0E20);
|
|
673 |
}
|
|
674 |
diff=l-r;
|
|
675 |
if (diff.IsZero())
|
|
676 |
return ETrue;
|
|
677 |
if (!l.IsZero())
|
|
678 |
diff.DivEq(l);
|
|
679 |
if (Abs(TReal(diff))<=aTol)
|
|
680 |
return ETrue;
|
|
681 |
return EFalse;
|
|
682 |
}
|
|
683 |
|
|
684 |
LOCAL_C void randrng(TReal& pret,TReal& llim,TReal& ulim)
|
|
685 |
/*
|
|
686 |
Returns a random number in the range [llim,ulim]
|
|
687 |
*/
|
|
688 |
{
|
|
689 |
|
|
690 |
pret=Math::FRand(rseed);
|
|
691 |
pret*=ulim-llim;
|
|
692 |
pret+=llim;
|
|
693 |
}
|
|
694 |
|
|
695 |
LOCAL_C TReal taylor(TReal x,TInt k)
|
|
696 |
/*
|
|
697 |
Evaluate the Taylor series approximation to arc sine up to terms of order k
|
|
698 |
*/
|
|
699 |
//TReal x; // argument
|
|
700 |
//TInt k; // Highest order term
|
|
701 |
{
|
|
702 |
|
|
703 |
TInt i,j;
|
|
704 |
TReal den,num,res,term,di;
|
|
705 |
|
|
706 |
den=1;
|
|
707 |
num=1;
|
|
708 |
term=0;
|
|
709 |
for (i=1;i<=k;i+=2)
|
|
710 |
{
|
|
711 |
for (j=2;j<i;j+=2)
|
|
712 |
{
|
|
713 |
num*=j;
|
|
714 |
if (j<(i-1))
|
|
715 |
den*=j+1;
|
|
716 |
}
|
|
717 |
di=(TReal)i;
|
|
718 |
Math::Pow(res,x,di);
|
|
719 |
term+=(res*den)/(i*num);
|
|
720 |
num=1;
|
|
721 |
den=1;
|
|
722 |
}
|
|
723 |
return(term);
|
|
724 |
}
|
|
725 |
|
|
726 |
LOCAL_C TReal tayatan(TReal val)
|
|
727 |
/*
|
|
728 |
Finds the taylor series approximation to the arc tangent function
|
|
729 |
*/
|
|
730 |
//TReal val;
|
|
731 |
{
|
|
732 |
|
|
733 |
TInt i;
|
|
734 |
TReal sgn,s,d,di,term,res;
|
|
735 |
|
|
736 |
term=0.0;
|
|
737 |
s=(-1.0);
|
|
738 |
for (i=0;i<8;i++)
|
|
739 |
{
|
|
740 |
di=(TReal)i;
|
|
741 |
d=2.0*di;
|
|
742 |
Math::Pow(sgn,s,di);
|
|
743 |
Math::Pow(res,val,d);
|
|
744 |
term+=(sgn*res)/(2.0*di+1.0);
|
|
745 |
}
|
|
746 |
return(val*term);
|
|
747 |
}
|
|
748 |
|
|
749 |
LOCAL_C void AssortedTests()
|
|
750 |
//
|
|
751 |
// Tests the methods with just a handful of values each
|
|
752 |
// All tests as accurate as possible - if exact answer given, tests for equality
|
|
753 |
//
|
|
754 |
{
|
|
755 |
|
|
756 |
TReal trg,src;
|
|
757 |
|
|
758 |
// ASin
|
|
759 |
test.Start(_L("Math::ASin()"));
|
|
760 |
test(Math::ASin(trg,0.0)==KErrNone);
|
|
761 |
test(trg==0.0);
|
|
762 |
|
|
763 |
test(Math::ASin(trg,1.0)==KErrNone);
|
|
764 |
test(testApprox(trg,1.5707963267949,5.0E-15));
|
|
765 |
|
|
766 |
// ACos
|
|
767 |
test.Next(_L("Math::ACos()"));
|
|
768 |
test(Math::ACos(trg,0)==KErrNone);
|
|
769 |
test(testApprox(trg,1.5707963267949,5.0E-15));
|
|
770 |
|
|
771 |
test(Math::ACos(trg,1.0)==KErrNone);
|
|
772 |
test(trg==0.0);
|
|
773 |
|
|
774 |
// ATan
|
|
775 |
test.Next(_L("Math::ATan()"));
|
|
776 |
test(Math::ATan(trg,0.0)==KErrNone);
|
|
777 |
test(trg==0.0);
|
|
778 |
|
|
779 |
test(Math::ATan(trg,1.0)==KErrNone);
|
|
780 |
test(testApprox(trg,0.78539816339745,5.0E-15));
|
|
781 |
|
|
782 |
test(Math::Tan(trg,KPi/4)==KErrNone);
|
|
783 |
test(testApprox(trg,1.0,1.0E-15));
|
|
784 |
test(Math::ATan(trg,trg)==KErrNone);
|
|
785 |
test(testApprox(trg,KPi/4,1e-15));
|
|
786 |
|
|
787 |
// Sqrt
|
|
788 |
test.Next(_L("Math::Sqrt()"));
|
|
789 |
test(Math::Sqrt(trg,0.0)==KErrNone);
|
|
790 |
test(trg==0.0);
|
|
791 |
|
|
792 |
test(Math::Sqrt(trg,-1.0)==KErrArgument);
|
|
793 |
|
|
794 |
test(Math::Sqrt(trg,100.0)==KErrNone);
|
|
795 |
test(testApprox(trg,10.0,1.0E-15));
|
|
796 |
|
|
797 |
test(Math::Sqrt(trg,56.25)==KErrNone);
|
|
798 |
test(trg==7.5);
|
|
799 |
|
|
800 |
// Pow10
|
|
801 |
test.Next(_L("Math::Pow10()"));
|
|
802 |
test(Math::Pow10(trg,-2)==KErrNone);
|
|
803 |
test(trg==0.01);
|
|
804 |
|
|
805 |
test(Math::Pow10(trg,-1)==KErrNone);
|
|
806 |
test(trg==0.1);
|
|
807 |
|
|
808 |
test(Math::Pow10(trg,0)==KErrNone);
|
|
809 |
test(trg==1.0);
|
|
810 |
|
|
811 |
test(Math::Pow10(trg,1)==KErrNone);
|
|
812 |
test(trg==10.0);
|
|
813 |
|
|
814 |
test(Math::Pow10(trg,2)==KErrNone);
|
|
815 |
test(trg==100.0);
|
|
816 |
|
|
817 |
// Ln
|
|
818 |
test.Next(_L("Math::Ln()"));
|
|
819 |
test(Math::Ln(trg,0.0)==KErrOverflow);
|
|
820 |
|
|
821 |
test(Math::Ln(trg,1.0)==KErrNone);
|
|
822 |
test(trg==0.0);
|
|
823 |
|
|
824 |
test(Math::Ln(trg,2)==KErrNone);
|
|
825 |
test(testApprox(trg,0.69314718055995,1.0E-14));
|
|
826 |
|
|
827 |
// Log
|
|
828 |
test.Next(_L("Math::Log()"));
|
|
829 |
test(Math::Log(trg,0)==KErrOverflow);
|
|
830 |
|
|
831 |
test(Math::Log(trg,1)==KErrNone);
|
|
832 |
test(trg==0);
|
|
833 |
|
|
834 |
test(Math::Log(trg,10)==KErrNone);
|
|
835 |
test(trg==1);
|
|
836 |
|
|
837 |
test(Math::Log(trg,100000)==KErrNone);
|
|
838 |
test(trg==5);
|
|
839 |
|
|
840 |
// Sin
|
|
841 |
test.Next(_L("Math::Sin()"));
|
|
842 |
test(Math::Sin(trg,0)==KErrNone);
|
|
843 |
test(trg==0);
|
|
844 |
|
|
845 |
test(Math::Sin(trg,1)==KErrNone);
|
|
846 |
test(testApprox(trg,0.84147098480790,5.0E-15));
|
|
847 |
|
|
848 |
test(Math::Sin(trg,KPi)==KErrNone);
|
|
849 |
// test(trg==0.0);
|
|
850 |
test(Abs(trg)<1e-15);
|
|
851 |
|
|
852 |
test(Math::Sin(trg,KPiBy2)==KErrNone);
|
|
853 |
test(testApprox(trg,1.0,1.0E-15));
|
|
854 |
|
|
855 |
test(Math::Sin(trg,10.0*KPi)==KErrNone);
|
|
856 |
// test(trg==0.0);
|
|
857 |
test(Abs(trg)<2e-15);
|
|
858 |
|
|
859 |
test(Math::Sin(trg,3)==KErrNone);
|
|
860 |
test(trg==0.1411200080598672);
|
|
861 |
|
|
862 |
test(Math::Sin(trg,4)==KErrNone);
|
|
863 |
test(trg==-0.7568024953079282);
|
|
864 |
|
|
865 |
test(Math::Sin(trg,3.1415)==KErrNone);
|
|
866 |
test(testApprox(trg,9.26535896605E-5,2.0E-13));
|
|
867 |
|
|
868 |
test(Math::Sin(trg,3.1416)==KErrNone);
|
|
869 |
test(testApprox(trg,-7.3464102066435914E-6,1.0E-11));
|
|
870 |
|
|
871 |
test(Math::Sin(trg,(10.0*KPi)+0.001)==KErrNone);
|
|
872 |
test(testApprox(trg,0.000999999833333,4.0E-13));
|
|
873 |
|
|
874 |
// Cos
|
|
875 |
test.Next(_L("Math::Cos()"));
|
|
876 |
test(Math::Cos(trg,0.0)==KErrNone);
|
|
877 |
test(testApprox(trg,1.0,1.0E-15));
|
|
878 |
|
|
879 |
test(Math::Cos(trg,1)==KErrNone);
|
|
880 |
test(testApprox(trg,0.54030230586814,1.0E-15));
|
|
881 |
|
|
882 |
test(Math::Cos(trg,KPiBy2)==KErrNone);
|
|
883 |
// test(trg==0.0);
|
|
884 |
test(Abs(trg)<1e-15);
|
|
885 |
|
|
886 |
test(Math::Cos(trg,KPi)==KErrNone);
|
|
887 |
test(trg==-1.0);
|
|
888 |
|
|
889 |
test(Math::Cos(trg,KPiBy2+KPi)==KErrNone);
|
|
890 |
// test(trg==0.0);
|
|
891 |
test(Abs(trg)<1e-15);
|
|
892 |
|
|
893 |
test(Math::Cos(trg,89.99999*KDegToRad)==KErrNone);
|
|
894 |
test(testApprox(trg,1.745329252E-07,5.0E-10));
|
|
895 |
|
|
896 |
test(Math::Cos(trg,90.00001*KDegToRad)==KErrNone);
|
|
897 |
test(testApprox(trg,-1.7453292516217e-007,5.0E-10));
|
|
898 |
|
|
899 |
// Tan
|
|
900 |
test.Next(_L("Math::Tan()"));
|
|
901 |
test(Math::Tan(trg,0.0)==KErrNone);
|
|
902 |
test(trg==0.0);
|
|
903 |
|
|
904 |
test(Math::Tan(trg,1)==KErrNone);
|
|
905 |
test(testApprox(trg,1.5574077246549,2.0E-15));
|
|
906 |
|
|
907 |
// Pow
|
|
908 |
test.Next(_L("Math::Pow()"));
|
|
909 |
src=10;
|
|
910 |
test(Math::Pow(trg,src,-1.0)==KErrNone);
|
|
911 |
test(testApprox(trg,0.1,1.0E-15));
|
|
912 |
|
|
913 |
test(Math::Pow(trg,src,0.0)==KErrNone);
|
|
914 |
test(trg==1.0);
|
|
915 |
|
|
916 |
test(Math::Pow(trg,src,2.0)==KErrNone);
|
|
917 |
test(testApprox(trg,100.0,1.0E-15));
|
|
918 |
|
|
919 |
src=1.0;
|
|
920 |
test(Math::Pow(trg,src,10000000000000000.0)==KErrNone);
|
|
921 |
test(trg==1.0);
|
|
922 |
|
|
923 |
test.End();
|
|
924 |
}
|
|
925 |
|
|
926 |
LOCAL_C void sqrtest1(TReal low,TReal upp)
|
|
927 |
/*
|
|
928 |
Test the identity sqrt(x*x)=x on the range low<=x<upp
|
|
929 |
*/
|
|
930 |
{
|
|
931 |
|
|
932 |
TReal x,y,res;
|
|
933 |
|
|
934 |
for (TInt j=0;j<100;j++)
|
|
935 |
{
|
|
936 |
randrng(x,low,upp);
|
|
937 |
y=x*x;
|
|
938 |
test(Math::Sqrt(res,y)==KErrNone);
|
|
939 |
test(testApprox(res,x,1.0E-15));
|
|
940 |
}
|
|
941 |
}
|
|
942 |
|
|
943 |
LOCAL_C void sqrtest2()
|
|
944 |
/*
|
|
945 |
Tests specific numbers
|
|
946 |
*/
|
|
947 |
{
|
|
948 |
|
|
949 |
TReal root;
|
|
950 |
|
|
951 |
// test errors
|
|
952 |
test(Math::Sqrt(root,KNaNTReal64)==KErrArgument);
|
|
953 |
test(Math::IsNaN(root));
|
|
954 |
test(Math::Sqrt(root,-1)==KErrArgument);
|
|
955 |
test(Math::IsNaN(root));
|
|
956 |
test(Math::Sqrt(root,KNegInfTReal64)==KErrArgument);
|
|
957 |
test(Math::IsNaN(root));
|
|
958 |
test(Math::Sqrt(root,KPosInfTReal64)==KErrOverflow);
|
|
959 |
test(root==KPosInfTReal64);
|
|
960 |
|
|
961 |
TInt i=sizeof(testsqrt)/sizeof(SQRT_TEST);
|
|
962 |
for (TInt j=0;j<i;j++)
|
|
963 |
{
|
|
964 |
test(Math::Sqrt(root,testsqrt[j].num)==KErrNone);
|
|
965 |
test(testApprox(root,testsqrt[j].res,1.0E-15));
|
|
966 |
}
|
|
967 |
|
|
968 |
// a couple of denormal tests
|
|
969 |
test(Math::Sqrt(root,4E-322)==KErrNone);
|
|
970 |
test(testApprox(root,2E-161,1.0E-3));
|
|
971 |
test(Math::Sqrt(root,1.6E-309)==KErrNone);
|
|
972 |
test(testApprox(root,4E-155,1.0E-15));
|
|
973 |
}
|
|
974 |
|
|
975 |
LOCAL_C void logtest()
|
|
976 |
/*
|
|
977 |
Test numbers in the range sqrt(.1) to .9, using the identity
|
|
978 |
log(x)=log(11x/10)-log(1.1)
|
|
979 |
*/
|
|
980 |
{
|
|
981 |
|
|
982 |
TReal res,x;
|
|
983 |
TReal cnstlog,cnstlogx;
|
|
984 |
|
|
985 |
TReal low=.316227766017;
|
|
986 |
TReal upp=0.9;
|
|
987 |
TReal cnst=11.0/10.0;
|
|
988 |
test(Math::Log(cnstlog,cnst)==KErrNone);
|
|
989 |
for (TInt j=0;j<10;j++)
|
|
990 |
{
|
|
991 |
randrng(x,low,upp);
|
|
992 |
test(Math::Log(res,x)==KErrNone);
|
|
993 |
TReal num=cnst*x;
|
|
994 |
test(Math::Log(cnstlogx,num)==KErrNone);
|
|
995 |
test(testApprox(res,(cnstlogx-cnstlog),1.0E-15));
|
|
996 |
}
|
|
997 |
}
|
|
998 |
|
|
999 |
LOCAL_C void lntest1()
|
|
1000 |
/*
|
|
1001 |
Test selected numbers
|
|
1002 |
*/
|
|
1003 |
{
|
|
1004 |
|
|
1005 |
TReal res;
|
|
1006 |
|
|
1007 |
// test errors
|
|
1008 |
// test(Math::Ln(res,KNegZeroTReal64)==KErrArgument);
|
|
1009 |
test(Math::Ln(res,KNegZeroTReal64)==KErrOverflow);
|
|
1010 |
test(Math::IsInfinite(res));
|
|
1011 |
test(Math::Ln(res,-34)==KErrArgument);
|
|
1012 |
test(Math::IsNaN(res));
|
|
1013 |
test(Math::Ln(res,KNaNTReal64)==KErrArgument);
|
|
1014 |
test(Math::IsNaN(res));
|
|
1015 |
test(Math::Ln(res,KNegInfTReal64)==KErrArgument);
|
|
1016 |
test(Math::IsNaN(res));
|
|
1017 |
test(Math::Ln(res,KPosInfTReal64)==KErrOverflow);
|
|
1018 |
test(res==KPosInfTReal64);
|
|
1019 |
test(Math::Ln(res,0.0)==KErrOverflow);
|
|
1020 |
test(res==KNegInfTReal64);
|
|
1021 |
test(Math::Ln(res,2.71828182845904524)==KErrNone);
|
|
1022 |
test(testApprox(res,1.0,1e-15));
|
|
1023 |
test(Math::Ln(res,7.389056098930650227)==KErrNone);
|
|
1024 |
test(testApprox(res,2.0,1e-15));
|
|
1025 |
|
|
1026 |
TInt i=sizeof(testln)/sizeof(TESTLN);
|
|
1027 |
for (TInt j=0;j<i;j++)
|
|
1028 |
{
|
|
1029 |
test(Math::Ln(res,testln[j].num)==KErrNone);
|
|
1030 |
test(testApprox(res,testln[j].res,1.0E-14));
|
|
1031 |
}
|
|
1032 |
|
|
1033 |
// test some denormals
|
|
1034 |
test(Math::Log(res,K1EMinus322Real64)==KErrNone);
|
|
1035 |
test(testApprox(res,-322.0,2.0E-5));
|
|
1036 |
test(Math::Log(res,K1EMinus313Real64)==KErrNone);
|
|
1037 |
test(testApprox(res,-313.0,1.0E-13));
|
|
1038 |
}
|
|
1039 |
|
|
1040 |
LOCAL_C void lntest2()
|
|
1041 |
/*
|
|
1042 |
Test numbers near to one against the Taylor series approximation
|
|
1043 |
*/
|
|
1044 |
{
|
|
1045 |
|
|
1046 |
TReal x,res;
|
|
1047 |
|
|
1048 |
TReal low=.999999989463;
|
|
1049 |
TReal upp=1.00000001054;
|
|
1050 |
for (TInt k=0;k<10;k++)
|
|
1051 |
{
|
|
1052 |
randrng(x,low,upp);
|
|
1053 |
TRealX tot=0.0;
|
|
1054 |
TRealX xx(x-1);
|
|
1055 |
TInt sign=-1;
|
|
1056 |
for (TInt i=4;i>0;i--)
|
|
1057 |
{
|
|
1058 |
tot+=TRealX(sign)/TRealX(i);
|
|
1059 |
tot*=xx;
|
|
1060 |
sign=-sign;
|
|
1061 |
}
|
|
1062 |
TReal tot2=(TReal)tot;
|
|
1063 |
test(Math::Ln(res,x)==KErrNone);
|
|
1064 |
test(testApprox(res,tot2,1.0E-15));
|
|
1065 |
}
|
|
1066 |
}
|
|
1067 |
|
|
1068 |
LOCAL_C void lntest3()
|
|
1069 |
/*
|
|
1070 |
Test numbers in the range sqrt(.5) to 15/16, using the identity
|
|
1071 |
ln(x)=ln(17x/16)-ln(17/16)
|
|
1072 |
*/
|
|
1073 |
{
|
|
1074 |
|
|
1075 |
TReal x,cnstln,cnstlnx,res;
|
|
1076 |
|
|
1077 |
TReal low=KSqhf;
|
|
1078 |
TReal upp=15.0/16.0;
|
|
1079 |
TReal cnst=17.0/16.0;
|
|
1080 |
test(Math::Ln(cnstln,cnst)==KErrNone);
|
|
1081 |
for (TInt j=0;j<10;j++)
|
|
1082 |
{
|
|
1083 |
randrng(x,low,upp);
|
|
1084 |
test(Math::Ln(res,x)==KErrNone);
|
|
1085 |
TReal num=cnst*x;
|
|
1086 |
test(Math::Ln(cnstlnx,num)==KErrNone);
|
|
1087 |
test(testApprox(res,(cnstlnx-cnstln),1.0E-15));
|
|
1088 |
}
|
|
1089 |
}
|
|
1090 |
|
|
1091 |
LOCAL_C void lntest4()
|
|
1092 |
/*
|
|
1093 |
Test numbers in the range 16 to 240 using the identity ln(x*x)=2ln(x)
|
|
1094 |
*/
|
|
1095 |
{
|
|
1096 |
|
|
1097 |
TReal cnstlnx,res;
|
|
1098 |
|
|
1099 |
TReal low=16.0;
|
|
1100 |
TReal upp=240.0;
|
|
1101 |
TReal x=16.0;
|
|
1102 |
test(Math::Ln(res,-1)==KErrArgument);
|
|
1103 |
for (TInt j=0;j<10;j++)
|
|
1104 |
{
|
|
1105 |
randrng(x,low,upp);
|
|
1106 |
TReal num=x*x;
|
|
1107 |
test(Math::Ln(res,num)==KErrNone);
|
|
1108 |
test(Math::Ln(cnstlnx,x)==KErrNone);
|
|
1109 |
test(testApprox(res,2*cnstlnx,1.0E-15));
|
|
1110 |
}
|
|
1111 |
}
|
|
1112 |
|
|
1113 |
LOCAL_C void exptest1()
|
|
1114 |
/*
|
|
1115 |
To test exponent for specific values
|
|
1116 |
*/
|
|
1117 |
{
|
|
1118 |
|
|
1119 |
TReal res;
|
|
1120 |
|
|
1121 |
// test errors
|
|
1122 |
test(Math::Exp(res,KNaNTReal64)==KErrArgument);
|
|
1123 |
test(Math::IsNaN(res));
|
|
1124 |
test(Math::Exp(res,KPosInfTReal64)==KErrOverflow);
|
|
1125 |
test(res==KPosInfTReal64);
|
|
1126 |
test(Math::Exp(res,709.8)==KErrOverflow);
|
|
1127 |
test(res==KPosInfTReal64);
|
|
1128 |
test(Math::Exp(res,KNegInfTReal64)==KErrUnderflow);
|
|
1129 |
test(Math::IsZero(res));
|
|
1130 |
test(Math::Exp(res,-745.2)==KErrUnderflow);
|
|
1131 |
test(Math::IsZero(res));
|
|
1132 |
|
|
1133 |
TInt i=sizeof(testexp)/sizeof(EXP);
|
|
1134 |
for (TInt j=0;j<i;j++)
|
|
1135 |
{
|
|
1136 |
test(Math::Exp(res,testexp[j].val)==KErrNone);
|
|
1137 |
test(testApprox(res,testexp[j].result,0)); // NB only tests values with results of 1
|
|
1138 |
}
|
|
1139 |
|
|
1140 |
// test some denormals
|
|
1141 |
test(Math::Exp(res,5E-324)==KErrNone);
|
|
1142 |
test(testApprox(res,1.0,0));
|
|
1143 |
test(Math::Exp(res,-6E-318)==KErrNone);
|
|
1144 |
test(testApprox(res,1.0,0));
|
|
1145 |
}
|
|
1146 |
|
|
1147 |
LOCAL_C void exptest2(TReal cnst,TReal ll,TReal ul)
|
|
1148 |
/*
|
|
1149 |
Test the identity exp(x-cnst)=exp(x)*exp(-cnst) for x in the range [ul,ll]
|
|
1150 |
*/
|
|
1151 |
//TReal cnst; // constant used in the identity
|
|
1152 |
//TReal ll; // Lower limit of the range
|
|
1153 |
//TReal ul; // Upper limit of the range
|
|
1154 |
{
|
|
1155 |
|
|
1156 |
TReal cnstexp,cnstexpx,x,res;
|
|
1157 |
|
|
1158 |
test(Math::Exp(cnstexp,cnst)==KErrNone);
|
|
1159 |
for (TInt j=0;j<10;j++)
|
|
1160 |
{
|
|
1161 |
randrng(x,ll,ul);
|
|
1162 |
test(Math::Exp(res,x)==KErrNone);
|
|
1163 |
TReal num=x+cnst;
|
|
1164 |
test(Math::Exp(cnstexpx,num)==KErrNone);
|
|
1165 |
test(testApprox(cnstexpx,(res*cnstexp),1.0E-15));
|
|
1166 |
}
|
|
1167 |
}
|
|
1168 |
|
|
1169 |
LOCAL_C void exptest3()
|
|
1170 |
/*
|
|
1171 |
Test for systematic error
|
|
1172 |
*/
|
|
1173 |
{
|
|
1174 |
|
|
1175 |
TReal step,ul,v;
|
|
1176 |
|
|
1177 |
TReal x=1.0123;
|
|
1178 |
TReal y=x/2;
|
|
1179 |
test(Math::Exp(v,y)==KErrNone);
|
|
1180 |
test(Math::Exp(step,x)==KErrNone);
|
|
1181 |
test(Math::Sqrt(ul,step)==KErrNone);
|
|
1182 |
test(testApprox(ul,v,1.0E-15));
|
|
1183 |
}
|
|
1184 |
|
|
1185 |
LOCAL_C void powtest1()
|
|
1186 |
/*
|
|
1187 |
Test selected numbers
|
|
1188 |
*/
|
|
1189 |
{
|
|
1190 |
|
|
1191 |
TReal res;
|
|
1192 |
|
|
1193 |
// test errors
|
|
1194 |
test(Math::Pow(res,10,-1E8)==KErrUnderflow);
|
|
1195 |
test(res==0.0);
|
|
1196 |
test(Math::Pow(res,10,-KMaxTReal64)==KErrUnderflow);
|
|
1197 |
test(res==0.0);
|
|
1198 |
test(Math::Pow(res,10,-5.5E307)==KErrUnderflow);
|
|
1199 |
test(res==0.0);
|
|
1200 |
test(Math::Pow(res,10,-5.4E307)==KErrUnderflow);
|
|
1201 |
test(res==0.0);
|
|
1202 |
test(Math::Pow(res,10,-1E300)==KErrUnderflow);
|
|
1203 |
test(res==0.0);
|
|
1204 |
test(Math::Pow(res,10,-1E10)==KErrUnderflow);
|
|
1205 |
test(res==0.0);
|
|
1206 |
|
|
1207 |
test(Math::Pow(res,10,5.5E307)==KErrOverflow);
|
|
1208 |
test(res==KPosInfTReal64);
|
|
1209 |
test(Math::Pow(res,10,5.4E307)==KErrOverflow);
|
|
1210 |
test(res==KPosInfTReal64);
|
|
1211 |
test(Math::Pow(res,10,1E308)==KErrOverflow);
|
|
1212 |
test(res==KPosInfTReal64);
|
|
1213 |
test(Math::Pow(res,10,1.7E308)==KErrOverflow);
|
|
1214 |
test(res==KPosInfTReal64);
|
|
1215 |
test(Math::Pow(res,10,KMaxTReal64)==KErrOverflow);
|
|
1216 |
test(res==KPosInfTReal64);
|
|
1217 |
|
|
1218 |
test(Math::Pow(res,1.0,KNaNTReal64)==KErrNone);
|
|
1219 |
test(res==1.0);
|
|
1220 |
test(Math::Pow(res,KNaNTReal64,1.0)==KErrArgument);
|
|
1221 |
test(Math::IsNaN(res));
|
|
1222 |
test(Math::Pow(res,0.0,KNaNTReal64)==KErrArgument);
|
|
1223 |
test(Math::IsNaN(res));
|
|
1224 |
test(Math::Pow(res,KNaNTReal64,0.0)==KErrNone);
|
|
1225 |
test(res==1.0);
|
|
1226 |
test(Math::Pow(res,KNaNTReal64,KNaNTReal64)==KErrArgument);
|
|
1227 |
test(Math::IsNaN(res));
|
|
1228 |
test(Math::Pow(res,KPosInfTReal64,KPosInfTReal64)==KErrOverflow);
|
|
1229 |
test(res==KPosInfTReal64);
|
|
1230 |
// test(Math::Pow(res,KNegInfTReal64,KPosInfTReal64)==KErrOverflow);
|
|
1231 |
// test(res==KPosInfTReal64);
|
|
1232 |
test(Math::Pow(res,KNegInfTReal64,KPosInfTReal64)==KErrOverflow);
|
|
1233 |
test(res==KPosInfTReal64);
|
|
1234 |
test(Math::Pow(res,2.0,KPosInfTReal64)==KErrOverflow);
|
|
1235 |
test(res==KPosInfTReal64);
|
|
1236 |
// test(Math::Pow(res,-2.0,KPosInfTReal64)==KErrOverflow);
|
|
1237 |
// test(res==KPosInfTReal64);
|
|
1238 |
test(Math::Pow(res,-2.0,KPosInfTReal64)==KErrOverflow);
|
|
1239 |
test(res==KPosInfTReal64);
|
|
1240 |
test(Math::Pow(res,0.5,KNegInfTReal64)==KErrOverflow);
|
|
1241 |
test(res==KPosInfTReal64);
|
|
1242 |
// test(Math::Pow(res,-0.5,KNegInfTReal64)==KErrOverflow);
|
|
1243 |
// test(res==KPosInfTReal64);
|
|
1244 |
test(Math::Pow(res,-0.5,KNegInfTReal64)==KErrOverflow);
|
|
1245 |
test(res==KPosInfTReal64);
|
|
1246 |
// test(Math::Pow(res,1.0,KPosInfTReal64)==KErrArgument);
|
|
1247 |
// test(Math::IsNaN(res));
|
|
1248 |
test(Math::Pow(res,1.0,KPosInfTReal64)==KErrNone);
|
|
1249 |
test(res==1.0);
|
|
1250 |
test(Math::Pow(res,-1.0,KPosInfTReal64)==KErrNone);
|
|
1251 |
test(res==1.0);
|
|
1252 |
// test(Math::Pow(res,1.0,KNegInfTReal64)==KErrArgument);
|
|
1253 |
// test(Math::IsNaN(res));
|
|
1254 |
test(Math::Pow(res,1.0,KNegInfTReal64)==KErrNone);
|
|
1255 |
test(res==1.0);
|
|
1256 |
test(Math::Pow(res,-1.0,KNegInfTReal64)==KErrNone);
|
|
1257 |
test(res==1.0);
|
|
1258 |
test(Math::Pow(res,0.0,0.0)==KErrNone);
|
|
1259 |
test(res==1.0);
|
|
1260 |
test(Math::Pow(res,KNegZeroTReal64,KNegZeroTReal64)==KErrNone);
|
|
1261 |
test(res==1.0);
|
|
1262 |
test(Math::Pow(res,0.0,KNegZeroTReal64)==KErrNone);
|
|
1263 |
test(res==1.0);
|
|
1264 |
test(Math::Pow(res,KNegZeroTReal64,0.0)==KErrNone);
|
|
1265 |
test(res==1.0);
|
|
1266 |
test(Math::Pow(res,KPosInfTReal64,2.0)==KErrOverflow);
|
|
1267 |
test(res==KPosInfTReal64);
|
|
1268 |
test(Math::Pow(res,0.0,-2.0)==KErrOverflow);
|
|
1269 |
test(res==KPosInfTReal64);
|
|
1270 |
test(Math::Pow(res,-2.0,-2.6)==KErrArgument);
|
|
1271 |
test(Math::IsNaN(res));
|
|
1272 |
test(Math::Pow(res,-2.0,4.8)==KErrArgument);
|
|
1273 |
test(Math::IsNaN(res));
|
|
1274 |
test(Math::Pow(res,KNegZeroTReal64,-5)==KErrOverflow);
|
|
1275 |
test(res==KNegInfTReal64);
|
|
1276 |
test(Math::Pow(res,KNegZeroTReal64,-6)==KErrOverflow);
|
|
1277 |
test(res==KPosInfTReal64);
|
|
1278 |
test(Math::Pow(res,30,999999)==KErrOverflow); // checking bug fixed
|
|
1279 |
test(res==KPosInfTReal64);
|
|
1280 |
test(Math::Pow(res,200,200)==KErrOverflow);
|
|
1281 |
test(res==KPosInfTReal64);
|
|
1282 |
test(Math::Pow(res,200,2000)==KErrOverflow); // checking bug fixed
|
|
1283 |
test(res==KPosInfTReal64);
|
|
1284 |
test(Math::Pow(res,1000,1000)==KErrOverflow);
|
|
1285 |
test(res==KPosInfTReal64);
|
|
1286 |
test(Math::Pow(res,1000,100)==KErrNone);
|
|
1287 |
test(testApprox(res,1E+300,3.0E-15));
|
|
1288 |
test(Math::Pow(res,1000,-1000)==KErrUnderflow);
|
|
1289 |
test(Math::IsZero(res));
|
|
1290 |
test(Math::Pow(res,1000,-100)==KErrNone);
|
|
1291 |
test(testApprox(res,1E-300,4.0E-15));
|
|
1292 |
|
|
1293 |
TInt j;
|
|
1294 |
TInt i=sizeof(testpow)/sizeof(POWER);
|
|
1295 |
for (j=0;j<i;j++)
|
|
1296 |
{
|
|
1297 |
test(Math::Pow(res,testpow[j].number,testpow[j].power)==KErrNone);
|
|
1298 |
test(testApprox(res,testpow[j].result,1.0E-15));
|
|
1299 |
}
|
|
1300 |
|
|
1301 |
// Added by AnnW, October 1996
|
|
1302 |
TInt size = sizeof(testpowexact)/sizeof(POWER);
|
|
1303 |
for (j=0; j<size; j++)
|
|
1304 |
{
|
|
1305 |
test(Math::Pow(res,testpowexact[j].number,testpowexact[j].power)==KErrNone);
|
|
1306 |
test(res==testpowexact[j].result);
|
|
1307 |
}
|
|
1308 |
|
|
1309 |
// denormals (base only - do not know results for denormal power)
|
|
1310 |
test(Math::Pow(res,K5EMinus324Real64,1.0)==KErrNone);
|
|
1311 |
test(res==K5EMinus324Real64);
|
|
1312 |
test(Math::Pow(res,K5EMinus324Real64,0.0)==KErrNone);
|
|
1313 |
test(res==1.0);
|
|
1314 |
test(Math::Pow(res,2E-160,2.0)==KErrNone);
|
|
1315 |
test(testApprox(res,K4EMinus320Real64,1.0E-4));
|
|
1316 |
|
|
1317 |
// This test is to check that reduce() is working properly
|
|
1318 |
// This is only a very approximate test due to loss of significance for such nos
|
|
1319 |
TReal base,power;
|
|
1320 |
for (TReal powerOfTwo=16.0; powerOfTwo<=54.0; powerOfTwo++)
|
|
1321 |
{
|
|
1322 |
Math::Pow(power,2.0,powerOfTwo);
|
|
1323 |
power+=0.7;
|
|
1324 |
Math::Pow(base,2.0,1/power);
|
|
1325 |
test(Math::Pow(res,base,power)==KErrNone);
|
|
1326 |
test((2.0-res)<=1.0);
|
|
1327 |
}
|
|
1328 |
}
|
|
1329 |
|
|
1330 |
LOCAL_C void powtest2(TReal low,TReal upp)
|
|
1331 |
/*
|
|
1332 |
Test the identity (x**2)**1.5=x**3 on the range low<=x<upp
|
|
1333 |
*/
|
|
1334 |
//TReal low; // lower limit of range to test
|
|
1335 |
//TReal upp; // upper limit of range to test
|
|
1336 |
{
|
|
1337 |
|
|
1338 |
TReal res,rres,x;
|
|
1339 |
|
|
1340 |
for (TInt j=0;j<10;j++)
|
|
1341 |
{
|
|
1342 |
randrng(x,low,upp);
|
|
1343 |
TReal y=2;
|
|
1344 |
test(Math::Pow(res,x,y)==KErrNone);
|
|
1345 |
TReal xr=res;
|
|
1346 |
y=1.5;
|
|
1347 |
test(Math::Pow(res,xr,y)==KErrNone);
|
|
1348 |
TReal yr=3;
|
|
1349 |
test(Math::Pow(rres,x,yr)==KErrNone);
|
|
1350 |
test(testApprox(rres,res,1.0E-14));
|
|
1351 |
}
|
|
1352 |
}
|
|
1353 |
|
|
1354 |
LOCAL_C void powtest3()
|
|
1355 |
/*
|
|
1356 |
Test the identity x**1=x
|
|
1357 |
*/
|
|
1358 |
{
|
|
1359 |
|
|
1360 |
TReal x,res;
|
|
1361 |
|
|
1362 |
TReal low=.5;
|
|
1363 |
TReal upp=1.0;
|
|
1364 |
for (TInt j=0;j<10;j++)
|
|
1365 |
{
|
|
1366 |
randrng(x,low,upp);
|
|
1367 |
TReal y=1.0;
|
|
1368 |
test(Math::Pow(res,x,y)==KErrNone);
|
|
1369 |
test(testApprox(res,x,1.0E-15));
|
|
1370 |
}
|
|
1371 |
}
|
|
1372 |
|
|
1373 |
LOCAL_C void powtest4()
|
|
1374 |
/*
|
|
1375 |
Test the identity (x**2)**(y/2)=x**y
|
|
1376 |
*/
|
|
1377 |
{
|
|
1378 |
|
|
1379 |
TReal res,xr,rres,x,y;
|
|
1380 |
|
|
1381 |
TReal low=.01;
|
|
1382 |
TReal upp=10.0;
|
|
1383 |
TReal lowy=-98; // range for y
|
|
1384 |
TReal uppy=98;
|
|
1385 |
for (TInt j=0;j<10;j++)
|
|
1386 |
{
|
|
1387 |
randrng(x,low,upp);
|
|
1388 |
randrng(y,lowy,uppy);
|
|
1389 |
test(Math::Pow(res,x,y)==KErrNone);
|
|
1390 |
TReal yr=2;
|
|
1391 |
test(Math::Pow(xr,x,yr)==KErrNone);
|
|
1392 |
y/=2;
|
|
1393 |
test(Math::Pow(rres,xr,y)==KErrNone);
|
|
1394 |
test(testApprox(res,rres,5.0E-14));
|
|
1395 |
}
|
|
1396 |
}
|
|
1397 |
|
|
1398 |
LOCAL_C void powtest5()
|
|
1399 |
/*
|
|
1400 |
Test the identity x**y=1/(x**(-y))
|
|
1401 |
*/
|
|
1402 |
{
|
|
1403 |
|
|
1404 |
TReal x,y;
|
|
1405 |
TReal res,rres;
|
|
1406 |
|
|
1407 |
test(Math::Pow(res,-2,-3.765)==KErrArgument);
|
|
1408 |
TReal low=0.5;
|
|
1409 |
TReal upp=1.0;
|
|
1410 |
for (TInt j=0;j<10;j++)
|
|
1411 |
{
|
|
1412 |
randrng(x,low,upp);
|
|
1413 |
randrng(y,low,upp);
|
|
1414 |
test(Math::Pow(res,x,y)==KErrNone);
|
|
1415 |
y*=(-1);
|
|
1416 |
test(Math::Pow(rres,x,y)==KErrNone);
|
|
1417 |
rres=1/rres;
|
|
1418 |
test(testApprox(res,rres,5.0E-15));
|
|
1419 |
}
|
|
1420 |
}
|
|
1421 |
|
|
1422 |
LOCAL_C void powtest6()
|
|
1423 |
/*
|
|
1424 |
Test specific ISO requirements on Pow()
|
|
1425 |
*/
|
|
1426 |
{
|
|
1427 |
TInt i;
|
|
1428 |
TInt n = sizeof(testpow_iso) / sizeof(POWERISO);
|
|
1429 |
for (i = 0; i < n; i++)
|
|
1430 |
{
|
|
1431 |
TReal ans;
|
|
1432 |
TInt rc;
|
|
1433 |
|
|
1434 |
// If one of these tests fails, convert the "failed check xx" number
|
|
1435 |
// to an index in testpow_iso[] by subtracting 1 and then dividing by 2.
|
|
1436 |
// If the original number was odd, the first test (rc == xxx) failed.
|
|
1437 |
// If the original number was even, the second test (.result) failed.
|
|
1438 |
rc = Math::Pow(ans, testpow_iso[i].number, testpow_iso[i].power);
|
|
1439 |
test(rc == testpow_iso[i].rc);
|
|
1440 |
test((rc == KErrArgument) || (ans == testpow_iso[i].result));
|
|
1441 |
}
|
|
1442 |
}
|
|
1443 |
|
|
1444 |
LOCAL_C void pow10test()
|
|
1445 |
//
|
|
1446 |
// Test Pow10() for various selected values - results should indicate which string to
|
|
1447 |
// binary conversions would NOT be expected to be exact - see t_float
|
|
1448 |
//
|
|
1449 |
{
|
|
1450 |
|
|
1451 |
TReal res;
|
|
1452 |
|
|
1453 |
// test errors
|
|
1454 |
test(Math::Pow10(res,-324)==KErrUnderflow);
|
|
1455 |
test(res==0.0);
|
|
1456 |
test(Math::Pow10(res,-400)==KErrUnderflow);
|
|
1457 |
test(res==0.0);
|
|
1458 |
test(Math::Pow10(res,309)==KErrOverflow);
|
|
1459 |
test(res==KPosInfTReal64);
|
|
1460 |
test(Math::Pow10(res,400)==KErrOverflow);
|
|
1461 |
test(res==KPosInfTReal64);
|
|
1462 |
|
|
1463 |
TInt j;
|
|
1464 |
TInt i=sizeof(pow10teste)/sizeof(POW10_TEST);
|
|
1465 |
|
|
1466 |
for (j=0; j<i; j++)
|
|
1467 |
{
|
|
1468 |
test(Math::Pow10(res,pow10teste[j].num)==KErrNone);
|
|
1469 |
test(res==pow10teste[j].res);
|
|
1470 |
}
|
|
1471 |
|
|
1472 |
/* i=sizeof(pow10testa)/sizeof(POW10_TEST);
|
|
1473 |
|
|
1474 |
for (j=0; j<i; j++)
|
|
1475 |
{
|
|
1476 |
test(Math::Pow10(res,pow10testa[j].num)==KErrNone);
|
|
1477 |
test(testApprox(res,pow10testa[j].res,1.0E-15));
|
|
1478 |
}
|
|
1479 |
*/ }
|
|
1480 |
|
|
1481 |
LOCAL_C void sintest1(TReal low,TReal upp)
|
|
1482 |
/*
|
|
1483 |
Test the identity sin(x)=sin(x/3)[3-4*(sin(x/3))**2] on the range low<=x<upp
|
|
1484 |
*/
|
|
1485 |
//TReal low; // lower limit of range to test
|
|
1486 |
//TReal upp; // upper limit of range to test
|
|
1487 |
{
|
|
1488 |
|
|
1489 |
TReal x,res,rres;
|
|
1490 |
|
|
1491 |
for (TInt j=0;j<100;j++)
|
|
1492 |
{
|
|
1493 |
randrng(x,low,upp);
|
|
1494 |
test(Math::Sin(res,x)==KErrNone);
|
|
1495 |
x/=3;
|
|
1496 |
test(Math::Sin(rres,x)==KErrNone);
|
|
1497 |
TReal err=rres*rres;
|
|
1498 |
err*=4;
|
|
1499 |
err=3-err;
|
|
1500 |
err*=rres;
|
|
1501 |
test(testApprox(res,err,1.0E-12));
|
|
1502 |
}
|
|
1503 |
}
|
|
1504 |
|
|
1505 |
LOCAL_C void sintest2()
|
|
1506 |
/*
|
|
1507 |
Test selected values (which may not give exact results)
|
|
1508 |
*/
|
|
1509 |
{
|
|
1510 |
|
|
1511 |
TReal res;
|
|
1512 |
|
|
1513 |
// test errors
|
|
1514 |
test(Math::Sin(res,KNaNTReal64)==KErrArgument);
|
|
1515 |
test(Math::IsNaN(res));
|
|
1516 |
test(Math::Sin(res,KPosInfTReal64)==KErrArgument);
|
|
1517 |
test(Math::IsNaN(res));
|
|
1518 |
test(Math::Sin(res,KNegInfTReal64)==KErrArgument);
|
|
1519 |
test(Math::IsNaN(res));
|
|
1520 |
test(Math::Sin(res,2147483648.0*KPi)==KErrArgument);
|
|
1521 |
test(Math::IsNaN(res));
|
|
1522 |
test(Math::Sin(res,-1E+10)==KErrArgument);
|
|
1523 |
test(Math::IsNaN(res));
|
|
1524 |
|
|
1525 |
TInt i=sizeof(testsin)/sizeof(TESTSINE);
|
|
1526 |
TInt j;
|
|
1527 |
|
|
1528 |
for (j=0;j<i;j++)
|
|
1529 |
{
|
|
1530 |
TReal x=testsin[j].num;
|
|
1531 |
TReal y=testsin[j].res;
|
|
1532 |
test(Math::Sin(res,x)==KErrNone);
|
|
1533 |
test(testApprox(res,y,1.0E-15));
|
|
1534 |
}
|
|
1535 |
|
|
1536 |
//Added by AnnW, October 1996
|
|
1537 |
TInt mult=101;
|
|
1538 |
for (j=-(mult-1); j<mult; j++)
|
|
1539 |
{
|
|
1540 |
test(Math::Sin(res, (4*j+1)*KPiBy2)==KErrNone);
|
|
1541 |
test(testApprox(res,1.0,1.0E-15));
|
|
1542 |
|
|
1543 |
test(Math::Sin(res, (4*j+3)*KPiBy2)==KErrNone);
|
|
1544 |
test(testApprox(res,-1.0,1.0E-15));
|
|
1545 |
|
|
1546 |
test(Math::Sin(res, ((4*j+1)*90)*KDegToRad)==KErrNone);
|
|
1547 |
test(testApprox(res,1.0,1.0E-15));
|
|
1548 |
|
|
1549 |
test(Math::Sin(res, ((4*j+3)*90)*KDegToRad)==KErrNone);
|
|
1550 |
test(testApprox(res,-1.0,1.0E-15));
|
|
1551 |
}
|
|
1552 |
//
|
|
1553 |
}
|
|
1554 |
|
|
1555 |
LOCAL_C void sintest3()
|
|
1556 |
/*
|
|
1557 |
To test the identity sin(-x)=-sin(x) on the range [0,10*pi]
|
|
1558 |
*/
|
|
1559 |
{
|
|
1560 |
|
|
1561 |
TReal x,res,rres;
|
|
1562 |
|
|
1563 |
TReal low=0.0;
|
|
1564 |
TReal upp=10*KPi;
|
|
1565 |
for (TInt j=0;j<10;j++)
|
|
1566 |
{
|
|
1567 |
randrng(x,low,upp);
|
|
1568 |
test(Math::Sin(res,x)==KErrNone);
|
|
1569 |
x*=(-1);
|
|
1570 |
test(Math::Sin(rres,x)==KErrNone);
|
|
1571 |
test(testApprox(rres,-res,1.0E-15));
|
|
1572 |
}
|
|
1573 |
}
|
|
1574 |
|
|
1575 |
LOCAL_C void sintest4()
|
|
1576 |
/*
|
|
1577 |
To test the identity sin(x)=x for x<<1
|
|
1578 |
*/
|
|
1579 |
{
|
|
1580 |
|
|
1581 |
TReal res,x;
|
|
1582 |
TReal low=1E-90;
|
|
1583 |
TReal upp=1E-10;
|
|
1584 |
|
|
1585 |
for (TInt j=0;j<10;j++)
|
|
1586 |
{
|
|
1587 |
randrng(x,low,upp);
|
|
1588 |
test(Math::Sin(res,x)==KErrNone);
|
|
1589 |
test(testApprox(res,x,1.0E-15));
|
|
1590 |
}
|
|
1591 |
|
|
1592 |
// test some denormals
|
|
1593 |
test(Math::Sin(res,5E-324)==KErrNone);
|
|
1594 |
test(testApprox(res,5E-324,1.0E-15));
|
|
1595 |
test(Math::Sin(res,7E-317)==KErrNone);
|
|
1596 |
test(testApprox(res,7E-317,1.0E-15));
|
|
1597 |
}
|
|
1598 |
/*
|
|
1599 |
LOCAL_C void sintest5()
|
|
1600 |
//
|
|
1601 |
// To test that exact results are given for multiples of pi and
|
|
1602 |
// values sufficiently close to them
|
|
1603 |
// Added by AnnW, October 1996
|
|
1604 |
//
|
|
1605 |
{
|
|
1606 |
|
|
1607 |
TReal res;
|
|
1608 |
TInt j;
|
|
1609 |
TInt mult=101; // can use up to 32768
|
|
1610 |
|
|
1611 |
test(Math::Sin(res,KNegZeroTReal64)==KErrNone);
|
|
1612 |
test(res==0.0);
|
|
1613 |
|
|
1614 |
for (j=-(mult-1); j<mult; j++)
|
|
1615 |
{
|
|
1616 |
test(Math::Sin(res, j*KPi)==KErrNone);
|
|
1617 |
test(res==0.0);
|
|
1618 |
test(Math::Sin(res, j*(KPi+1.224E-16))==KErrNone);
|
|
1619 |
test(res==0.0);
|
|
1620 |
test(Math::Sin(res, (j*180)*KDegToRad)==KErrNone);
|
|
1621 |
test(res==0.0);
|
|
1622 |
if (j!=0)
|
|
1623 |
{
|
|
1624 |
test(Math::Sin(res, j*(KPi+1.0E-14))==KErrNone);
|
|
1625 |
test(res!=0.0);
|
|
1626 |
}
|
|
1627 |
}
|
|
1628 |
}
|
|
1629 |
*/
|
|
1630 |
LOCAL_C void costest1()
|
|
1631 |
/*
|
|
1632 |
To test the identity cos(x)=cos(x/3)[4*(cos(x/3)**2)-3] on the interval
|
|
1633 |
[7*pi,7.5*pi]
|
|
1634 |
Added by AnnW, October 1996
|
|
1635 |
*/
|
|
1636 |
{
|
|
1637 |
|
|
1638 |
TReal x,res,rres;
|
|
1639 |
|
|
1640 |
TReal low=7*KPi;
|
|
1641 |
TReal upp=7.5*KPi;
|
|
1642 |
for (TInt j=0;j<100;j++)
|
|
1643 |
{
|
|
1644 |
randrng(x,low,upp);
|
|
1645 |
test(Math::Cos(res,x)==KErrNone);
|
|
1646 |
x/=3;
|
|
1647 |
test(Math::Cos(rres,x)==KErrNone);
|
|
1648 |
test(testApprox(res,rres*(4*(rres*rres)-3),5.0E-13));
|
|
1649 |
}
|
|
1650 |
}
|
|
1651 |
|
|
1652 |
LOCAL_C void costest2()
|
|
1653 |
/*
|
|
1654 |
Test selected values (which may not give exact results)
|
|
1655 |
Added by AnnW, October 1996
|
|
1656 |
*/
|
|
1657 |
{
|
|
1658 |
|
|
1659 |
TReal res;
|
|
1660 |
|
|
1661 |
// test errors
|
|
1662 |
test(Math::Cos(res,KNaNTReal64)==KErrArgument);
|
|
1663 |
test(Math::IsNaN(res));
|
|
1664 |
test(Math::Cos(res,KPosInfTReal64)==KErrArgument);
|
|
1665 |
test(Math::IsNaN(res));
|
|
1666 |
test(Math::Cos(res,KNegInfTReal64)==KErrArgument);
|
|
1667 |
test(Math::IsNaN(res));
|
|
1668 |
test(Math::Cos(res,(2147483648.0*KPi))==KErrArgument);
|
|
1669 |
test(Math::IsNaN(res));
|
|
1670 |
test(Math::Sin(res,-1E+10)==KErrArgument);
|
|
1671 |
test(Math::IsNaN(res));
|
|
1672 |
|
|
1673 |
TInt j;
|
|
1674 |
TInt mult=101;
|
|
1675 |
TInt i=sizeof(testcos)/sizeof(TESTCOSINE);
|
|
1676 |
|
|
1677 |
for (j=0; j<i; j++)
|
|
1678 |
{
|
|
1679 |
test(Math::Cos(res,testcos[j].num)==KErrNone);
|
|
1680 |
test(testApprox(res,testcos[j].res,1.0E-15));
|
|
1681 |
}
|
|
1682 |
|
|
1683 |
test(Math::Cos(res,KNegZeroTReal64)==KErrNone);
|
|
1684 |
test(testApprox(res,1.0,1E-15));
|
|
1685 |
|
|
1686 |
for (j=-(mult-1); j<mult; j++)
|
|
1687 |
{
|
|
1688 |
test(Math::Cos(res, (2*j)*KPi)==KErrNone);
|
|
1689 |
test(testApprox(res,1.0,1.0E-15));
|
|
1690 |
|
|
1691 |
test(Math::Cos(res, (2*j+1)*KPi)==KErrNone);
|
|
1692 |
test(testApprox(res,-1.0,1.0E-15));
|
|
1693 |
|
|
1694 |
test(Math::Cos(res, (2*j)*(KPi+1.224E-16))==KErrNone);
|
|
1695 |
test(testApprox(res,1.0,1.0E-15));
|
|
1696 |
|
|
1697 |
test(Math::Cos(res, (2*j+1)*(KPi+1.224E-16))==KErrNone);
|
|
1698 |
test(testApprox(res,-1.0,1.0E-15));
|
|
1699 |
|
|
1700 |
test(Math::Cos(res, ((2*j)*180)*KDegToRad)==KErrNone);
|
|
1701 |
test(testApprox(res,1.0,1.0E-15));
|
|
1702 |
|
|
1703 |
test(Math::Cos(res, ((2*j+1)*180)*KDegToRad)==KErrNone);
|
|
1704 |
test(testApprox(res,-1.0,1.0E-15));
|
|
1705 |
}
|
|
1706 |
}
|
|
1707 |
|
|
1708 |
LOCAL_C void costest3()
|
|
1709 |
/*
|
|
1710 |
To test the identity cos(-x)=cos(x) on the range [0,10*pi]
|
|
1711 |
Added by AnnW, October 1996
|
|
1712 |
*/
|
|
1713 |
{
|
|
1714 |
|
|
1715 |
TReal x,res,rres;
|
|
1716 |
|
|
1717 |
TReal low=0.0;
|
|
1718 |
TReal upp=10*KPi;
|
|
1719 |
for (TInt j=0;j<10;j++)
|
|
1720 |
{
|
|
1721 |
randrng(x,low,upp);
|
|
1722 |
test(Math::Cos(res,x)==KErrNone);
|
|
1723 |
x*=(-1);
|
|
1724 |
test(Math::Cos(rres,x)==KErrNone);
|
|
1725 |
test(testApprox(rres,res,1.0E-15));
|
|
1726 |
}
|
|
1727 |
}
|
|
1728 |
|
|
1729 |
LOCAL_C void costest4()
|
|
1730 |
/*
|
|
1731 |
To test the identity cos(x)=1 for x<<1
|
|
1732 |
Added by Annw, October 1996
|
|
1733 |
*/
|
|
1734 |
{
|
|
1735 |
|
|
1736 |
TReal res,x;
|
|
1737 |
TReal low=1E-90;
|
|
1738 |
TReal upp=1E-10;
|
|
1739 |
|
|
1740 |
for (TInt j=0;j<10;j++)
|
|
1741 |
{
|
|
1742 |
randrng(x,low,upp);
|
|
1743 |
test(Math::Cos(res,x)==KErrNone);
|
|
1744 |
test(testApprox(res,1.0,1.0E-15));
|
|
1745 |
}
|
|
1746 |
|
|
1747 |
// test some denormals
|
|
1748 |
test(Math::Cos(res,5E-324)==KErrNone);
|
|
1749 |
test(testApprox(res,1.0,1.0E-15));
|
|
1750 |
test(Math::Cos(res,1.34E-315)==KErrNone);
|
|
1751 |
test(testApprox(res,1.0,1.0E-15));
|
|
1752 |
}
|
|
1753 |
/*
|
|
1754 |
LOCAL_C void costest5()
|
|
1755 |
//
|
|
1756 |
// To test that exact results are given for multiples of KPi and
|
|
1757 |
// values sufficiently close to them
|
|
1758 |
// Added by AnnW, October 1996
|
|
1759 |
//
|
|
1760 |
{
|
|
1761 |
|
|
1762 |
TReal res;
|
|
1763 |
TInt mult=101; // can use up to 32768
|
|
1764 |
TInt j;
|
|
1765 |
|
|
1766 |
for (j=-(mult-1); j<mult; j++)
|
|
1767 |
{
|
|
1768 |
test(Math::Cos(res, (2*j+1)*KPiBy2)==KErrNone);
|
|
1769 |
test(res==0.0);
|
|
1770 |
test(Math::Cos(res, (2*j+1)*KPiBy2+(j+1)*1.224E-16)==KErrNone);
|
|
1771 |
test(res==0.0);
|
|
1772 |
test(Math::Cos(res, (2*j+1)*90*KDegToRad)==KErrNone);
|
|
1773 |
test(res==0.0);
|
|
1774 |
if (j!=0)
|
|
1775 |
{
|
|
1776 |
test(Math::Sin(res, (2*j+1)*(KPiBy2+1.0E-14))==KErrNone);
|
|
1777 |
test(res!=0.0);
|
|
1778 |
}
|
|
1779 |
}
|
|
1780 |
}
|
|
1781 |
*/
|
|
1782 |
LOCAL_C void tantest1(TReal low,TReal upp)
|
|
1783 |
/*
|
|
1784 |
Test the identity tan(x)=(2*tan(x/2))/(1-tan(x/2)**2) on the range low<=x<upp
|
|
1785 |
*/
|
|
1786 |
//TReal low; // lower limit of range to test
|
|
1787 |
//TReal upp; // upper limit of range to test
|
|
1788 |
{
|
|
1789 |
|
|
1790 |
TReal x,res,rres;
|
|
1791 |
|
|
1792 |
for (TInt j=0;j<100;j++)
|
|
1793 |
{
|
|
1794 |
if (j==90)
|
|
1795 |
{
|
|
1796 |
test(1);
|
|
1797 |
}
|
|
1798 |
randrng(x,low,upp);
|
|
1799 |
test(Math::Tan(res,x)==KErrNone);
|
|
1800 |
x/=2;
|
|
1801 |
test(Math::Tan(rres,x)==KErrNone);
|
|
1802 |
TReal ex=(2*rres)/(1-rres*rres);
|
|
1803 |
test(testApprox(res,ex,1.0E-15));
|
|
1804 |
}
|
|
1805 |
}
|
|
1806 |
|
|
1807 |
LOCAL_C void tantest2()
|
|
1808 |
/*
|
|
1809 |
To test tangent for specific arguments
|
|
1810 |
*/
|
|
1811 |
{
|
|
1812 |
|
|
1813 |
TReal res;
|
|
1814 |
|
|
1815 |
// test errors
|
|
1816 |
test(Math::Tan(res,KNaNTReal64)==KErrArgument);
|
|
1817 |
test(Math::IsNaN(res));
|
|
1818 |
test(Math::Tan(res,KPosInfTReal64)==KErrArgument);
|
|
1819 |
test(Math::IsNaN(res));
|
|
1820 |
test(Math::Tan(res,KNegInfTReal64)==KErrArgument);
|
|
1821 |
test(Math::IsNaN(res));
|
|
1822 |
test(Math::Tan(res, 1073741824.0*KPi)==KErrArgument);
|
|
1823 |
test(Math::IsNaN(res));
|
|
1824 |
test(Math::Tan(res, 4.0E+102)==KErrArgument);
|
|
1825 |
test(Math::IsNaN(res));
|
|
1826 |
test(Math::Tan(res, -4.0E+102)==KErrArgument);
|
|
1827 |
test(Math::IsNaN(res));
|
|
1828 |
|
|
1829 |
TInt j;
|
|
1830 |
TInt mult=101; // can use up to 32768
|
|
1831 |
TInt i=sizeof(testtan)/sizeof(TAN);
|
|
1832 |
for (j=0;j<i;j++)
|
|
1833 |
{
|
|
1834 |
test(Math::Tan(res,testtan[j].angle)==KErrNone);
|
|
1835 |
test(testApprox(res,testtan[j].result,1.0E-15));
|
|
1836 |
}
|
|
1837 |
|
|
1838 |
//Added by AnnW, October 1996
|
|
1839 |
for (j=-(mult-1); j<mult; j++)
|
|
1840 |
{
|
|
1841 |
// test(Math::Tan(res, (2*j+1)*KPiBy2)==KErrOverflow);
|
|
1842 |
// test(Math::IsInfinite(res)); // this test is no longer valid
|
|
1843 |
test(Math::Tan(res, (2*j+1)*(KPiBy2+1.0E-15))!=KErrOverflow);
|
|
1844 |
test(Math::IsFinite(res));
|
|
1845 |
}
|
|
1846 |
|
|
1847 |
// Check that signs are correct
|
|
1848 |
test(Math::Tan(res,KPiBy2+5E-16)==KErrNone);
|
|
1849 |
test(res<0);
|
|
1850 |
test(Math::Tan(res,KPiBy2-5E-16)==KErrNone);
|
|
1851 |
test(res>0);
|
|
1852 |
}
|
|
1853 |
|
|
1854 |
LOCAL_C void tantest3()
|
|
1855 |
/*
|
|
1856 |
To test the identity tan(-x)=-tan(x) on the range [-1.5,1.5]
|
|
1857 |
*/
|
|
1858 |
{
|
|
1859 |
|
|
1860 |
TReal x,res,rres;
|
|
1861 |
|
|
1862 |
TReal low=(-1.5);
|
|
1863 |
TReal upp=1.5;
|
|
1864 |
for (TInt j=0;j<10;j++)
|
|
1865 |
{
|
|
1866 |
randrng(x,low,upp);
|
|
1867 |
test(Math::Tan(res,x)==KErrNone);
|
|
1868 |
x*=(-1);
|
|
1869 |
test(Math::Tan(rres,x)==KErrNone);
|
|
1870 |
test(testApprox(rres,-res,1.0E-15));
|
|
1871 |
}
|
|
1872 |
}
|
|
1873 |
|
|
1874 |
LOCAL_C void tantest4()
|
|
1875 |
/*
|
|
1876 |
To test the identity tan(x)=x for x<<1
|
|
1877 |
*/
|
|
1878 |
{
|
|
1879 |
|
|
1880 |
TReal x,res;
|
|
1881 |
|
|
1882 |
TReal low=1E-90;
|
|
1883 |
TReal upp=1E-10;
|
|
1884 |
for (TInt j=0;j<10;j++)
|
|
1885 |
{
|
|
1886 |
randrng(x,low,upp);
|
|
1887 |
test(Math::Tan(res,x)==KErrNone);
|
|
1888 |
test(testApprox(res,x,1.0E-15));
|
|
1889 |
}
|
|
1890 |
|
|
1891 |
// Check some denormals
|
|
1892 |
test(Math::Tan(res,5E-324)==KErrNone);
|
|
1893 |
test(res==5E-324);
|
|
1894 |
test(Math::Tan(res,-1.234567891234E-315)==KErrNone);
|
|
1895 |
test(res==-1.234567891234E-315);
|
|
1896 |
}
|
|
1897 |
/*
|
|
1898 |
LOCAL_C void tantest5()
|
|
1899 |
|
|
1900 |
// To test that exact results are given for multiples of KPi
|
|
1901 |
// Added by AnnW, October 1996
|
|
1902 |
|
|
1903 |
{
|
|
1904 |
|
|
1905 |
TReal res;
|
|
1906 |
TInt j;
|
|
1907 |
TInt mult=101; // can use up to 32768
|
|
1908 |
|
|
1909 |
test(Math::Tan(res,KNegZeroTReal64)==KErrNone);
|
|
1910 |
test(res==KNegZeroTReal64);
|
|
1911 |
|
|
1912 |
for (j=-(mult-1); j<mult; j++)
|
|
1913 |
{
|
|
1914 |
test(Math::Tan(res, j*KPi)==KErrNone);
|
|
1915 |
test(res==0.0);
|
|
1916 |
test(Math::Tan(res, j*(KPi+1.224E-16))==KErrNone);
|
|
1917 |
test(res==0.0);
|
|
1918 |
test(Math::Tan(res, (j*180)*KDegToRad)==KErrNone);
|
|
1919 |
test(res==0.0);
|
|
1920 |
if (j!=0)
|
|
1921 |
{
|
|
1922 |
test(Math::Sin(res, j*(KPi+1.0E-14))==KErrNone);
|
|
1923 |
test(res!=0.0);
|
|
1924 |
}
|
|
1925 |
}
|
|
1926 |
}
|
|
1927 |
*/
|
|
1928 |
LOCAL_C void astest1(TReal low,TReal upp,TInt k,TInt cosflg)
|
|
1929 |
/*
|
|
1930 |
Tests random numbers in the range [low,upp] using the Taylor approximation
|
|
1931 |
*/
|
|
1932 |
//TReal low; // lower limit of range to test
|
|
1933 |
//TReal upp; // upper limit of range to test
|
|
1934 |
//TInt k; // Highest order term to be used in the taylor approximation
|
|
1935 |
//TInt cosflg; // Flag for arc cos
|
|
1936 |
{
|
|
1937 |
|
|
1938 |
TReal res,x;
|
|
1939 |
|
|
1940 |
for (TInt j=0;j<100;j++)
|
|
1941 |
{
|
|
1942 |
randrng(x,low,upp);
|
|
1943 |
if (cosflg)
|
|
1944 |
test(Math::ACos(res,x)==KErrNone);
|
|
1945 |
else
|
|
1946 |
test(Math::ASin(res,x)==KErrNone);
|
|
1947 |
TReal tres=taylor(x,k);
|
|
1948 |
if (cosflg)
|
|
1949 |
tres=KPiBy2-tres;
|
|
1950 |
test(testApprox(tres,res,5.0E-15));
|
|
1951 |
}
|
|
1952 |
}
|
|
1953 |
|
|
1954 |
LOCAL_C void astest2()
|
|
1955 |
/*
|
|
1956 |
To test the identity arc sin(x)=x for x<<1
|
|
1957 |
*/
|
|
1958 |
{
|
|
1959 |
|
|
1960 |
TReal x,res;
|
|
1961 |
|
|
1962 |
TReal low=1E-90;
|
|
1963 |
TReal upp=1E-10;
|
|
1964 |
for (TInt j=0;j<100;j++)
|
|
1965 |
{
|
|
1966 |
randrng(x,low,upp);
|
|
1967 |
test(Math::ASin(res,x)==KErrNone);
|
|
1968 |
test(testApprox(res,x,1.0E-15));
|
|
1969 |
}
|
|
1970 |
|
|
1971 |
// Check some denormals
|
|
1972 |
test(Math::ASin(res,5E-324)==KErrNone);
|
|
1973 |
test(res==5E-324);
|
|
1974 |
test(Math::ASin(res,-8.912345678E-318)==KErrNone);
|
|
1975 |
test(res==-8.912345678E-318);
|
|
1976 |
}
|
|
1977 |
|
|
1978 |
LOCAL_C void astest3()
|
|
1979 |
/*
|
|
1980 |
To test the identity arc sin(-x)=-arc sin(x)
|
|
1981 |
*/
|
|
1982 |
{
|
|
1983 |
|
|
1984 |
TReal res,rres,x;
|
|
1985 |
|
|
1986 |
TReal low=0.0;
|
|
1987 |
TReal upp=1.0;
|
|
1988 |
for (TInt j=0;j<100;j++)
|
|
1989 |
{
|
|
1990 |
randrng(x,low,upp);
|
|
1991 |
test(Math::ASin(res,x)==KErrNone);
|
|
1992 |
TReal y=(-x);
|
|
1993 |
test(Math::ASin(rres,y)==KErrNone);
|
|
1994 |
test(testApprox(rres,-res,1.0E-15));
|
|
1995 |
}
|
|
1996 |
}
|
|
1997 |
|
|
1998 |
LOCAL_C void astest4(TInt k,TInt sgn)
|
|
1999 |
/*
|
|
2000 |
Test selected numbers
|
|
2001 |
*/
|
|
2002 |
//TInt k; // arc cosine flag
|
|
2003 |
//TInt sgn; // sign flag for range
|
|
2004 |
{
|
|
2005 |
|
|
2006 |
TReal res;
|
|
2007 |
|
|
2008 |
// test errors
|
|
2009 |
test(Math::ASin(res,KNaNTReal64)==KErrArgument);
|
|
2010 |
test(Math::IsNaN(res));
|
|
2011 |
test(Math::ASin(res,KPosInfTReal64)==KErrArgument);
|
|
2012 |
test(Math::IsNaN(res));
|
|
2013 |
test(Math::ASin(res,KNegInfTReal64)==KErrArgument);
|
|
2014 |
test(Math::IsNaN(res));
|
|
2015 |
test(Math::ASin(res,1.0000000000001)==KErrArgument);
|
|
2016 |
test(Math::IsNaN(res));
|
|
2017 |
test(Math::ASin(res,-1.0000000000001)==KErrArgument);
|
|
2018 |
test(Math::IsNaN(res));
|
|
2019 |
test(Math::ACos(res,KNaNTReal64)==KErrArgument);
|
|
2020 |
test(Math::IsNaN(res));
|
|
2021 |
test(Math::ACos(res,KPosInfTReal64)==KErrArgument);
|
|
2022 |
test(Math::IsNaN(res));
|
|
2023 |
test(Math::ACos(res,KNegInfTReal64)==KErrArgument);
|
|
2024 |
test(Math::IsNaN(res));
|
|
2025 |
test(Math::ACos(res,1.0000000000001)==KErrArgument);
|
|
2026 |
test(Math::IsNaN(res));
|
|
2027 |
test(Math::ACos(res,-1.0000000000001)==KErrArgument);
|
|
2028 |
test(Math::IsNaN(res));
|
|
2029 |
|
|
2030 |
test(Math::ASin(res,0.0)==KErrNone);
|
|
2031 |
test(res==0.0);
|
|
2032 |
test(Math::ASin(res,KNegZeroTReal64)==KErrNone);
|
|
2033 |
test(res==0.0);
|
|
2034 |
|
|
2035 |
TInt i=sizeof(testas)/sizeof(TESTASC);
|
|
2036 |
for (TInt j=0;j<i;j++)
|
|
2037 |
{
|
|
2038 |
// NB Results for comparison only given to 12 or 13 decimal places, so can't expect
|
|
2039 |
// better accuracy
|
|
2040 |
if (k)
|
|
2041 |
{
|
|
2042 |
testas[j].num*=sgn;
|
|
2043 |
testas[j].res*=sgn;
|
|
2044 |
test(Math::ACos(res,testas[j].num)==KErrNone);
|
|
2045 |
test(testApprox(res,(KPiBy2-testas[j].res),1.0E-11));
|
|
2046 |
}
|
|
2047 |
else
|
|
2048 |
{
|
|
2049 |
test(Math::ASin(res,testas[j].num)==KErrNone);
|
|
2050 |
test(testApprox(res,testas[j].res,1.0E-12));
|
|
2051 |
}
|
|
2052 |
}
|
|
2053 |
|
|
2054 |
// Check some denormals for ACos()
|
|
2055 |
test(Math::ACos(res,5E-324)==KErrNone);
|
|
2056 |
test(res==KPiBy2);
|
|
2057 |
test(Math::ACos(res,-9.87654E-320)==KErrNone);
|
|
2058 |
test(res==KPiBy2);
|
|
2059 |
}
|
|
2060 |
|
|
2061 |
LOCAL_C void attest1()
|
|
2062 |
/*
|
|
2063 |
Random argument tests for x in the primary range, comparing the result with a
|
|
2064 |
Taylor series approximation
|
|
2065 |
*/
|
|
2066 |
{
|
|
2067 |
|
|
2068 |
TReal res,x;
|
|
2069 |
|
|
2070 |
TReal low=(-0.0625);
|
|
2071 |
TReal upp=0.0625;
|
|
2072 |
for (TInt i=0;i<10;i++)
|
|
2073 |
{
|
|
2074 |
randrng(x,low,upp);
|
|
2075 |
test(Math::ATan(res,x)==KErrNone);
|
|
2076 |
TReal tres=tayatan(x);
|
|
2077 |
test(testApprox(res,tres,1.0E-15));
|
|
2078 |
}
|
|
2079 |
}
|
|
2080 |
|
|
2081 |
LOCAL_C void attest2()
|
|
2082 |
/*
|
|
2083 |
Random argument tests for x outside the primary range, using the identity
|
|
2084 |
arctan(u)=arctan(v)+arctan[(u-v)/(1+uv)]
|
|
2085 |
*/
|
|
2086 |
{
|
|
2087 |
|
|
2088 |
TReal x,res,rres,atcnst;
|
|
2089 |
|
|
2090 |
TReal low=0.0625;
|
|
2091 |
TReal upp=2.0-KSqt3;
|
|
2092 |
TReal cnst=0.0625;
|
|
2093 |
test(Math::ATan(atcnst,cnst)==KErrNone);
|
|
2094 |
for (TInt i=0;i<10;i++)
|
|
2095 |
{
|
|
2096 |
randrng(x,low,upp);
|
|
2097 |
test(Math::ATan(res,x)==KErrNone);
|
|
2098 |
TReal y=(x-cnst)/(1+x*cnst);
|
|
2099 |
test(Math::ATan(rres,y)==KErrNone);
|
|
2100 |
test(testApprox(res,(atcnst+rres),1.0E-15));
|
|
2101 |
}
|
|
2102 |
}
|
|
2103 |
|
|
2104 |
LOCAL_C void attest3()
|
|
2105 |
/*
|
|
2106 |
Check that the identity arctan(-x)=-arctan(x) holds
|
|
2107 |
*/
|
|
2108 |
{
|
|
2109 |
|
|
2110 |
TReal res,rres,x;
|
|
2111 |
TReal low=0.0;
|
|
2112 |
TReal upp=1.0;
|
|
2113 |
for (TInt i=0;i<10;i++)
|
|
2114 |
{
|
|
2115 |
randrng(x,upp,low);
|
|
2116 |
test(Math::ATan(res,x)==KErrNone);
|
|
2117 |
x=(-x);
|
|
2118 |
test(Math::ATan(rres,x)==KErrNone);
|
|
2119 |
test(testApprox(res,-rres,1.0E-15));
|
|
2120 |
}
|
|
2121 |
}
|
|
2122 |
|
|
2123 |
LOCAL_C void attest4()
|
|
2124 |
/*
|
|
2125 |
Check that the identity arctan(x)=x for Abs(x)<1 holds
|
|
2126 |
*/
|
|
2127 |
{
|
|
2128 |
|
|
2129 |
TReal x,res;
|
|
2130 |
|
|
2131 |
TReal low=1E-90;
|
|
2132 |
TReal upp=1E-20;
|
|
2133 |
for (TInt i=0;i<10;i++)
|
|
2134 |
{
|
|
2135 |
randrng(x,low,upp);
|
|
2136 |
test(Math::ATan(res,x)==KErrNone);
|
|
2137 |
test(testApprox(res,x,1.0E-15));
|
|
2138 |
}
|
|
2139 |
|
|
2140 |
// Check some denormals
|
|
2141 |
test(Math::ATan(res,-5E-324)==KErrNone);
|
|
2142 |
test(res==-5E-324);
|
|
2143 |
test(Math::ATan(res,7.123E-322)==KErrNone);
|
|
2144 |
test(res==7.123E-322);
|
|
2145 |
}
|
|
2146 |
|
|
2147 |
LOCAL_C void attest5()
|
|
2148 |
/*
|
|
2149 |
Tests selected values
|
|
2150 |
*/
|
|
2151 |
{
|
|
2152 |
|
|
2153 |
TReal res;
|
|
2154 |
|
|
2155 |
// test errors, special cases
|
|
2156 |
test(Math::ATan(res,KNaNTReal64)==KErrArgument);
|
|
2157 |
test(Math::IsNaN(res));
|
|
2158 |
test(Math::ATan(res,0.0)==KErrNone);
|
|
2159 |
test(res==0.0);
|
|
2160 |
test(Math::ATan(res,KNegZeroTReal64)==KErrNone);
|
|
2161 |
test(res==0.0);
|
|
2162 |
test(Math::ATan(res,KPosInfTReal64)==KErrNone);
|
|
2163 |
test(res==KPiBy2);
|
|
2164 |
test(Math::ATan(res,KNegInfTReal64)==KErrNone);
|
|
2165 |
test(res==-KPiBy2);
|
|
2166 |
|
|
2167 |
test(Math::ATan(res,KNaNTReal64,1.0)==KErrArgument);
|
|
2168 |
test(Math::IsNaN(res));
|
|
2169 |
test(Math::ATan(res,1.0,KNaNTReal64)==KErrArgument);
|
|
2170 |
test(Math::IsNaN(res));
|
|
2171 |
test(Math::ATan(res,KNaNTReal64,KNaNTReal64)==KErrArgument);
|
|
2172 |
test(Math::IsNaN(res));
|
|
2173 |
test(Math::ATan(res,0.0,KNegZeroTReal64)==KErrArgument);
|
|
2174 |
test(Math::IsNaN(res));
|
|
2175 |
test(Math::ATan(res,KNegZeroTReal64,KNegZeroTReal64)==KErrArgument);
|
|
2176 |
test(Math::IsNaN(res));
|
|
2177 |
test(Math::ATan(res,0.0,0.0)==KErrArgument);
|
|
2178 |
test(Math::IsNaN(res));
|
|
2179 |
test(Math::ATan(res,KNegZeroTReal64,KNegZeroTReal64)==KErrArgument);
|
|
2180 |
test(Math::IsNaN(res));
|
|
2181 |
test(Math::ATan(res,KPosInfTReal64,KNegInfTReal64)==KErrNone);
|
|
2182 |
test(res==3.0*(KPiBy2/2.0));
|
|
2183 |
test(Math::ATan(res,KPosInfTReal64,KPosInfTReal64)==KErrNone);
|
|
2184 |
test(res==KPiBy2/2.0);
|
|
2185 |
test(Math::ATan(res,KNegInfTReal64,KPosInfTReal64)==KErrNone);
|
|
2186 |
test(res==-(KPiBy2/2.0));
|
|
2187 |
test(Math::ATan(res,KNegInfTReal64,KNegInfTReal64)==KErrNone);
|
|
2188 |
test(res==-3.0*(KPiBy2/2.0));
|
|
2189 |
test(Math::ATan(res,KNegZeroTReal64,1.0)==KErrNone);
|
|
2190 |
test(res==0.0);
|
|
2191 |
test(Math::ATan(res,0.0,1.0)==KErrNone);
|
|
2192 |
test(res==0.0);
|
|
2193 |
test(Math::ATan(res,0.0,-1.0)==KErrNone);
|
|
2194 |
test(res==KPi);
|
|
2195 |
test(Math::ATan(res,1.0,KPosInfTReal64)==KErrNone);
|
|
2196 |
test(res==0.0);
|
|
2197 |
test(Math::ATan(res,1.0,KNegInfTReal64)==KErrNone);
|
|
2198 |
test(res==KPi);
|
|
2199 |
test(Math::ATan(res,0.0,KPosInfTReal64)==KErrNone);
|
|
2200 |
test(res==0.0);
|
|
2201 |
test(Math::ATan(res,KPosInfTReal64,1.0)==KErrNone);
|
|
2202 |
test(res==KPiBy2);
|
|
2203 |
test(Math::ATan(res,KNegInfTReal64,1.0)==KErrNone);
|
|
2204 |
test(res==-KPiBy2);
|
|
2205 |
test(Math::ATan(res,1.0,0.0)==KErrNone);
|
|
2206 |
test(res==KPiBy2);
|
|
2207 |
test(Math::ATan(res,1.0,KNegZeroTReal64)==KErrNone);
|
|
2208 |
test(res==KPiBy2);
|
|
2209 |
test(Math::ATan(res,KPosInfTReal64,-1.0)==KErrNone);
|
|
2210 |
test(res==KPiBy2);
|
|
2211 |
test(Math::ATan(res,KNegInfTReal64,-1.0)==KErrNone);
|
|
2212 |
test(res==-KPiBy2);
|
|
2213 |
test(Math::ATan(res,-1.0,0.0)==KErrNone);
|
|
2214 |
test(res==-KPiBy2);
|
|
2215 |
test(Math::ATan(res,-1.0,KNegZeroTReal64)==KErrNone);
|
|
2216 |
test(res==-KPiBy2);
|
|
2217 |
test(Math::ATan(res,5E-324,10)==KErrNone);
|
|
2218 |
test(res==0.0);
|
|
2219 |
test(Math::ATan(res,1E+308,0.1)==KErrNone);
|
|
2220 |
test(res==KPiBy2);
|
|
2221 |
|
|
2222 |
TInt i=sizeof(testat2)/sizeof(TESTATAN2);
|
|
2223 |
for (TInt j=0;j<i;j++)
|
|
2224 |
{
|
|
2225 |
// NB Some results only given to 12 dp so cannot expect better accuracy
|
|
2226 |
test(Math::ATan(res,testat2[j].num1,testat2[j].num2)==KErrNone);
|
|
2227 |
test(testApprox(res,testat2[j].res,1.0E-12));
|
|
2228 |
}
|
|
2229 |
}
|
|
2230 |
|
|
2231 |
LOCAL_C void inttest1()
|
|
2232 |
/*
|
|
2233 |
Tests specific numbers
|
|
2234 |
*/
|
|
2235 |
{
|
|
2236 |
|
|
2237 |
TReal res;
|
|
2238 |
|
|
2239 |
// Specials
|
|
2240 |
test(Math::Int(res,KNaNTReal64)==KErrArgument);
|
|
2241 |
test(Math::IsNaN(res));
|
|
2242 |
test(Math::Int(res,KPosInfTReal64)==KErrOverflow);
|
|
2243 |
test(res==KPosInfTReal64);
|
|
2244 |
test(Math::Int(res,KNegInfTReal64)==KErrOverflow);
|
|
2245 |
test(res==KNegInfTReal64);
|
|
2246 |
|
|
2247 |
TInt i=sizeof(testint1)/sizeof(INT_TEST);
|
|
2248 |
for (TInt j=0;j<i;j++)
|
|
2249 |
{
|
|
2250 |
test(Math::Int(res,testint1[j].num)==KErrNone);
|
|
2251 |
test(res==testint1[j].res);
|
|
2252 |
}
|
|
2253 |
|
|
2254 |
// Check some denormals
|
|
2255 |
test(Math::Int(res,5E-324)==KErrNone);
|
|
2256 |
test(res==0.0);
|
|
2257 |
test(Math::Int(res,1.45E-309)==KErrNone);
|
|
2258 |
test(res==0.0);
|
|
2259 |
}
|
|
2260 |
|
|
2261 |
LOCAL_C void inttest2()
|
|
2262 |
/*
|
|
2263 |
Tests specific numbers
|
|
2264 |
*/
|
|
2265 |
{
|
|
2266 |
|
|
2267 |
TInt16 res;
|
|
2268 |
|
|
2269 |
// test errors
|
|
2270 |
test(Math::Int(res,KNaNTReal64)==KErrArgument);
|
|
2271 |
test(res==0);
|
|
2272 |
test(Math::Int(res,KPosInfTReal64)==KErrOverflow);
|
|
2273 |
test(res==TInt16(KMaxTInt16));
|
|
2274 |
test(Math::Int(res,32768.9830857)==KErrOverflow);
|
|
2275 |
test(res==TInt16(KMaxTInt16));
|
|
2276 |
test(Math::Int(res,32769.36946)==KErrOverflow);
|
|
2277 |
test(res==TInt16(KMaxTInt16));
|
|
2278 |
test(Math::Int(res,KNegInfTReal64)==KErrUnderflow);
|
|
2279 |
test(res==TInt16(KMinTInt16));
|
|
2280 |
test(Math::Int(res,-32774.997937)==KErrUnderflow);
|
|
2281 |
test(res==TInt16(KMinTInt16));
|
|
2282 |
|
|
2283 |
TInt i=sizeof(testint2)/sizeof(INTI_TEST);
|
|
2284 |
for (TInt j=0;j<i;j++)
|
|
2285 |
{
|
|
2286 |
test(Math::Int(res,testint2[j].num)==KErrNone);
|
|
2287 |
test(res==testint2[j].res);
|
|
2288 |
}
|
|
2289 |
|
|
2290 |
// Check some denormals
|
|
2291 |
test(Math::Int(res,5E-324)==KErrNone);
|
|
2292 |
test(res==0.0);
|
|
2293 |
test(Math::Int(res,1.45E-309)==KErrNone);
|
|
2294 |
test(res==0.0);
|
|
2295 |
}
|
|
2296 |
|
|
2297 |
LOCAL_C void inttest3()
|
|
2298 |
/*
|
|
2299 |
Tests specific numbers
|
|
2300 |
*/
|
|
2301 |
{
|
|
2302 |
|
|
2303 |
TInt32 res;
|
|
2304 |
|
|
2305 |
// test errors
|
|
2306 |
test(Math::Int(res,KNaNTReal64)==KErrArgument);
|
|
2307 |
test(res==0);
|
|
2308 |
test(Math::Int(res,KPosInfTReal64)==KErrOverflow);
|
|
2309 |
test(res==KMaxTInt32);
|
|
2310 |
test(Math::Int(res,2147483648.34576)==KErrOverflow);
|
|
2311 |
test(res==KMaxTInt32);
|
|
2312 |
test(Math::Int(res,2147553576.8794365)==KErrOverflow);
|
|
2313 |
test(res==KMaxTInt32);
|
|
2314 |
test(Math::Int(res,KNegInfTReal64)==KErrUnderflow);
|
|
2315 |
test(res==KMinTInt32);
|
|
2316 |
test(Math::Int(res,-2147496757.583)==KErrUnderflow);
|
|
2317 |
test(res==KMinTInt32);
|
|
2318 |
|
|
2319 |
TInt i=sizeof(testint3)/sizeof(INTL_TEST);
|
|
2320 |
for (TInt j=0;j<i;j++)
|
|
2321 |
{
|
|
2322 |
test(Math::Int(res,testint3[j].num)==KErrNone);
|
|
2323 |
test(res==testint3[j].res);
|
|
2324 |
}
|
|
2325 |
|
|
2326 |
// Check some denormals
|
|
2327 |
test(Math::Int(res,5E-324)==KErrNone);
|
|
2328 |
test(res==0.0);
|
|
2329 |
test(Math::Int(res,1.45E-309)==KErrNone);
|
|
2330 |
test(res==0.0);
|
|
2331 |
}
|
|
2332 |
|
|
2333 |
LOCAL_C void inttest4()
|
|
2334 |
{
|
|
2335 |
// tests Int()
|
|
2336 |
TInt16 tint16;
|
|
2337 |
TInt32 tint32;
|
|
2338 |
TReal trg,src=100.0;
|
|
2339 |
|
|
2340 |
test.Start(_L("Math::Int()"));
|
|
2341 |
src=0.0;
|
|
2342 |
test(Math::Int(trg,src)==KErrNone);
|
|
2343 |
test(trg==0.0);
|
|
2344 |
test(Math::Int(tint16,src)==KErrNone);
|
|
2345 |
test(tint16==0);
|
|
2346 |
test(Math::Int(tint32,src)==KErrNone);
|
|
2347 |
test(tint32==0);
|
|
2348 |
|
|
2349 |
src=0.1233456789;
|
|
2350 |
test(Math::Int(trg,src)==KErrNone);
|
|
2351 |
test(trg==0.0);
|
|
2352 |
test(Math::Int(tint16,src)==KErrNone);
|
|
2353 |
test(tint16==0);
|
|
2354 |
test(Math::Int(tint32,src)==KErrNone);
|
|
2355 |
test(tint32==0);
|
|
2356 |
|
|
2357 |
src=-0.5;
|
|
2358 |
test(Math::Int(trg,src)==KErrNone);
|
|
2359 |
test(trg==0.0);
|
|
2360 |
test(Math::Int(tint16,src)==KErrNone);
|
|
2361 |
test(tint16==0);
|
|
2362 |
test(Math::Int(tint32,src)==KErrNone);
|
|
2363 |
test(tint32==0);
|
|
2364 |
|
|
2365 |
src=1.123456789;
|
|
2366 |
test(Math::Int(trg,src)==KErrNone);
|
|
2367 |
test(trg==1.0);
|
|
2368 |
test(Math::Int(tint16,src)==KErrNone);
|
|
2369 |
test(tint16==1);
|
|
2370 |
test(Math::Int(tint32,src)==KErrNone);
|
|
2371 |
test(tint32==1);
|
|
2372 |
|
|
2373 |
src=-1.12345678;
|
|
2374 |
test(Math::Int(trg,src)==KErrNone);
|
|
2375 |
test(trg==-1.0);
|
|
2376 |
test(Math::Int(tint16,src)==KErrNone);
|
|
2377 |
test(tint16==-1);
|
|
2378 |
test(Math::Int(tint32,src)==KErrNone);
|
|
2379 |
test(tint32==-1);
|
|
2380 |
|
|
2381 |
src=KMaxTInt16-0.1;
|
|
2382 |
test(Math::Int(trg,src)==KErrNone);
|
|
2383 |
test(trg==KMaxTInt16-1);
|
|
2384 |
test(Math::Int(tint16,src)==KErrNone);
|
|
2385 |
test(tint16==KMaxTInt16-1);
|
|
2386 |
test(Math::Int(tint32,src)==KErrNone);
|
|
2387 |
test(tint32==KMaxTInt16-1);
|
|
2388 |
|
|
2389 |
src=KMaxTInt16+0.5;
|
|
2390 |
test(Math::Int(trg,src)==KErrNone);
|
|
2391 |
test(trg==KMaxTInt16);
|
|
2392 |
test(Math::Int(tint16,src)==KErrNone);
|
|
2393 |
test(tint16==KMaxTInt16);
|
|
2394 |
test(Math::Int(tint32,src)==KErrNone);
|
|
2395 |
test(tint32==KMaxTInt16);
|
|
2396 |
|
|
2397 |
src=KMaxTInt16+1;
|
|
2398 |
test(Math::Int(trg,src)==KErrNone);
|
|
2399 |
test(trg==KMaxTInt16+1);
|
|
2400 |
test(Math::Int(tint16,src)==KErrOverflow);
|
|
2401 |
test(Math::Int(tint32,src)==KErrNone);
|
|
2402 |
test(tint32==KMaxTInt16+1);
|
|
2403 |
|
|
2404 |
src=KMinTInt16-0.1;
|
|
2405 |
test(Math::Int(trg,src)==KErrNone);
|
|
2406 |
test(trg==KMinTInt16);
|
|
2407 |
test(Math::Int(tint16,src)==KErrNone);
|
|
2408 |
test(tint16==KMinTInt16);
|
|
2409 |
test(Math::Int(tint32,src)==KErrNone);
|
|
2410 |
test(tint32==KMinTInt16);
|
|
2411 |
|
|
2412 |
src=KMinTInt16;
|
|
2413 |
test(Math::Int(trg,src)==KErrNone);
|
|
2414 |
test(trg==KMinTInt16);
|
|
2415 |
test(Math::Int(tint16,src)==KErrNone);
|
|
2416 |
test(tint16==KMinTInt16);
|
|
2417 |
test(Math::Int(tint32,src)==KErrNone);
|
|
2418 |
test(tint32==KMinTInt16);
|
|
2419 |
|
|
2420 |
src=KMinTInt16-1;
|
|
2421 |
test(Math::Int(trg,src)==KErrNone);
|
|
2422 |
test(trg==KMinTInt16-1);
|
|
2423 |
test(Math::Int(tint16,src)==KErrUnderflow);
|
|
2424 |
test(Math::Int(tint32,src)==KErrNone);
|
|
2425 |
test(tint32==KMinTInt16-1);
|
|
2426 |
|
|
2427 |
src=KMaxTInt32-0.1;
|
|
2428 |
test(Math::Int(trg,src)==KErrNone);
|
|
2429 |
test(trg==KMaxTInt32-1);
|
|
2430 |
test(Math::Int(tint16,src)==KErrOverflow);
|
|
2431 |
test(Math::Int(tint32,src)==KErrNone);
|
|
2432 |
test(tint32==KMaxTInt32-1);
|
|
2433 |
|
|
2434 |
src=KMaxTInt32+0.5;
|
|
2435 |
test(Math::Int(trg,src)==KErrNone);
|
|
2436 |
test(trg==KMaxTInt32);
|
|
2437 |
test(Math::Int(tint16,src)==KErrOverflow);
|
|
2438 |
test(Math::Int(tint32,src)==KErrNone);
|
|
2439 |
test(tint32==KMaxTInt32);
|
|
2440 |
|
|
2441 |
src=KMaxTInt32;
|
|
2442 |
src+=1;
|
|
2443 |
test(Math::Int(trg,src)==KErrNone);
|
|
2444 |
test(trg==(TUint32)KMaxTInt32+1);
|
|
2445 |
test(Math::Int(tint16,src)==KErrOverflow);
|
|
2446 |
test(Math::Int(tint32,src)==KErrOverflow);
|
|
2447 |
|
|
2448 |
src=KMinTInt32+0.1;
|
|
2449 |
test(Math::Int(trg,src)==KErrNone);
|
|
2450 |
test(trg==KMinTInt32+1);
|
|
2451 |
test(Math::Int(tint16,src)==KErrUnderflow);
|
|
2452 |
test(Math::Int(tint32,src)==KErrNone);
|
|
2453 |
test(tint32==KMinTInt32+1);
|
|
2454 |
|
|
2455 |
src=KMinTInt32;
|
|
2456 |
test(Math::Int(trg,src)==KErrNone);
|
|
2457 |
test(trg==KMinTInt32);
|
|
2458 |
test(Math::Int(tint16,src)==KErrUnderflow);
|
|
2459 |
test(Math::Int(tint32,src)==KErrNone);
|
|
2460 |
test(tint32==KMinTInt32);
|
|
2461 |
|
|
2462 |
src=KMinTInt32;
|
|
2463 |
src-=1;
|
|
2464 |
test(Math::Int(trg,src)==KErrNone);
|
|
2465 |
test((trg+1)==KMinTInt32);
|
|
2466 |
test(Math::Int(tint16,src)==KErrUnderflow);
|
|
2467 |
test(Math::Int(tint32,src)==KErrUnderflow);
|
|
2468 |
|
|
2469 |
src=KMaxTUint32-0.1;
|
|
2470 |
test(Math::Int(trg,src)==KErrNone);
|
|
2471 |
test(trg==KMaxTUint32-1);
|
|
2472 |
test(Math::Int(tint16,src)==KErrOverflow);
|
|
2473 |
test(Math::Int(tint32,src)==KErrOverflow);
|
|
2474 |
|
|
2475 |
src=KMaxTUint32;
|
|
2476 |
test(Math::Int(trg,src)==KErrNone);
|
|
2477 |
test(trg==KMaxTUint32);
|
|
2478 |
test(Math::Int(tint16,src)==KErrOverflow);
|
|
2479 |
test(Math::Int(tint32,src)==KErrOverflow);
|
|
2480 |
|
|
2481 |
test.End();
|
|
2482 |
}
|
|
2483 |
|
|
2484 |
LOCAL_C void fractest1()
|
|
2485 |
/*
|
|
2486 |
Tests specific numbers
|
|
2487 |
*/
|
|
2488 |
{
|
|
2489 |
|
|
2490 |
TReal res;
|
|
2491 |
|
|
2492 |
// test errors
|
|
2493 |
test(Math::Frac(res,KNaNTReal64)==KErrArgument);
|
|
2494 |
test(Math::IsNaN(res));
|
|
2495 |
test(Math::Frac(res,KPosInfTReal64)==KErrOverflow);
|
|
2496 |
test(res==0.0);
|
|
2497 |
test(Math::Frac(res,KNegInfTReal64)==KErrOverflow);
|
|
2498 |
test(res==0.0);
|
|
2499 |
|
|
2500 |
TInt i=sizeof(testfrac)/sizeof(FRAC_TEST);
|
|
2501 |
for (TInt j=0;j<i;j++)
|
|
2502 |
{
|
|
2503 |
test(Math::Frac(res,testfrac[j].num)==KErrNone);
|
|
2504 |
TReal err=(res-testfrac[j].res);
|
|
2505 |
if (res)
|
|
2506 |
err/=testfrac[j].num; // NB num not res
|
|
2507 |
test(Abs(err)<1.0E-15);
|
|
2508 |
}
|
|
2509 |
|
|
2510 |
// Check some denormals
|
|
2511 |
test(Math::Frac(res,5E-324)==KErrNone);
|
|
2512 |
test(res==5E-324);
|
|
2513 |
test(Math::Frac(res,1.23456789E-314)==KErrNone);
|
|
2514 |
test(res==1.23456789E-314);
|
|
2515 |
}
|
|
2516 |
|
|
2517 |
LOCAL_C void fractest2()
|
|
2518 |
{
|
|
2519 |
// tests Frac()
|
|
2520 |
test.Start(_L("Math::Frac()"));
|
|
2521 |
TReal trg,src;
|
|
2522 |
|
|
2523 |
src=0.0;
|
|
2524 |
test(Math::Frac(trg,src)==KErrNone);
|
|
2525 |
test(trg==0.0);
|
|
2526 |
|
|
2527 |
src=0.1;
|
|
2528 |
test(Math::Frac(trg,src)==KErrNone);
|
|
2529 |
test(trg==0.1);
|
|
2530 |
|
|
2531 |
src=-0.1;
|
|
2532 |
test(Math::Frac(trg,src)==KErrNone);
|
|
2533 |
test(trg==-0.1);
|
|
2534 |
|
|
2535 |
src=7.5;
|
|
2536 |
test(Math::Frac(trg,src)==KErrNone);
|
|
2537 |
test(trg==0.5);
|
|
2538 |
|
|
2539 |
src=-7.5;
|
|
2540 |
test(Math::Frac(trg,src)==KErrNone);
|
|
2541 |
test(trg==-0.5);
|
|
2542 |
|
|
2543 |
src=5.998046875;
|
|
2544 |
test(Math::Frac(trg,src)==KErrNone);
|
|
2545 |
test(trg==0.998046875);
|
|
2546 |
|
|
2547 |
src=-5.998046875;
|
|
2548 |
test(Math::Frac(trg,src)==KErrNone);
|
|
2549 |
test(trg==-0.998046875);
|
|
2550 |
|
|
2551 |
src=-0.00000000001;
|
|
2552 |
test(Math::Frac(trg,src)==KErrNone);
|
|
2553 |
test(trg==-0.00000000001);
|
|
2554 |
|
|
2555 |
src=1000000000000.5;
|
|
2556 |
test(Math::Frac(trg,src)==KErrNone);
|
|
2557 |
test(trg==0.5);
|
|
2558 |
|
|
2559 |
src=1099511627776.0;
|
|
2560 |
src+=0.000244140625;
|
|
2561 |
test(Math::Frac(trg,src)==KErrNone);
|
|
2562 |
test(trg==0.000244140625);
|
|
2563 |
|
|
2564 |
src=-KMaxTInt32;
|
|
2565 |
src+=0.5;
|
|
2566 |
test(Math::Frac(trg,src)==KErrNone);
|
|
2567 |
test(trg==-0.5);
|
|
2568 |
|
|
2569 |
src=KMaxTUint32;
|
|
2570 |
src+=0.5;
|
|
2571 |
test(Math::Frac(trg,src)==KErrNone);
|
|
2572 |
test(trg==0.5);
|
|
2573 |
|
|
2574 |
test.End();
|
|
2575 |
}
|
|
2576 |
|
|
2577 |
LOCAL_C void modtest1()
|
|
2578 |
/*
|
|
2579 |
Test modulo function using specified values
|
|
2580 |
*/
|
|
2581 |
{
|
|
2582 |
|
|
2583 |
TReal res;
|
|
2584 |
|
|
2585 |
// test errors
|
|
2586 |
test(Math::Mod(res,KNaNTReal64,1.0)==KErrArgument);
|
|
2587 |
test(Math::IsNaN(res));
|
|
2588 |
test(Math::Mod(res,1.0,KNaNTReal64)==KErrArgument);
|
|
2589 |
test(Math::IsNaN(res));
|
|
2590 |
test(Math::Mod(res,KNaNTReal64,KNaNTReal64)==KErrArgument);
|
|
2591 |
test(Math::IsNaN(res));
|
|
2592 |
test(Math::Mod(res,KPosInfTReal64,2.0)==KErrArgument);
|
|
2593 |
test(Math::IsNaN(res));
|
|
2594 |
test(Math::Mod(res,KNegInfTReal64,2.0)==KErrArgument);
|
|
2595 |
test(Math::IsNaN(res));
|
|
2596 |
test(Math::Mod(res,2.0,KNegZeroTReal64)==KErrArgument);
|
|
2597 |
test(Math::IsNaN(res));
|
|
2598 |
test(Math::Mod(res,1.0,0.0)==KErrArgument);
|
|
2599 |
test(Math::IsNaN(res));
|
|
2600 |
|
|
2601 |
TInt i=sizeof(testmod)/sizeof(MOD_TEST);
|
|
2602 |
for (TInt j=0;j<i;j++)
|
|
2603 |
{
|
|
2604 |
test(Math::Mod(res,testmod[j].num,testmod[j].mod)==KErrNone);
|
|
2605 |
test(testApprox(res,testmod[j].res,5.0E-13));
|
|
2606 |
}
|
|
2607 |
|
|
2608 |
// Check some denormals
|
|
2609 |
test(Math::Mod(res,K1Point2EMinus320Real64,K5EMinus321Real64)==KErrNone);
|
|
2610 |
test(res==K2EMinus321Real64);
|
|
2611 |
test(Math::Mod(res,K1Point234EMinus316Real64,K1Point234EMinus316Real64)==KErrNone);
|
|
2612 |
test(res==0.0);
|
|
2613 |
}
|
|
2614 |
|
|
2615 |
LOCAL_C void modtest2()
|
|
2616 |
/*
|
|
2617 |
Test modulo function for values which will be incorrect so return KErrTotalLossOfPrecision
|
|
2618 |
*/
|
|
2619 |
{
|
|
2620 |
|
|
2621 |
TReal res;
|
|
2622 |
|
|
2623 |
TInt i=sizeof(testmod2)/sizeof(MOD_TEST);
|
|
2624 |
for (TInt j=0;j<i;j++)
|
|
2625 |
{
|
|
2626 |
test(Math::Mod(res,testmod2[j].num,testmod2[j].mod)==KErrTotalLossOfPrecision);
|
|
2627 |
test(Math::IsZero(res));
|
|
2628 |
}
|
|
2629 |
}
|
|
2630 |
|
|
2631 |
LOCAL_C void DuplicateTest()
|
|
2632 |
//
|
|
2633 |
// Tests that you can use the same variable for both operands in some Math functions
|
|
2634 |
// NB results only given to 12 or 13 significant figures so cannot expect better accuracy
|
|
2635 |
//
|
|
2636 |
{
|
|
2637 |
|
|
2638 |
TReal inOut;
|
|
2639 |
test.Start(_L("ACos"));
|
|
2640 |
inOut=-0.5;
|
|
2641 |
test(Math::ACos(inOut,inOut)==KErrNone);
|
|
2642 |
test(testApprox(inOut,2.094395102393,1.0E-13));
|
|
2643 |
|
|
2644 |
test.Next(_L("ASin"));
|
|
2645 |
inOut=-0.5;
|
|
2646 |
test(Math::ASin(inOut,inOut)==KErrNone);
|
|
2647 |
test(testApprox(inOut,-0.523598775598,6.0E-13));
|
|
2648 |
|
|
2649 |
test.Next(_L("ATan"));
|
|
2650 |
inOut=0.5;
|
|
2651 |
test(Math::ATan(inOut,inOut)==KErrNone);
|
|
2652 |
test(testApprox(inOut,0.463647609001,5.0E-13));
|
|
2653 |
inOut=-0.25;
|
|
2654 |
TReal another=-0.5;
|
|
2655 |
test(Math::ATan(inOut,inOut,another)==KErrNone);
|
|
2656 |
test(testApprox(inOut,-2.677945044589,5.0E-15));
|
|
2657 |
inOut=-0.5;
|
|
2658 |
another=0.25;
|
|
2659 |
test(Math::ATan(inOut,another,inOut)==KErrNone);
|
|
2660 |
test(testApprox(inOut,2.677945044589,5.0E-15));
|
|
2661 |
|
|
2662 |
test.Next(_L("Cos"));
|
|
2663 |
inOut=1;
|
|
2664 |
test(Math::Cos(inOut,inOut)==KErrNone);
|
|
2665 |
test(testApprox(inOut,0.540302305868,3.0E-13));
|
|
2666 |
|
|
2667 |
test.Next(_L("Exp"));
|
|
2668 |
inOut=0.5;
|
|
2669 |
test(Math::Exp(inOut,inOut)==KErrNone);
|
|
2670 |
test(testApprox(inOut,1.648721270700,1.0E-13));
|
|
2671 |
|
|
2672 |
test.Next(_L("Frac"));
|
|
2673 |
inOut=56.123456789;
|
|
2674 |
test(Math::Frac(inOut,inOut)==KErrNone);
|
|
2675 |
test(testApprox(inOut,0.123456789,2.0E-14));
|
|
2676 |
|
|
2677 |
test.Next(_L("Int"));
|
|
2678 |
inOut=56.123456789;
|
|
2679 |
test(Math::Int(inOut,inOut)==KErrNone);
|
|
2680 |
test(inOut==56);
|
|
2681 |
|
|
2682 |
test.Next(_L("Log"));
|
|
2683 |
inOut=0.5;
|
|
2684 |
test(Math::Log(inOut,inOut)==KErrNone);
|
|
2685 |
test(testApprox(inOut,-0.301029995664,7.0E-14));
|
|
2686 |
|
|
2687 |
test.Next(_L("Ln"));
|
|
2688 |
inOut=0.5;
|
|
2689 |
test(Math::Ln(inOut,inOut)==KErrNone);
|
|
2690 |
test(testApprox(inOut,-0.693147180560,8.0E-14));
|
|
2691 |
|
|
2692 |
test.Next(_L("Mod"));
|
|
2693 |
inOut=53;
|
|
2694 |
another=17;
|
|
2695 |
test(Math::Mod(inOut,inOut,another)==KErrNone);
|
|
2696 |
test(inOut==2);
|
|
2697 |
inOut=17;
|
|
2698 |
another=53;
|
|
2699 |
test(Math::Mod(inOut,another,inOut)==KErrNone);
|
|
2700 |
test(inOut==2);
|
|
2701 |
|
|
2702 |
test.Next(_L("Pow"));
|
|
2703 |
inOut=-5;
|
|
2704 |
another=3;
|
|
2705 |
test(Math::Pow(inOut,inOut,another)==KErrNone);
|
|
2706 |
test(inOut==-125.0);
|
|
2707 |
another=-5;
|
|
2708 |
inOut=3;
|
|
2709 |
test(Math::Pow(inOut,another,inOut)==KErrNone);
|
|
2710 |
test(inOut==-125.0);
|
|
2711 |
|
|
2712 |
test.Next(_L("Sin"));
|
|
2713 |
inOut=1;
|
|
2714 |
test(Math::Sin(inOut,inOut)==KErrNone);
|
|
2715 |
test(testApprox(inOut,0.84147098480790,5.0E-15));
|
|
2716 |
|
|
2717 |
test.Next(_L("Round"));
|
|
2718 |
inOut=123.4567;
|
|
2719 |
test(Math::Round(inOut,inOut,2)==KErrNone);
|
|
2720 |
test(testApprox(inOut,123.46,1.0E-15));
|
|
2721 |
|
|
2722 |
test.Next(_L("Sqrt"));
|
|
2723 |
inOut=53;
|
|
2724 |
test(Math::Sqrt(inOut,inOut)==KErrNone);
|
|
2725 |
test(testApprox(inOut,7.280109889281,7.0E-14));
|
|
2726 |
|
|
2727 |
test.Next(_L("Tan"));
|
|
2728 |
inOut=1;
|
|
2729 |
test(Math::Tan(inOut,inOut)==KErrNone);
|
|
2730 |
test(testApprox(inOut,1.557407724655,7.0E-14));
|
|
2731 |
|
|
2732 |
test.End();
|
|
2733 |
}
|
|
2734 |
|
|
2735 |
LOCAL_C void specialtest()
|
|
2736 |
//
|
|
2737 |
// Tests functions which test for specials
|
|
2738 |
//
|
|
2739 |
{
|
|
2740 |
|
|
2741 |
test(Math::IsZero(0.0));
|
|
2742 |
test(Math::IsZero(KNegZeroTReal64));
|
|
2743 |
test(Math::IsZero(0.0));
|
|
2744 |
test(!Math::IsZero(1.0));
|
|
2745 |
test(!Math::IsZero(KPosInfTReal64));
|
|
2746 |
test(!Math::IsZero(KNaNTReal64));
|
|
2747 |
test(!Math::IsZero(K5EMinus324Real64));
|
|
2748 |
|
|
2749 |
test(Math::IsNaN(KNaNTReal64));
|
|
2750 |
test(!Math::IsNaN(KPosInfTReal64));
|
|
2751 |
test(!Math::IsNaN(KNegInfTReal64));
|
|
2752 |
test(!Math::IsNaN(0.0));
|
|
2753 |
test(!Math::IsNaN(1.0));
|
|
2754 |
|
|
2755 |
test(Math::IsInfinite(KPosInfTReal64));
|
|
2756 |
test(Math::IsInfinite(KNegInfTReal64));
|
|
2757 |
test(!Math::IsInfinite(KNaNTReal64));
|
|
2758 |
test(!Math::IsInfinite(0.0));
|
|
2759 |
test(!Math::IsInfinite(KMaxTReal64));
|
|
2760 |
|
|
2761 |
test(!Math::IsFinite(KPosInfTReal64));
|
|
2762 |
test(!Math::IsFinite(KNegInfTReal64));
|
|
2763 |
test(!Math::IsFinite(KNaNTReal64));
|
|
2764 |
test(Math::IsFinite(0.0));
|
|
2765 |
test(Math::IsFinite(KMaxTReal64));
|
|
2766 |
test(Math::IsFinite(5E-324));
|
|
2767 |
test(Math::IsFinite(1.0));
|
|
2768 |
}
|
|
2769 |
|
|
2770 |
void _matherr(TExcType aType)
|
|
2771 |
//
|
|
2772 |
// Dummy function to handle exceptions
|
|
2773 |
//
|
|
2774 |
{
|
|
2775 |
|
|
2776 |
test.Printf(_L("_matherr: Exception type %u handled\n"),TUint(aType));
|
|
2777 |
}
|
|
2778 |
|
|
2779 |
#ifdef __GCC32__
|
|
2780 |
#define FSTCW(x) asm("mov eax, %0\nfstcw [eax]": : "i"(&x))
|
|
2781 |
#define FLDCW(x) asm("mov eax, %0\nfldcw [eax]": : "i"(&x))
|
|
2782 |
#else
|
|
2783 |
#define FSTCW(x) _asm fstcw x
|
|
2784 |
#define FLDCW(x) _asm fldcw x
|
|
2785 |
#endif
|
|
2786 |
TInt16 cw=0; // must be global or GCC/GAS can't get the address!
|
|
2787 |
|
|
2788 |
GLDEF_C TInt E32Main()
|
|
2789 |
{
|
|
2790 |
|
|
2791 |
#if defined (__X86__)
|
|
2792 |
FSTCW(cw);
|
|
2793 |
test.Printf(_L("control word = 0x%x\n"),cw);
|
|
2794 |
cw=0x27f; // WINS value
|
|
2795 |
FLDCW(cw);
|
|
2796 |
#endif
|
|
2797 |
|
|
2798 |
test.Title();
|
|
2799 |
|
|
2800 |
test.Start(_L("Assorted tests"));
|
|
2801 |
AssortedTests();
|
|
2802 |
|
|
2803 |
test.Next(_L("sqrtest1(KSqhf,1.0)"));
|
|
2804 |
sqrtest1(KSqhf,1.0);
|
|
2805 |
test.Next(_L("sqrtest1(1.0,1.41421356238)"));
|
|
2806 |
sqrtest1(1.0,1.41421356238);
|
|
2807 |
test.Next(_L("sqrtest2"));
|
|
2808 |
sqrtest2();
|
|
2809 |
|
|
2810 |
test.Next(_L("logtest"));
|
|
2811 |
logtest();
|
|
2812 |
test.Next(_L("lntest1"));
|
|
2813 |
lntest1();
|
|
2814 |
test.Next(_L("lntest2"));
|
|
2815 |
lntest2();
|
|
2816 |
test.Next(_L("lntest3"));
|
|
2817 |
lntest3();
|
|
2818 |
test.Next(_L("lntest4"));
|
|
2819 |
lntest4();
|
|
2820 |
|
|
2821 |
test.Next(_L("exptest1"));
|
|
2822 |
exptest1();
|
|
2823 |
test.Next(_L("exptest2(-0.0625,-.9375,1.0625)"));
|
|
2824 |
exptest2(-0.0625,-0.9375,1.0625);
|
|
2825 |
test.Next(_L("exptest2(-29.0/16.0),1.0,88.0)"));
|
|
2826 |
exptest2((-29.0/16.0),1.0,88.0);
|
|
2827 |
test.Next(_L("exptest2(-29.0/16.0),-1.0,-88.0)"));
|
|
2828 |
exptest2((-29.0/16.0),-1.0,-88.0);
|
|
2829 |
test.Next(_L("exptest3"));
|
|
2830 |
exptest3();
|
|
2831 |
|
|
2832 |
test.Next(_L("powtest1"));
|
|
2833 |
powtest1();
|
|
2834 |
test.Next(_L("powtest2(.5,1.0)"));
|
|
2835 |
powtest2(.5,1.0);
|
|
2836 |
test.Next(_L("powtest2(1.0,1.0E33)"));
|
|
2837 |
powtest2(1.0,1.0E33);
|
|
2838 |
test.Next(_L("powtest3"));
|
|
2839 |
powtest3();
|
|
2840 |
test.Next(_L("powtest4"));
|
|
2841 |
powtest4();
|
|
2842 |
test.Next(_L("powtest5"));
|
|
2843 |
powtest5();
|
|
2844 |
test.Next(_L("powtest6"));
|
|
2845 |
powtest6();
|
|
2846 |
|
|
2847 |
test.Next(_L("pow10test"));
|
|
2848 |
pow10test();
|
|
2849 |
|
|
2850 |
test.Next(_L("sintest1(3*KPi,3.5*KPi)"));
|
|
2851 |
sintest1(3*KPi,3.5*KPi);
|
|
2852 |
test.Next(_L("sintest1(3*KPi,3.5*KPi)"));
|
|
2853 |
sintest1(6*KPi,6.5*KPi);
|
|
2854 |
test.Next(_L("sintest2"));
|
|
2855 |
sintest2();
|
|
2856 |
test.Next(_L("sintest3"));
|
|
2857 |
sintest3();
|
|
2858 |
test.Next(_L("sintest4"));
|
|
2859 |
sintest4();
|
|
2860 |
// test.Next(_L("sintest5")); // this test is no longer valid
|
|
2861 |
// sintest5();
|
|
2862 |
|
|
2863 |
test.Next(_L("costest1"));
|
|
2864 |
costest1();
|
|
2865 |
test.Next(_L("costest2"));
|
|
2866 |
costest2();
|
|
2867 |
test.Next(_L("costest3"));
|
|
2868 |
costest3();
|
|
2869 |
test.Next(_L("costest4"));
|
|
2870 |
costest4();
|
|
2871 |
// test.Next(_L("costest5")); // this test is no longer valid
|
|
2872 |
// costest5();
|
|
2873 |
|
|
2874 |
test.Next(_L("tantest1(-.25*KPi,.25*KPi)"));
|
|
2875 |
tantest1(-.25*KPi,.25*KPi);
|
|
2876 |
test.Next(_L("tantest1(.875*KPi,1.125*KPi)"));
|
|
2877 |
tantest1(.875*KPi,1.125*KPi);
|
|
2878 |
test.Next(_L("tantest1(6*KPi,6.25*KPi)"));
|
|
2879 |
tantest1(6*KPi,6.25*KPi);
|
|
2880 |
test.Next(_L("tantest2"));
|
|
2881 |
tantest2();
|
|
2882 |
test.Next(_L("tantest3"));
|
|
2883 |
tantest3();
|
|
2884 |
test.Next(_L("tantest4"));
|
|
2885 |
tantest4();
|
|
2886 |
// test.Next(_L("tantest5")); // this test is no longer valid
|
|
2887 |
// tantest5();
|
|
2888 |
|
|
2889 |
test.Next(_L("astest1(-.125,0.125,15,0)"));
|
|
2890 |
astest1(-.125,0.125,15,0);
|
|
2891 |
test.Next(_L("astest1(-.125,0.125,15,1)"));
|
|
2892 |
astest1(-.125,0.125,15,1);
|
|
2893 |
test.Next(_L("astest2"));
|
|
2894 |
astest2();
|
|
2895 |
test.Next(_L("astest3"));
|
|
2896 |
astest3();
|
|
2897 |
test.Next(_L("astest4(0,1)"));
|
|
2898 |
astest4(0,1);
|
|
2899 |
test.Next(_L("astest4(1,1)"));
|
|
2900 |
astest4(1,1);
|
|
2901 |
test.Next(_L("astest4(1,-1)"));
|
|
2902 |
astest4(1,-1);
|
|
2903 |
|
|
2904 |
test.Next(_L("attest1"));
|
|
2905 |
attest1();
|
|
2906 |
test.Next(_L("attest2"));
|
|
2907 |
attest2();
|
|
2908 |
test.Next(_L("attest3"));
|
|
2909 |
attest3();
|
|
2910 |
test.Next(_L("attest4"));
|
|
2911 |
attest4();
|
|
2912 |
test.Next(_L("attest5"));
|
|
2913 |
attest5();
|
|
2914 |
|
|
2915 |
test.Next(_L("inttest1"));
|
|
2916 |
inttest1();
|
|
2917 |
test.Next(_L("intitest2"));
|
|
2918 |
inttest2();
|
|
2919 |
test.Next(_L("inttest3"));
|
|
2920 |
inttest3();
|
|
2921 |
test.Next(_L("inttest4"));
|
|
2922 |
inttest4();
|
|
2923 |
|
|
2924 |
test.Next(_L("fractest1"));
|
|
2925 |
fractest1();
|
|
2926 |
test.Next(_L("fractest2"));
|
|
2927 |
fractest2();
|
|
2928 |
|
|
2929 |
test.Next(_L("modtest1"));
|
|
2930 |
modtest1();
|
|
2931 |
test.Next(_L("modtest2"));
|
|
2932 |
modtest2();
|
|
2933 |
|
|
2934 |
test.Next(_L("Test duplicate parameters"));
|
|
2935 |
DuplicateTest();
|
|
2936 |
|
|
2937 |
test.Next(_L("Test Math::Is...() functions"));
|
|
2938 |
specialtest();
|
|
2939 |
|
|
2940 |
test.End();
|
|
2941 |
return(KErrNone);
|
|
2942 |
}
|
|
2943 |
|