Update contrib.
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".
8 // Initial Contributors:
9 // Nokia Corporation - initial contribution.
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.
20 // Test functionality of the Math library.
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:
34 // Assumptions/Requirement/Pre-requisites:
35 // Failures and causes:
36 // Base Port information:
43 LOCAL_D RTest test(_L("T_MATH"));
45 LOCAL_D TInt64 rseed = MAKE_TINT64(123456789,987654321);
49 TReal num; // input number
50 TReal res; // expected result
53 LOCAL_D SQRT_TEST testsqrt[]=
56 {KNegZeroTReal64,KNegZeroTReal64},
68 {1.0000000001,1.00000000005}
73 TReal num; // input number
74 TReal res; // expected result
77 LOCAL_D TESTLN testln[]=
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},
108 TReal val; // value for which the exponent is to be found
109 TReal result; // result
112 LOCAL_D EXP testexp[]=
122 TReal number; // number to be raised to a power
123 TReal power; // power
124 TReal result; // result
127 LOCAL_D POWER testpow[]=
133 {16,20,1.208925819614628E+24},
136 // Added by AnnW, October 1996
137 LOCAL_D const POWER testpowexact[]=
142 {0.0,3.9271E-17,0.0},
153 {-1.0,1.0000000001E+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},
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},
173 // Check ISO requirements on Pow()
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
183 const TReal KPosZeroTReal64 = 0.0;
185 LOCAL_D const POWERISO testpow_iso[] =
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
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
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
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
205 // pow(-1, +/-INF) returns 1
206 { -1.0, KPosInfTReal64, KErrNone, 1.0 }, // 8
207 { -1.0, KNegInfTReal64, KErrNone, 1.0 }, // 9
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
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
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
248 // pow(x, -INF) returns +INF for |x| < 1
249 { 0.5, KNegInfTReal64, KErrOverflow, KPosInfTReal64 }, // 42
250 { -0.5, KNegInfTReal64, KErrOverflow, KPosInfTReal64 }, // 43
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
258 // pow(x, +INF) returns +0 for |x| < 1
259 { .5, KPosInfTReal64, KErrNone, KPosZeroTReal64 }, // 48
260 { -.5, KPosInfTReal64, KErrNone, KPosZeroTReal64 }, // 49
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
268 // pow(-INF, y) returns -0 for y an odd integer < 0
269 { KNegInfTReal64, -1, KErrNone, KNegZeroTReal64 }, // 54
270 { KNegInfTReal64, -5, KErrNone, KNegZeroTReal64 }, // 55
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
276 // pow(-INF, y) returns -INF for y an odd integer > 0
277 { KNegInfTReal64, 1, KErrOverflow, KNegInfTReal64 }, // 58
278 { KNegInfTReal64, 5, KErrOverflow, KNegInfTReal64 }, // 59
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
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
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
299 TInt num; // input number
300 TReal res; // expected result
303 LOCAL_D POW10_TEST pow10teste[]=
311 //LOCAL_D POW10_TEST pow10testa[]=
319 {-310,K1EMinus310Real64},
320 {-323,K1EMinus323Real64}
325 TReal num; // input number
326 TReal res; // expected result
329 #pragma warning ( disable : 4204 ) // non-constant aggregate initializer
330 LOCAL_D TESTSINE testsin[]=
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},
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}
353 TReal num; // input number
354 TReal res; // expected result
357 LOCAL_D TESTCOSINE testcos[]=
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},
372 {120*KDegToRad,-0.5},
375 {2*(KPi+1.0E-15),1.0}
380 TReal angle; // angle for which the tangent is to be found
381 TReal result; // result
384 LOCAL_D TAN testtan[]=
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}, //
401 TReal num; // input number
402 TReal res; // expected result
405 LOCAL_D TESTASC testas[]=
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},
418 {-1.0, -90.0*KDegToRad},
424 TReal num1; // Divisor
425 TReal num2; // Divand
426 TReal res; // expected result
429 LOCAL_D TESTATAN2 testat2[]=
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
439 #pragma warning ( default : 4204 )
443 TReal num; // input number
444 TReal res; // expected result
447 LOCAL_D INT_TEST testint1[]=
454 {232478.35,232478.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},
475 TReal num; // input number
476 TInt16 res; // expected result
479 LOCAL_D INTI_TEST testint2[]=
492 {-32767.47658,-32767},
493 {32767.9830857,32767},
494 {-32768.47658,-32767-1}
499 TReal num; // input number
500 TInt32 res; // expected result
503 LOCAL_D INTL_TEST testint3[]=
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}
530 TReal num; // input number
531 TReal res; // expected result
534 LOCAL_D FRAC_TEST testfrac[]=
537 {KNegZeroTReal64,0.0},
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}
564 TReal num; // input number
566 TReal res; // expected result
569 LOCAL_D MOD_TEST testmod[]=
574 {-65.6478,.65,-.6478},
575 {-6858.78432,-87.5323,-31.26492},
576 {7665.140215,-34.98,4.520215},
579 {1.0,KPosInfTReal64,1.0},
580 {1.0,KNegInfTReal64,1.0},
593 {1024.0,3.0,1.0}, //10
603 {1048576.0,3.0,1.0}, //20
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}
643 // expected result is unused in following - will be zero in all cases
644 LOCAL_D MOD_TEST testmod2[]=
648 {KMaxTReal64,5.0,0.0},
649 {-KMaxTReal64,5.0,0.0},
651 {36028797019963968.0,2.0,0.0}, // 2**55,2**1
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},
659 TInt testApprox(TReal aFound,TReal aExpect,TReal aTol)
661 // Tests relative error, i.e. whether (aFound-aExpect)/aFound <= aTol
665 TRealX diff,check,l,r,t;
669 if (l.Mult(check,t)==KErrUnderflow)
679 if (Abs(TReal(diff))<=aTol)
684 LOCAL_C void randrng(TReal& pret,TReal& llim,TReal& ulim)
686 Returns a random number in the range [llim,ulim]
690 pret=Math::FRand(rseed);
695 LOCAL_C TReal taylor(TReal x,TInt k)
697 Evaluate the Taylor series approximation to arc sine up to terms of order k
699 //TReal x; // argument
700 //TInt k; // Highest order term
704 TReal den,num,res,term,di;
719 term+=(res*den)/(i*num);
726 LOCAL_C TReal tayatan(TReal val)
728 Finds the taylor series approximation to the arc tangent function
734 TReal sgn,s,d,di,term,res;
743 Math::Pow(res,val,d);
744 term+=(sgn*res)/(2.0*di+1.0);
749 LOCAL_C void AssortedTests()
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
759 test.Start(_L("Math::ASin()"));
760 test(Math::ASin(trg,0.0)==KErrNone);
763 test(Math::ASin(trg,1.0)==KErrNone);
764 test(testApprox(trg,1.5707963267949,5.0E-15));
767 test.Next(_L("Math::ACos()"));
768 test(Math::ACos(trg,0)==KErrNone);
769 test(testApprox(trg,1.5707963267949,5.0E-15));
771 test(Math::ACos(trg,1.0)==KErrNone);
775 test.Next(_L("Math::ATan()"));
776 test(Math::ATan(trg,0.0)==KErrNone);
779 test(Math::ATan(trg,1.0)==KErrNone);
780 test(testApprox(trg,0.78539816339745,5.0E-15));
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));
788 test.Next(_L("Math::Sqrt()"));
789 test(Math::Sqrt(trg,0.0)==KErrNone);
792 test(Math::Sqrt(trg,-1.0)==KErrArgument);
794 test(Math::Sqrt(trg,100.0)==KErrNone);
795 test(testApprox(trg,10.0,1.0E-15));
797 test(Math::Sqrt(trg,56.25)==KErrNone);
801 test.Next(_L("Math::Pow10()"));
802 test(Math::Pow10(trg,-2)==KErrNone);
805 test(Math::Pow10(trg,-1)==KErrNone);
808 test(Math::Pow10(trg,0)==KErrNone);
811 test(Math::Pow10(trg,1)==KErrNone);
814 test(Math::Pow10(trg,2)==KErrNone);
818 test.Next(_L("Math::Ln()"));
819 test(Math::Ln(trg,0.0)==KErrOverflow);
821 test(Math::Ln(trg,1.0)==KErrNone);
824 test(Math::Ln(trg,2)==KErrNone);
825 test(testApprox(trg,0.69314718055995,1.0E-14));
828 test.Next(_L("Math::Log()"));
829 test(Math::Log(trg,0)==KErrOverflow);
831 test(Math::Log(trg,1)==KErrNone);
834 test(Math::Log(trg,10)==KErrNone);
837 test(Math::Log(trg,100000)==KErrNone);
841 test.Next(_L("Math::Sin()"));
842 test(Math::Sin(trg,0)==KErrNone);
845 test(Math::Sin(trg,1)==KErrNone);
846 test(testApprox(trg,0.84147098480790,5.0E-15));
848 test(Math::Sin(trg,KPi)==KErrNone);
850 test(Abs(trg)<1e-15);
852 test(Math::Sin(trg,KPiBy2)==KErrNone);
853 test(testApprox(trg,1.0,1.0E-15));
855 test(Math::Sin(trg,10.0*KPi)==KErrNone);
857 test(Abs(trg)<2e-15);
859 test(Math::Sin(trg,3)==KErrNone);
860 test(trg==0.1411200080598672);
862 test(Math::Sin(trg,4)==KErrNone);
863 test(trg==-0.7568024953079282);
865 test(Math::Sin(trg,3.1415)==KErrNone);
866 test(testApprox(trg,9.26535896605E-5,2.0E-13));
868 test(Math::Sin(trg,3.1416)==KErrNone);
869 test(testApprox(trg,-7.3464102066435914E-6,1.0E-11));
871 test(Math::Sin(trg,(10.0*KPi)+0.001)==KErrNone);
872 test(testApprox(trg,0.000999999833333,4.0E-13));
875 test.Next(_L("Math::Cos()"));
876 test(Math::Cos(trg,0.0)==KErrNone);
877 test(testApprox(trg,1.0,1.0E-15));
879 test(Math::Cos(trg,1)==KErrNone);
880 test(testApprox(trg,0.54030230586814,1.0E-15));
882 test(Math::Cos(trg,KPiBy2)==KErrNone);
884 test(Abs(trg)<1e-15);
886 test(Math::Cos(trg,KPi)==KErrNone);
889 test(Math::Cos(trg,KPiBy2+KPi)==KErrNone);
891 test(Abs(trg)<1e-15);
893 test(Math::Cos(trg,89.99999*KDegToRad)==KErrNone);
894 test(testApprox(trg,1.745329252E-07,5.0E-10));
896 test(Math::Cos(trg,90.00001*KDegToRad)==KErrNone);
897 test(testApprox(trg,-1.7453292516217e-007,5.0E-10));
900 test.Next(_L("Math::Tan()"));
901 test(Math::Tan(trg,0.0)==KErrNone);
904 test(Math::Tan(trg,1)==KErrNone);
905 test(testApprox(trg,1.5574077246549,2.0E-15));
908 test.Next(_L("Math::Pow()"));
910 test(Math::Pow(trg,src,-1.0)==KErrNone);
911 test(testApprox(trg,0.1,1.0E-15));
913 test(Math::Pow(trg,src,0.0)==KErrNone);
916 test(Math::Pow(trg,src,2.0)==KErrNone);
917 test(testApprox(trg,100.0,1.0E-15));
920 test(Math::Pow(trg,src,10000000000000000.0)==KErrNone);
926 LOCAL_C void sqrtest1(TReal low,TReal upp)
928 Test the identity sqrt(x*x)=x on the range low<=x<upp
934 for (TInt j=0;j<100;j++)
938 test(Math::Sqrt(res,y)==KErrNone);
939 test(testApprox(res,x,1.0E-15));
943 LOCAL_C void sqrtest2()
945 Tests specific numbers
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);
961 TInt i=sizeof(testsqrt)/sizeof(SQRT_TEST);
962 for (TInt j=0;j<i;j++)
964 test(Math::Sqrt(root,testsqrt[j].num)==KErrNone);
965 test(testApprox(root,testsqrt[j].res,1.0E-15));
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));
975 LOCAL_C void logtest()
977 Test numbers in the range sqrt(.1) to .9, using the identity
978 log(x)=log(11x/10)-log(1.1)
983 TReal cnstlog,cnstlogx;
985 TReal low=.316227766017;
987 TReal cnst=11.0/10.0;
988 test(Math::Log(cnstlog,cnst)==KErrNone);
989 for (TInt j=0;j<10;j++)
992 test(Math::Log(res,x)==KErrNone);
994 test(Math::Log(cnstlogx,num)==KErrNone);
995 test(testApprox(res,(cnstlogx-cnstlog),1.0E-15));
999 LOCAL_C void lntest1()
1001 Test selected numbers
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));
1026 TInt i=sizeof(testln)/sizeof(TESTLN);
1027 for (TInt j=0;j<i;j++)
1029 test(Math::Ln(res,testln[j].num)==KErrNone);
1030 test(testApprox(res,testln[j].res,1.0E-14));
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));
1040 LOCAL_C void lntest2()
1042 Test numbers near to one against the Taylor series approximation
1048 TReal low=.999999989463;
1049 TReal upp=1.00000001054;
1050 for (TInt k=0;k<10;k++)
1056 for (TInt i=4;i>0;i--)
1058 tot+=TRealX(sign)/TRealX(i);
1062 TReal tot2=(TReal)tot;
1063 test(Math::Ln(res,x)==KErrNone);
1064 test(testApprox(res,tot2,1.0E-15));
1068 LOCAL_C void lntest3()
1070 Test numbers in the range sqrt(.5) to 15/16, using the identity
1071 ln(x)=ln(17x/16)-ln(17/16)
1075 TReal x,cnstln,cnstlnx,res;
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++)
1084 test(Math::Ln(res,x)==KErrNone);
1086 test(Math::Ln(cnstlnx,num)==KErrNone);
1087 test(testApprox(res,(cnstlnx-cnstln),1.0E-15));
1091 LOCAL_C void lntest4()
1093 Test numbers in the range 16 to 240 using the identity ln(x*x)=2ln(x)
1102 test(Math::Ln(res,-1)==KErrArgument);
1103 for (TInt j=0;j<10;j++)
1107 test(Math::Ln(res,num)==KErrNone);
1108 test(Math::Ln(cnstlnx,x)==KErrNone);
1109 test(testApprox(res,2*cnstlnx,1.0E-15));
1113 LOCAL_C void exptest1()
1115 To test exponent for specific values
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));
1133 TInt i=sizeof(testexp)/sizeof(EXP);
1134 for (TInt j=0;j<i;j++)
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
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));
1147 LOCAL_C void exptest2(TReal cnst,TReal ll,TReal ul)
1149 Test the identity exp(x-cnst)=exp(x)*exp(-cnst) for x in the range [ul,ll]
1151 //TReal cnst; // constant used in the identity
1152 //TReal ll; // Lower limit of the range
1153 //TReal ul; // Upper limit of the range
1156 TReal cnstexp,cnstexpx,x,res;
1158 test(Math::Exp(cnstexp,cnst)==KErrNone);
1159 for (TInt j=0;j<10;j++)
1162 test(Math::Exp(res,x)==KErrNone);
1164 test(Math::Exp(cnstexpx,num)==KErrNone);
1165 test(testApprox(cnstexpx,(res*cnstexp),1.0E-15));
1169 LOCAL_C void exptest3()
1171 Test for systematic error
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));
1185 LOCAL_C void powtest1()
1187 Test selected numbers
1194 test(Math::Pow(res,10,-1E8)==KErrUnderflow);
1196 test(Math::Pow(res,10,-KMaxTReal64)==KErrUnderflow);
1198 test(Math::Pow(res,10,-5.5E307)==KErrUnderflow);
1200 test(Math::Pow(res,10,-5.4E307)==KErrUnderflow);
1202 test(Math::Pow(res,10,-1E300)==KErrUnderflow);
1204 test(Math::Pow(res,10,-1E10)==KErrUnderflow);
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);
1218 test(Math::Pow(res,1.0,KNaNTReal64)==KErrNone);
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);
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);
1250 test(Math::Pow(res,-1.0,KPosInfTReal64)==KErrNone);
1252 // test(Math::Pow(res,1.0,KNegInfTReal64)==KErrArgument);
1253 // test(Math::IsNaN(res));
1254 test(Math::Pow(res,1.0,KNegInfTReal64)==KErrNone);
1256 test(Math::Pow(res,-1.0,KNegInfTReal64)==KErrNone);
1258 test(Math::Pow(res,0.0,0.0)==KErrNone);
1260 test(Math::Pow(res,KNegZeroTReal64,KNegZeroTReal64)==KErrNone);
1262 test(Math::Pow(res,0.0,KNegZeroTReal64)==KErrNone);
1264 test(Math::Pow(res,KNegZeroTReal64,0.0)==KErrNone);
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));
1294 TInt i=sizeof(testpow)/sizeof(POWER);
1297 test(Math::Pow(res,testpow[j].number,testpow[j].power)==KErrNone);
1298 test(testApprox(res,testpow[j].result,1.0E-15));
1301 // Added by AnnW, October 1996
1302 TInt size = sizeof(testpowexact)/sizeof(POWER);
1303 for (j=0; j<size; j++)
1305 test(Math::Pow(res,testpowexact[j].number,testpowexact[j].power)==KErrNone);
1306 test(res==testpowexact[j].result);
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);
1314 test(Math::Pow(res,2E-160,2.0)==KErrNone);
1315 test(testApprox(res,K4EMinus320Real64,1.0E-4));
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
1320 for (TReal powerOfTwo=16.0; powerOfTwo<=54.0; powerOfTwo++)
1322 Math::Pow(power,2.0,powerOfTwo);
1324 Math::Pow(base,2.0,1/power);
1325 test(Math::Pow(res,base,power)==KErrNone);
1326 test((2.0-res)<=1.0);
1330 LOCAL_C void powtest2(TReal low,TReal upp)
1332 Test the identity (x**2)**1.5=x**3 on the range low<=x<upp
1334 //TReal low; // lower limit of range to test
1335 //TReal upp; // upper limit of range to test
1340 for (TInt j=0;j<10;j++)
1344 test(Math::Pow(res,x,y)==KErrNone);
1347 test(Math::Pow(res,xr,y)==KErrNone);
1349 test(Math::Pow(rres,x,yr)==KErrNone);
1350 test(testApprox(rres,res,1.0E-14));
1354 LOCAL_C void powtest3()
1356 Test the identity x**1=x
1364 for (TInt j=0;j<10;j++)
1368 test(Math::Pow(res,x,y)==KErrNone);
1369 test(testApprox(res,x,1.0E-15));
1373 LOCAL_C void powtest4()
1375 Test the identity (x**2)**(y/2)=x**y
1379 TReal res,xr,rres,x,y;
1383 TReal lowy=-98; // range for y
1385 for (TInt j=0;j<10;j++)
1388 randrng(y,lowy,uppy);
1389 test(Math::Pow(res,x,y)==KErrNone);
1391 test(Math::Pow(xr,x,yr)==KErrNone);
1393 test(Math::Pow(rres,xr,y)==KErrNone);
1394 test(testApprox(res,rres,5.0E-14));
1398 LOCAL_C void powtest5()
1400 Test the identity x**y=1/(x**(-y))
1407 test(Math::Pow(res,-2,-3.765)==KErrArgument);
1410 for (TInt j=0;j<10;j++)
1414 test(Math::Pow(res,x,y)==KErrNone);
1416 test(Math::Pow(rres,x,y)==KErrNone);
1418 test(testApprox(res,rres,5.0E-15));
1422 LOCAL_C void powtest6()
1424 Test specific ISO requirements on Pow()
1428 TInt n = sizeof(testpow_iso) / sizeof(POWERISO);
1429 for (i = 0; i < n; i++)
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));
1444 LOCAL_C void pow10test()
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
1454 test(Math::Pow10(res,-324)==KErrUnderflow);
1456 test(Math::Pow10(res,-400)==KErrUnderflow);
1458 test(Math::Pow10(res,309)==KErrOverflow);
1459 test(res==KPosInfTReal64);
1460 test(Math::Pow10(res,400)==KErrOverflow);
1461 test(res==KPosInfTReal64);
1464 TInt i=sizeof(pow10teste)/sizeof(POW10_TEST);
1468 test(Math::Pow10(res,pow10teste[j].num)==KErrNone);
1469 test(res==pow10teste[j].res);
1472 /* i=sizeof(pow10testa)/sizeof(POW10_TEST);
1476 test(Math::Pow10(res,pow10testa[j].num)==KErrNone);
1477 test(testApprox(res,pow10testa[j].res,1.0E-15));
1481 LOCAL_C void sintest1(TReal low,TReal upp)
1483 Test the identity sin(x)=sin(x/3)[3-4*(sin(x/3))**2] on the range low<=x<upp
1485 //TReal low; // lower limit of range to test
1486 //TReal upp; // upper limit of range to test
1491 for (TInt j=0;j<100;j++)
1494 test(Math::Sin(res,x)==KErrNone);
1496 test(Math::Sin(rres,x)==KErrNone);
1497 TReal err=rres*rres;
1501 test(testApprox(res,err,1.0E-12));
1505 LOCAL_C void sintest2()
1507 Test selected values (which may not give exact results)
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));
1525 TInt i=sizeof(testsin)/sizeof(TESTSINE);
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));
1536 //Added by AnnW, October 1996
1538 for (j=-(mult-1); j<mult; j++)
1540 test(Math::Sin(res, (4*j+1)*KPiBy2)==KErrNone);
1541 test(testApprox(res,1.0,1.0E-15));
1543 test(Math::Sin(res, (4*j+3)*KPiBy2)==KErrNone);
1544 test(testApprox(res,-1.0,1.0E-15));
1546 test(Math::Sin(res, ((4*j+1)*90)*KDegToRad)==KErrNone);
1547 test(testApprox(res,1.0,1.0E-15));
1549 test(Math::Sin(res, ((4*j+3)*90)*KDegToRad)==KErrNone);
1550 test(testApprox(res,-1.0,1.0E-15));
1555 LOCAL_C void sintest3()
1557 To test the identity sin(-x)=-sin(x) on the range [0,10*pi]
1565 for (TInt j=0;j<10;j++)
1568 test(Math::Sin(res,x)==KErrNone);
1570 test(Math::Sin(rres,x)==KErrNone);
1571 test(testApprox(rres,-res,1.0E-15));
1575 LOCAL_C void sintest4()
1577 To test the identity sin(x)=x for x<<1
1585 for (TInt j=0;j<10;j++)
1588 test(Math::Sin(res,x)==KErrNone);
1589 test(testApprox(res,x,1.0E-15));
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));
1599 LOCAL_C void sintest5()
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
1609 TInt mult=101; // can use up to 32768
1611 test(Math::Sin(res,KNegZeroTReal64)==KErrNone);
1614 for (j=-(mult-1); j<mult; j++)
1616 test(Math::Sin(res, j*KPi)==KErrNone);
1618 test(Math::Sin(res, j*(KPi+1.224E-16))==KErrNone);
1620 test(Math::Sin(res, (j*180)*KDegToRad)==KErrNone);
1624 test(Math::Sin(res, j*(KPi+1.0E-14))==KErrNone);
1630 LOCAL_C void costest1()
1632 To test the identity cos(x)=cos(x/3)[4*(cos(x/3)**2)-3] on the interval
1634 Added by AnnW, October 1996
1642 for (TInt j=0;j<100;j++)
1645 test(Math::Cos(res,x)==KErrNone);
1647 test(Math::Cos(rres,x)==KErrNone);
1648 test(testApprox(res,rres*(4*(rres*rres)-3),5.0E-13));
1652 LOCAL_C void costest2()
1654 Test selected values (which may not give exact results)
1655 Added by AnnW, October 1996
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));
1675 TInt i=sizeof(testcos)/sizeof(TESTCOSINE);
1679 test(Math::Cos(res,testcos[j].num)==KErrNone);
1680 test(testApprox(res,testcos[j].res,1.0E-15));
1683 test(Math::Cos(res,KNegZeroTReal64)==KErrNone);
1684 test(testApprox(res,1.0,1E-15));
1686 for (j=-(mult-1); j<mult; j++)
1688 test(Math::Cos(res, (2*j)*KPi)==KErrNone);
1689 test(testApprox(res,1.0,1.0E-15));
1691 test(Math::Cos(res, (2*j+1)*KPi)==KErrNone);
1692 test(testApprox(res,-1.0,1.0E-15));
1694 test(Math::Cos(res, (2*j)*(KPi+1.224E-16))==KErrNone);
1695 test(testApprox(res,1.0,1.0E-15));
1697 test(Math::Cos(res, (2*j+1)*(KPi+1.224E-16))==KErrNone);
1698 test(testApprox(res,-1.0,1.0E-15));
1700 test(Math::Cos(res, ((2*j)*180)*KDegToRad)==KErrNone);
1701 test(testApprox(res,1.0,1.0E-15));
1703 test(Math::Cos(res, ((2*j+1)*180)*KDegToRad)==KErrNone);
1704 test(testApprox(res,-1.0,1.0E-15));
1708 LOCAL_C void costest3()
1710 To test the identity cos(-x)=cos(x) on the range [0,10*pi]
1711 Added by AnnW, October 1996
1719 for (TInt j=0;j<10;j++)
1722 test(Math::Cos(res,x)==KErrNone);
1724 test(Math::Cos(rres,x)==KErrNone);
1725 test(testApprox(rres,res,1.0E-15));
1729 LOCAL_C void costest4()
1731 To test the identity cos(x)=1 for x<<1
1732 Added by Annw, October 1996
1740 for (TInt j=0;j<10;j++)
1743 test(Math::Cos(res,x)==KErrNone);
1744 test(testApprox(res,1.0,1.0E-15));
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));
1754 LOCAL_C void costest5()
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
1763 TInt mult=101; // can use up to 32768
1766 for (j=-(mult-1); j<mult; j++)
1768 test(Math::Cos(res, (2*j+1)*KPiBy2)==KErrNone);
1770 test(Math::Cos(res, (2*j+1)*KPiBy2+(j+1)*1.224E-16)==KErrNone);
1772 test(Math::Cos(res, (2*j+1)*90*KDegToRad)==KErrNone);
1776 test(Math::Sin(res, (2*j+1)*(KPiBy2+1.0E-14))==KErrNone);
1782 LOCAL_C void tantest1(TReal low,TReal upp)
1784 Test the identity tan(x)=(2*tan(x/2))/(1-tan(x/2)**2) on the range low<=x<upp
1786 //TReal low; // lower limit of range to test
1787 //TReal upp; // upper limit of range to test
1792 for (TInt j=0;j<100;j++)
1799 test(Math::Tan(res,x)==KErrNone);
1801 test(Math::Tan(rres,x)==KErrNone);
1802 TReal ex=(2*rres)/(1-rres*rres);
1803 test(testApprox(res,ex,1.0E-15));
1807 LOCAL_C void tantest2()
1809 To test tangent for specific arguments
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));
1830 TInt mult=101; // can use up to 32768
1831 TInt i=sizeof(testtan)/sizeof(TAN);
1834 test(Math::Tan(res,testtan[j].angle)==KErrNone);
1835 test(testApprox(res,testtan[j].result,1.0E-15));
1838 //Added by AnnW, October 1996
1839 for (j=-(mult-1); j<mult; j++)
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));
1847 // Check that signs are correct
1848 test(Math::Tan(res,KPiBy2+5E-16)==KErrNone);
1850 test(Math::Tan(res,KPiBy2-5E-16)==KErrNone);
1854 LOCAL_C void tantest3()
1856 To test the identity tan(-x)=-tan(x) on the range [-1.5,1.5]
1864 for (TInt j=0;j<10;j++)
1867 test(Math::Tan(res,x)==KErrNone);
1869 test(Math::Tan(rres,x)==KErrNone);
1870 test(testApprox(rres,-res,1.0E-15));
1874 LOCAL_C void tantest4()
1876 To test the identity tan(x)=x for x<<1
1884 for (TInt j=0;j<10;j++)
1887 test(Math::Tan(res,x)==KErrNone);
1888 test(testApprox(res,x,1.0E-15));
1891 // Check some denormals
1892 test(Math::Tan(res,5E-324)==KErrNone);
1894 test(Math::Tan(res,-1.234567891234E-315)==KErrNone);
1895 test(res==-1.234567891234E-315);
1898 LOCAL_C void tantest5()
1900 // To test that exact results are given for multiples of KPi
1901 // Added by AnnW, October 1996
1907 TInt mult=101; // can use up to 32768
1909 test(Math::Tan(res,KNegZeroTReal64)==KErrNone);
1910 test(res==KNegZeroTReal64);
1912 for (j=-(mult-1); j<mult; j++)
1914 test(Math::Tan(res, j*KPi)==KErrNone);
1916 test(Math::Tan(res, j*(KPi+1.224E-16))==KErrNone);
1918 test(Math::Tan(res, (j*180)*KDegToRad)==KErrNone);
1922 test(Math::Sin(res, j*(KPi+1.0E-14))==KErrNone);
1928 LOCAL_C void astest1(TReal low,TReal upp,TInt k,TInt cosflg)
1930 Tests random numbers in the range [low,upp] using the Taylor approximation
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
1940 for (TInt j=0;j<100;j++)
1944 test(Math::ACos(res,x)==KErrNone);
1946 test(Math::ASin(res,x)==KErrNone);
1947 TReal tres=taylor(x,k);
1950 test(testApprox(tres,res,5.0E-15));
1954 LOCAL_C void astest2()
1956 To test the identity arc sin(x)=x for x<<1
1964 for (TInt j=0;j<100;j++)
1967 test(Math::ASin(res,x)==KErrNone);
1968 test(testApprox(res,x,1.0E-15));
1971 // Check some denormals
1972 test(Math::ASin(res,5E-324)==KErrNone);
1974 test(Math::ASin(res,-8.912345678E-318)==KErrNone);
1975 test(res==-8.912345678E-318);
1978 LOCAL_C void astest3()
1980 To test the identity arc sin(-x)=-arc sin(x)
1988 for (TInt j=0;j<100;j++)
1991 test(Math::ASin(res,x)==KErrNone);
1993 test(Math::ASin(rres,y)==KErrNone);
1994 test(testApprox(rres,-res,1.0E-15));
1998 LOCAL_C void astest4(TInt k,TInt sgn)
2000 Test selected numbers
2002 //TInt k; // arc cosine flag
2003 //TInt sgn; // sign flag for range
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));
2030 test(Math::ASin(res,0.0)==KErrNone);
2032 test(Math::ASin(res,KNegZeroTReal64)==KErrNone);
2035 TInt i=sizeof(testas)/sizeof(TESTASC);
2036 for (TInt j=0;j<i;j++)
2038 // NB Results for comparison only given to 12 or 13 decimal places, so can't expect
2044 test(Math::ACos(res,testas[j].num)==KErrNone);
2045 test(testApprox(res,(KPiBy2-testas[j].res),1.0E-11));
2049 test(Math::ASin(res,testas[j].num)==KErrNone);
2050 test(testApprox(res,testas[j].res,1.0E-12));
2054 // Check some denormals for ACos()
2055 test(Math::ACos(res,5E-324)==KErrNone);
2057 test(Math::ACos(res,-9.87654E-320)==KErrNone);
2061 LOCAL_C void attest1()
2063 Random argument tests for x in the primary range, comparing the result with a
2064 Taylor series approximation
2070 TReal low=(-0.0625);
2072 for (TInt i=0;i<10;i++)
2075 test(Math::ATan(res,x)==KErrNone);
2076 TReal tres=tayatan(x);
2077 test(testApprox(res,tres,1.0E-15));
2081 LOCAL_C void attest2()
2083 Random argument tests for x outside the primary range, using the identity
2084 arctan(u)=arctan(v)+arctan[(u-v)/(1+uv)]
2088 TReal x,res,rres,atcnst;
2091 TReal upp=2.0-KSqt3;
2093 test(Math::ATan(atcnst,cnst)==KErrNone);
2094 for (TInt i=0;i<10;i++)
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));
2104 LOCAL_C void attest3()
2106 Check that the identity arctan(-x)=-arctan(x) holds
2113 for (TInt i=0;i<10;i++)
2116 test(Math::ATan(res,x)==KErrNone);
2118 test(Math::ATan(rres,x)==KErrNone);
2119 test(testApprox(res,-rres,1.0E-15));
2123 LOCAL_C void attest4()
2125 Check that the identity arctan(x)=x for Abs(x)<1 holds
2133 for (TInt i=0;i<10;i++)
2136 test(Math::ATan(res,x)==KErrNone);
2137 test(testApprox(res,x,1.0E-15));
2140 // Check some denormals
2141 test(Math::ATan(res,-5E-324)==KErrNone);
2143 test(Math::ATan(res,7.123E-322)==KErrNone);
2144 test(res==7.123E-322);
2147 LOCAL_C void attest5()
2149 Tests selected values
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);
2160 test(Math::ATan(res,KNegZeroTReal64)==KErrNone);
2162 test(Math::ATan(res,KPosInfTReal64)==KErrNone);
2164 test(Math::ATan(res,KNegInfTReal64)==KErrNone);
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);
2191 test(Math::ATan(res,0.0,1.0)==KErrNone);
2193 test(Math::ATan(res,0.0,-1.0)==KErrNone);
2195 test(Math::ATan(res,1.0,KPosInfTReal64)==KErrNone);
2197 test(Math::ATan(res,1.0,KNegInfTReal64)==KErrNone);
2199 test(Math::ATan(res,0.0,KPosInfTReal64)==KErrNone);
2201 test(Math::ATan(res,KPosInfTReal64,1.0)==KErrNone);
2203 test(Math::ATan(res,KNegInfTReal64,1.0)==KErrNone);
2205 test(Math::ATan(res,1.0,0.0)==KErrNone);
2207 test(Math::ATan(res,1.0,KNegZeroTReal64)==KErrNone);
2209 test(Math::ATan(res,KPosInfTReal64,-1.0)==KErrNone);
2211 test(Math::ATan(res,KNegInfTReal64,-1.0)==KErrNone);
2213 test(Math::ATan(res,-1.0,0.0)==KErrNone);
2215 test(Math::ATan(res,-1.0,KNegZeroTReal64)==KErrNone);
2217 test(Math::ATan(res,5E-324,10)==KErrNone);
2219 test(Math::ATan(res,1E+308,0.1)==KErrNone);
2222 TInt i=sizeof(testat2)/sizeof(TESTATAN2);
2223 for (TInt j=0;j<i;j++)
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));
2231 LOCAL_C void inttest1()
2233 Tests specific numbers
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);
2247 TInt i=sizeof(testint1)/sizeof(INT_TEST);
2248 for (TInt j=0;j<i;j++)
2250 test(Math::Int(res,testint1[j].num)==KErrNone);
2251 test(res==testint1[j].res);
2254 // Check some denormals
2255 test(Math::Int(res,5E-324)==KErrNone);
2257 test(Math::Int(res,1.45E-309)==KErrNone);
2261 LOCAL_C void inttest2()
2263 Tests specific numbers
2270 test(Math::Int(res,KNaNTReal64)==KErrArgument);
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));
2283 TInt i=sizeof(testint2)/sizeof(INTI_TEST);
2284 for (TInt j=0;j<i;j++)
2286 test(Math::Int(res,testint2[j].num)==KErrNone);
2287 test(res==testint2[j].res);
2290 // Check some denormals
2291 test(Math::Int(res,5E-324)==KErrNone);
2293 test(Math::Int(res,1.45E-309)==KErrNone);
2297 LOCAL_C void inttest3()
2299 Tests specific numbers
2306 test(Math::Int(res,KNaNTReal64)==KErrArgument);
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);
2319 TInt i=sizeof(testint3)/sizeof(INTL_TEST);
2320 for (TInt j=0;j<i;j++)
2322 test(Math::Int(res,testint3[j].num)==KErrNone);
2323 test(res==testint3[j].res);
2326 // Check some denormals
2327 test(Math::Int(res,5E-324)==KErrNone);
2329 test(Math::Int(res,1.45E-309)==KErrNone);
2333 LOCAL_C void inttest4()
2338 TReal trg,src=100.0;
2340 test.Start(_L("Math::Int()"));
2342 test(Math::Int(trg,src)==KErrNone);
2344 test(Math::Int(tint16,src)==KErrNone);
2346 test(Math::Int(tint32,src)==KErrNone);
2350 test(Math::Int(trg,src)==KErrNone);
2352 test(Math::Int(tint16,src)==KErrNone);
2354 test(Math::Int(tint32,src)==KErrNone);
2358 test(Math::Int(trg,src)==KErrNone);
2360 test(Math::Int(tint16,src)==KErrNone);
2362 test(Math::Int(tint32,src)==KErrNone);
2366 test(Math::Int(trg,src)==KErrNone);
2368 test(Math::Int(tint16,src)==KErrNone);
2370 test(Math::Int(tint32,src)==KErrNone);
2374 test(Math::Int(trg,src)==KErrNone);
2376 test(Math::Int(tint16,src)==KErrNone);
2378 test(Math::Int(tint32,src)==KErrNone);
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);
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);
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);
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);
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);
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);
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);
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);
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);
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);
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);
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);
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);
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);
2484 LOCAL_C void fractest1()
2486 Tests specific numbers
2493 test(Math::Frac(res,KNaNTReal64)==KErrArgument);
2494 test(Math::IsNaN(res));
2495 test(Math::Frac(res,KPosInfTReal64)==KErrOverflow);
2497 test(Math::Frac(res,KNegInfTReal64)==KErrOverflow);
2500 TInt i=sizeof(testfrac)/sizeof(FRAC_TEST);
2501 for (TInt j=0;j<i;j++)
2503 test(Math::Frac(res,testfrac[j].num)==KErrNone);
2504 TReal err=(res-testfrac[j].res);
2506 err/=testfrac[j].num; // NB num not res
2507 test(Abs(err)<1.0E-15);
2510 // Check some denormals
2511 test(Math::Frac(res,5E-324)==KErrNone);
2513 test(Math::Frac(res,1.23456789E-314)==KErrNone);
2514 test(res==1.23456789E-314);
2517 LOCAL_C void fractest2()
2520 test.Start(_L("Math::Frac()"));
2524 test(Math::Frac(trg,src)==KErrNone);
2528 test(Math::Frac(trg,src)==KErrNone);
2532 test(Math::Frac(trg,src)==KErrNone);
2536 test(Math::Frac(trg,src)==KErrNone);
2540 test(Math::Frac(trg,src)==KErrNone);
2544 test(Math::Frac(trg,src)==KErrNone);
2545 test(trg==0.998046875);
2548 test(Math::Frac(trg,src)==KErrNone);
2549 test(trg==-0.998046875);
2552 test(Math::Frac(trg,src)==KErrNone);
2553 test(trg==-0.00000000001);
2555 src=1000000000000.5;
2556 test(Math::Frac(trg,src)==KErrNone);
2559 src=1099511627776.0;
2560 src+=0.000244140625;
2561 test(Math::Frac(trg,src)==KErrNone);
2562 test(trg==0.000244140625);
2566 test(Math::Frac(trg,src)==KErrNone);
2571 test(Math::Frac(trg,src)==KErrNone);
2577 LOCAL_C void modtest1()
2579 Test modulo function using specified values
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));
2601 TInt i=sizeof(testmod)/sizeof(MOD_TEST);
2602 for (TInt j=0;j<i;j++)
2604 test(Math::Mod(res,testmod[j].num,testmod[j].mod)==KErrNone);
2605 test(testApprox(res,testmod[j].res,5.0E-13));
2608 // Check some denormals
2609 test(Math::Mod(res,K1Point2EMinus320Real64,K5EMinus321Real64)==KErrNone);
2610 test(res==K2EMinus321Real64);
2611 test(Math::Mod(res,K1Point234EMinus316Real64,K1Point234EMinus316Real64)==KErrNone);
2615 LOCAL_C void modtest2()
2617 Test modulo function for values which will be incorrect so return KErrTotalLossOfPrecision
2623 TInt i=sizeof(testmod2)/sizeof(MOD_TEST);
2624 for (TInt j=0;j<i;j++)
2626 test(Math::Mod(res,testmod2[j].num,testmod2[j].mod)==KErrTotalLossOfPrecision);
2627 test(Math::IsZero(res));
2631 LOCAL_C void DuplicateTest()
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
2639 test.Start(_L("ACos"));
2641 test(Math::ACos(inOut,inOut)==KErrNone);
2642 test(testApprox(inOut,2.094395102393,1.0E-13));
2644 test.Next(_L("ASin"));
2646 test(Math::ASin(inOut,inOut)==KErrNone);
2647 test(testApprox(inOut,-0.523598775598,6.0E-13));
2649 test.Next(_L("ATan"));
2651 test(Math::ATan(inOut,inOut)==KErrNone);
2652 test(testApprox(inOut,0.463647609001,5.0E-13));
2655 test(Math::ATan(inOut,inOut,another)==KErrNone);
2656 test(testApprox(inOut,-2.677945044589,5.0E-15));
2659 test(Math::ATan(inOut,another,inOut)==KErrNone);
2660 test(testApprox(inOut,2.677945044589,5.0E-15));
2662 test.Next(_L("Cos"));
2664 test(Math::Cos(inOut,inOut)==KErrNone);
2665 test(testApprox(inOut,0.540302305868,3.0E-13));
2667 test.Next(_L("Exp"));
2669 test(Math::Exp(inOut,inOut)==KErrNone);
2670 test(testApprox(inOut,1.648721270700,1.0E-13));
2672 test.Next(_L("Frac"));
2674 test(Math::Frac(inOut,inOut)==KErrNone);
2675 test(testApprox(inOut,0.123456789,2.0E-14));
2677 test.Next(_L("Int"));
2679 test(Math::Int(inOut,inOut)==KErrNone);
2682 test.Next(_L("Log"));
2684 test(Math::Log(inOut,inOut)==KErrNone);
2685 test(testApprox(inOut,-0.301029995664,7.0E-14));
2687 test.Next(_L("Ln"));
2689 test(Math::Ln(inOut,inOut)==KErrNone);
2690 test(testApprox(inOut,-0.693147180560,8.0E-14));
2692 test.Next(_L("Mod"));
2695 test(Math::Mod(inOut,inOut,another)==KErrNone);
2699 test(Math::Mod(inOut,another,inOut)==KErrNone);
2702 test.Next(_L("Pow"));
2705 test(Math::Pow(inOut,inOut,another)==KErrNone);
2706 test(inOut==-125.0);
2709 test(Math::Pow(inOut,another,inOut)==KErrNone);
2710 test(inOut==-125.0);
2712 test.Next(_L("Sin"));
2714 test(Math::Sin(inOut,inOut)==KErrNone);
2715 test(testApprox(inOut,0.84147098480790,5.0E-15));
2717 test.Next(_L("Round"));
2719 test(Math::Round(inOut,inOut,2)==KErrNone);
2720 test(testApprox(inOut,123.46,1.0E-15));
2722 test.Next(_L("Sqrt"));
2724 test(Math::Sqrt(inOut,inOut)==KErrNone);
2725 test(testApprox(inOut,7.280109889281,7.0E-14));
2727 test.Next(_L("Tan"));
2729 test(Math::Tan(inOut,inOut)==KErrNone);
2730 test(testApprox(inOut,1.557407724655,7.0E-14));
2735 LOCAL_C void specialtest()
2737 // Tests functions which test for specials
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));
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));
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));
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));
2770 void _matherr(TExcType aType)
2772 // Dummy function to handle exceptions
2776 test.Printf(_L("_matherr: Exception type %u handled\n"),TUint(aType));
2780 #define FSTCW(x) asm("mov eax, %0\nfstcw [eax]": : "i"(&x))
2781 #define FLDCW(x) asm("mov eax, %0\nfldcw [eax]": : "i"(&x))
2783 #define FSTCW(x) _asm fstcw x
2784 #define FLDCW(x) _asm fldcw x
2786 TInt16 cw=0; // must be global or GCC/GAS can't get the address!
2788 GLDEF_C TInt E32Main()
2791 #if defined (__X86__)
2793 test.Printf(_L("control word = 0x%x\n"),cw);
2794 cw=0x27f; // WINS value
2800 test.Start(_L("Assorted tests"));
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"));
2810 test.Next(_L("logtest"));
2812 test.Next(_L("lntest1"));
2814 test.Next(_L("lntest2"));
2816 test.Next(_L("lntest3"));
2818 test.Next(_L("lntest4"));
2821 test.Next(_L("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"));
2832 test.Next(_L("powtest1"));
2834 test.Next(_L("powtest2(.5,1.0)"));
2836 test.Next(_L("powtest2(1.0,1.0E33)"));
2837 powtest2(1.0,1.0E33);
2838 test.Next(_L("powtest3"));
2840 test.Next(_L("powtest4"));
2842 test.Next(_L("powtest5"));
2844 test.Next(_L("powtest6"));
2847 test.Next(_L("pow10test"));
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"));
2856 test.Next(_L("sintest3"));
2858 test.Next(_L("sintest4"));
2860 // test.Next(_L("sintest5")); // this test is no longer valid
2863 test.Next(_L("costest1"));
2865 test.Next(_L("costest2"));
2867 test.Next(_L("costest3"));
2869 test.Next(_L("costest4"));
2871 // test.Next(_L("costest5")); // this test is no longer valid
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"));
2882 test.Next(_L("tantest3"));
2884 test.Next(_L("tantest4"));
2886 // test.Next(_L("tantest5")); // this test is no longer valid
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"));
2895 test.Next(_L("astest3"));
2897 test.Next(_L("astest4(0,1)"));
2899 test.Next(_L("astest4(1,1)"));
2901 test.Next(_L("astest4(1,-1)"));
2904 test.Next(_L("attest1"));
2906 test.Next(_L("attest2"));
2908 test.Next(_L("attest3"));
2910 test.Next(_L("attest4"));
2912 test.Next(_L("attest5"));
2915 test.Next(_L("inttest1"));
2917 test.Next(_L("intitest2"));
2919 test.Next(_L("inttest3"));
2921 test.Next(_L("inttest4"));
2924 test.Next(_L("fractest1"));
2926 test.Next(_L("fractest2"));
2929 test.Next(_L("modtest1"));
2931 test.Next(_L("modtest2"));
2934 test.Next(_L("Test duplicate parameters"));
2937 test.Next(_L("Test Math::Is...() functions"));