diff -r c55016431358 -r 0a7b44b10206 symport/e32test/math/t_math.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/symport/e32test/math/t_math.cpp Thu Jun 25 15:59:54 2009 +0100 @@ -0,0 +1,2926 @@ +// Copyright (c) 1995-2009 Nokia Corporation and/or its subsidiary(-ies). +// All rights reserved. +// This component and the accompanying materials are made available +// under the terms of the License "Symbian Foundation License v1.0" +// which accompanies this distribution, and is available +// at the URL "http://www.symbianfoundation.org/legal/sfl-v10.html". +// +// Initial Contributors: +// Nokia Corporation - initial contribution. +// +// Contributors: +// +// Description: +// e32test\math\t_math.cpp +// T_MATH.CPP - Test routines for the maths functions +// NB When considering the accuracy of the results (i.e. the tolerance used in testApprox()) it +// should be remembered that the results expected are not always given to full precision and so +// the results obtained are mostly as accurate as can be expected. +// Overview: +// Test functionality of the Math library. +// API Information: +// Math. +// Details: +// - Test math's trigonometric, powers, roots, logs, modulo, sqrt, exp, +// Int, Frac, rounding for range of input values are as expected. +// - Test the returned error values are as expected when illegal math's +// operations are done. +// - Check the return value is KErrTotalLossOfPrecision when incorrect values +// is passed to modulo function. +// - Test for success when the same variable for both operands in some +// Math functions are used. +// Platforms/Drives/Compatibility: +// All. +// Assumptions/Requirement/Pre-requisites: +// Failures and causes: +// Base Port information: +// +// + +#include "t_math.h" +#include "t_vals.h" + +LOCAL_D RTest test(_L("T_MATH")); + +LOCAL_D TInt64 rseed = MAKE_TINT64(123456789,987654321); + +typedef struct + { + TReal num; // input number + TReal res; // expected result + } SQRT_TEST; + +LOCAL_D SQRT_TEST testsqrt[]= + { + {0.0,0.0}, // zero + {KNegZeroTReal64,KNegZeroTReal64}, + {1.0,1.0}, + {.64,.8}, + {.81,.9}, + {9,3}, + {25,5}, + {10000,100}, + {400,20}, + {6.25,2.5}, + {1E-98,1E-49}, + {1E-98,1E-49}, + {1E98,1E49}, + {1.0000000001,1.00000000005} + }; + +typedef struct + { + TReal num; // input number + TReal res; // expected result + } TESTLN; + +LOCAL_D TESTLN testln[]= + { + {.001,-6.9077552789821317}, + {.002,-6.2146080984221917}, + {.023,-3.7722610630529874}, + {.004,-5.5214609178622464}, + {.050,-2.9957322735539910}, + {.100,-2.3025850929940457}, + {.150,-1.8971199848858813}, + {.200,-1.6094379124341004}, + {.250,-1.3862943611198906}, + {.300,-1.2039728043259360}, + {.350,-1.0498221244986777}, + {.400,-0.9162907318741551}, + {.450,-0.7985076962177716}, + {.500,-0.6931471805599453}, + {.550,-0.5978370007556204}, + {.600,-0.5108256237659907}, + {.650,-0.4307829160924543}, + {.700,-0.3566749439387324}, + {.750,-0.2876820724517809}, + {.980,-0.0202027073175194}, + {.985,-0.0151136378100482}, + {.990,-0.0100503358535014}, + {.995,-0.0050125418235443}, + {.088,-2.4304184645039306}, + {1,0} + }; + +typedef struct + { + TReal val; // value for which the exponent is to be found + TReal result; // result + } EXP; + +LOCAL_D EXP testexp[]= + { + {4E-20,1.0}, + {5.4E-20,1.0}, + {0.0,1.0}, + {5E-324,1.0}, + }; + +typedef struct + { + TReal number; // number to be raised to a power + TReal power; // power + TReal result; // result + } POWER; + +LOCAL_D POWER testpow[]= + { + {45,3,91125.0}, + {-2,4,16}, + {2,-3,0.125}, + {-2,3,-8}, + {16,20,1.208925819614628E+24}, + }; + +// Added by AnnW, October 1996 +LOCAL_D const POWER testpowexact[]= + { + {0.0,1.0,0.0}, + {0,7,0}, + {0.0,16.0,0.0}, + {0.0,3.9271E-17,0.0}, + {-2,0,1}, + {1,0,1}, + {1.545243,0,1}, + {4.8,0.0,1.0}, + {195.0,0.0,1.0}, + {1.0E-7,0.0,1.0}, + {1.0,2.0,1.0}, + {1.0,1.0E-6,1.0}, + {1.0,1.0E+10,1.0}, + {-1.0,2.0,1.0}, + {-1.0,1.0000000001E+10,-1.0}, + {-1.0,1.0E+10,1.0}, + {1.593704102953967e+3,1.0,1.593704102953967e+3}, + {1.234567E+50,1.0,1.234567E+50}, + {1.2345678901234567E+146,1.0,1.2345678901234567E+146}, + {-7.6543210987654321E-53,1.0,-7.6543210987654321E-53}, + {0.0,2.0,0.0}, + {KNegZeroTReal64,4.0,0.0}, + {KPosInfTReal64,-2.0,0.0}, + {KNegInfTReal64,-2.0,0.0}, + {2.0,KNegInfTReal64,0.0}, + {-2.0,KNegInfTReal64,0.0}, + {0.5,KPosInfTReal64,0.0}, + {-0.5,KPosInfTReal64,0.0}, + {KPosInfTReal64,-5.0,0.0}, + {KPosInfTReal64,-6.0,0.0}, + {KNegInfTReal64,KNegInfTReal64,0.0}, + {KPosInfTReal64,KNegInfTReal64,0.0}, + }; + +// Check ISO requirements on Pow() +// +typedef struct + { + TReal number; // number to be raised to a power + TReal power; // power + TInt rc; // return value from Pow() + TReal result; // numerical result + } POWERISO; + +const TReal KPosZeroTReal64 = 0.0; + +LOCAL_D const POWERISO testpow_iso[] = + { + // pow(+/-0, y) returns +/-INF and raises the ''divide-by-zero'' + // floating-point exception for y an odd integer < 0 + { KPosZeroTReal64, -3.0, KErrOverflow, KPosInfTReal64 }, // 0 + { KNegZeroTReal64, -3.0, KErrOverflow, KNegInfTReal64 }, // 1 + + // pow(+/-0, y) returns +INF and raises the ''divide-by-zero'' + // floating-point exception for y < 0 and not an odd integer + { KPosZeroTReal64, -2.0, KErrOverflow, KPosInfTReal64 }, // 2 + { KNegZeroTReal64, -2.0, KErrOverflow, KPosInfTReal64 }, // 3 + + // pow(+/-0, y) returns +/-0 for y an odd integer > 0 + { KPosZeroTReal64, 3.0, KErrNone, KPosZeroTReal64 }, // 4 + { KNegZeroTReal64, 3.0, KErrNone, KNegZeroTReal64 }, // 5 + + // pow(+/-0, y) returns +0 for y > 0 and not an odd integer + { KPosZeroTReal64, 2.0, KErrNone, KPosZeroTReal64 }, // 6 + { KNegZeroTReal64, 2.0, KErrNone, KPosZeroTReal64 }, // 7 + + // pow(-1, +/-INF) returns 1 + { -1.0, KPosInfTReal64, KErrNone, 1.0 }, // 8 + { -1.0, KNegInfTReal64, KErrNone, 1.0 }, // 9 + + // pow(+1, y) returns 1 for any y, even a NaN + { 1.0, 1.0, KErrNone, 1.0 }, // 10 + { 1.0, 10.0, KErrNone, 1.0 }, // 11 + { 1.0, -1.0, KErrNone, 1.0 }, // 12 + { 1.0, -10.0, KErrNone, 1.0 }, // 13 + { 1.0, 0.5, KErrNone, 1.0 }, // 14 + { 1.0, -0.5, KErrNone, 1.0 }, // 15 + { 1.0, KPosInfTReal64, KErrNone, 1.0 }, // 16 + { 1.0, KNegInfTReal64, KErrNone, 1.0 }, // 17 + { 1.0, KNaNTReal64, KErrNone, 1.0 }, // 18 + + // pow(x, +/-0) returns 1 for any x, even a NaN + { 1.0, KPosZeroTReal64, KErrNone, 1.0 }, // 19 + { 1.0, KNegZeroTReal64, KErrNone, 1.0 }, // 20 + { 2.0, KPosZeroTReal64, KErrNone, 1.0 }, // 21 + { 2.0, KNegZeroTReal64, KErrNone, 1.0 }, // 22 + { 0.5, KPosZeroTReal64, KErrNone, 1.0 }, // 23 + { 0.5, KNegZeroTReal64, KErrNone, 1.0 }, // 24 + { -1.0, KPosZeroTReal64, KErrNone, 1.0 }, // 25 + { -1.0, KNegZeroTReal64, KErrNone, 1.0 }, // 26 + { -2.0, KPosZeroTReal64, KErrNone, 1.0 }, // 27 + { -2.0, KNegZeroTReal64, KErrNone, 1.0 }, // 28 + { -0.5, KPosZeroTReal64, KErrNone, 1.0 }, // 29 + { -0.5, KNegZeroTReal64, KErrNone, 1.0 }, // 30 + { KPosZeroTReal64, KPosZeroTReal64, KErrNone, 1.0 }, // 31 + { KPosZeroTReal64, KNegZeroTReal64, KErrNone, 1.0 }, // 32 + { KNegZeroTReal64, KPosZeroTReal64, KErrNone, 1.0 }, // 33 + { KNegZeroTReal64, KNegZeroTReal64, KErrNone, 1.0 }, // 34 + { KPosInfTReal64, KPosZeroTReal64, KErrNone, 1.0 }, // 35 + { KPosInfTReal64, KNegZeroTReal64, KErrNone, 1.0 }, // 36 + { KNegInfTReal64, KPosZeroTReal64, KErrNone, 1.0 }, // 37 + { KNegInfTReal64, KNegZeroTReal64, KErrNone, 1.0 }, // 38 + { KNaNTReal64, KPosZeroTReal64, KErrNone, 1.0 }, // 39 + { KNaNTReal64, KNegZeroTReal64, KErrNone, 1.0 }, // 40 + + // pow(x, y) returns a NaN and raises the ''invalid'' floating-point + // exception for finite x < 0 and finite non-integer y + { -1.0, 1.5, KErrArgument, KNaNTReal64 }, // 41 + + // pow(x, -INF) returns +INF for |x| < 1 + { 0.5, KNegInfTReal64, KErrOverflow, KPosInfTReal64 }, // 42 + { -0.5, KNegInfTReal64, KErrOverflow, KPosInfTReal64 }, // 43 + + // pow(x, -INF) returns +0 for |x| > 1 + { 2, KNegInfTReal64, KErrNone, KPosZeroTReal64 }, // 44 + { -2, KNegInfTReal64, KErrNone, KPosZeroTReal64 }, // 45 + { 4.5, KNegInfTReal64, KErrNone, KPosZeroTReal64 }, // 46 + { -4.5, KNegInfTReal64, KErrNone, KPosZeroTReal64 }, // 47 + + // pow(x, +INF) returns +0 for |x| < 1 + { .5, KPosInfTReal64, KErrNone, KPosZeroTReal64 }, // 48 + { -.5, KPosInfTReal64, KErrNone, KPosZeroTReal64 }, // 49 + + // pow(x, +INF) returns +INF for |x| > 1 + { 2, KPosInfTReal64, KErrOverflow, KPosInfTReal64 }, // 50 + { -2, KPosInfTReal64, KErrOverflow, KPosInfTReal64 }, // 51 + { 4.5, KPosInfTReal64, KErrOverflow, KPosInfTReal64 }, // 52 + { -4.5, KPosInfTReal64, KErrOverflow, KPosInfTReal64 }, // 53 + + // pow(-INF, y) returns -0 for y an odd integer < 0 + { KNegInfTReal64, -1, KErrNone, KNegZeroTReal64 }, // 54 + { KNegInfTReal64, -5, KErrNone, KNegZeroTReal64 }, // 55 + + // pow(-INF, y) returns +0 for y < 0 and not an odd integer + { KNegInfTReal64, -2, KErrNone, KPosZeroTReal64 }, // 56 + { KNegInfTReal64, -5.5, KErrNone, KPosZeroTReal64 }, // 57 + + // pow(-INF, y) returns -INF for y an odd integer > 0 + { KNegInfTReal64, 1, KErrOverflow, KNegInfTReal64 }, // 58 + { KNegInfTReal64, 5, KErrOverflow, KNegInfTReal64 }, // 59 + + // pow(-INF, y) returns +INF for y > 0 and not an odd integer + { KNegInfTReal64, 2, KErrOverflow, KPosInfTReal64 }, // 60 + { KNegInfTReal64, 5.5, KErrOverflow, KPosInfTReal64 }, // 61 + + // pow(+INF, y) returns +0 for y < 0 + { KPosInfTReal64, -1, KErrNone, KPosZeroTReal64 }, // 62 + { KPosInfTReal64, -2, KErrNone, KPosZeroTReal64 }, // 63 + { KPosInfTReal64, -5, KErrNone, KPosZeroTReal64 }, // 64 + { KPosInfTReal64, -5.5, KErrNone, KPosZeroTReal64 }, // 65 + + // pow(+INF, y) returns +INF for y > 0 + { KPosInfTReal64, 1, KErrOverflow, KPosInfTReal64 }, // 66 + { KPosInfTReal64, 2, KErrOverflow, KPosInfTReal64 }, // 67 + { KPosInfTReal64, 5, KErrOverflow, KPosInfTReal64 }, // 68 + { KPosInfTReal64, 5.5, KErrOverflow, KPosInfTReal64 }, // 69 + }; + +struct POW10_TEST + { + TInt num; // input number + TReal res; // expected result + }; + +LOCAL_D POW10_TEST pow10teste[]= + { + {300,1.0E300}, + {-162,1.0E-162}, + {-300,1.0E-300}, + {-99,1.0E-99}, +// }; + +//LOCAL_D POW10_TEST pow10testa[]= +// { + {99,1.0E99}, + {283,1.0E283}, + {-89,1.0E-89}, + {-200,1.0E-200}, + {-43,1.0E-43}, + {24,1.0E24}, + {-310,K1EMinus310Real64}, + {-323,K1EMinus323Real64} + }; + +typedef struct + { + TReal num; // input number + TReal res; // expected result + } TESTSINE; + +#pragma warning ( disable : 4204 ) // non-constant aggregate initializer +LOCAL_D TESTSINE testsin[]= + { + {0.5,0.4794255386042029}, // These were found using S3a + {1.2,0.9320390859672263}, + {1.6,0.9995736030415051}, + {28.6,-0.3199399618841981}, + {-18.3,0.5223085896267315}, + {KPi/4,0.7071067811865474}, + {3*KPi/4,0.7071067811865474}, + {5*KPi/4,-0.7071067811865474}, + {-KPi/4,-0.7071067811865474}, + {KPi/3,0.8660254037844387}, + {-KPi/3,-0.8660254037844387}, + {KPi/6,0.5}, + {-KPi/6,-0.5}, + {150*KDegToRad,0.5}, + {210*KDegToRad,-0.5}, +// {KPi+1.0E-15,-7.657143961860984E-16}, // loss of significance will limit accuracy here +// 2*(KPi+1.0E-15),1.5314287923721969e-15} + }; + +typedef struct + { + TReal num; // input number + TReal res; // expected result + } TESTCOSINE; + +LOCAL_D TESTCOSINE testcos[]= + { + {0.5,0.8775825618903727}, // These were found using S3a + {1.2,0.3623577544766734}, + {1.6,-0.0291995223012888}, + {28.6,-0.9474378189567576}, + {-18.3,0.8527565521308730}, + {KPi/4,0.7071067811865474}, + {3*KPi/4,-0.7071067811865474}, + {5*KPi/4,-0.7071067811865474}, + {-KPi/4,0.7071067811865474}, + {KPi/6,0.8660254037844387}, + {5*KPi/6,-0.8660254037844387}, + {KPi/3,0.5}, + {4*KPi/3,-0.5}, + {120*KDegToRad,-0.5}, + {300*KDegToRad,0.5}, + {KPi+1.0E-15,-1.0}, + {2*(KPi+1.0E-15),1.0} + }; + +typedef struct + { + TReal angle; // angle for which the tangent is to be found + TReal result; // result + } TAN; + +LOCAL_D TAN testtan[]= + { + {KPi/4,1.0}, + {-KPi/4,-1.0}, + {45*KDegToRad,1.0}, + {KPi/3,1.732050807568877}, // Added by AnnW - Calculated on S3a + {2*KPi/3,-1.732050807568878}, // + {KPi/6,0.5773502691896257}, // + {-KPi/6,-0.5773502691896257}, // + {89*KDegToRad,57.28996163075913}, // these two should be the same! + {91*KDegToRad,-57.28996163075955}, // + {4E-123,4E-123}, + {-4E-123,-4E-123}, + }; + +typedef struct + { + TReal num; // input number + TReal res; // expected result + } TESTASC; + +LOCAL_D TESTASC testas[]= + { + {.75,.848062078981}, + {.82,.961411018764}, + {.87,1.055202320549}, + {.89,1.097345169523}, + {.90,1.119769514999}, + {.92,1.168080485214}, + {.94,1.222630305522}, + {.96,1.287002217587}, + {.99,1.429256853470}, + {1.0,1.570796326795}, + {0.0,0}, + {-1.0, -90.0*KDegToRad}, + {0.5,30.0*KDegToRad} + }; + +typedef struct + { + TReal num1; // Divisor + TReal num2; // Divand + TReal res; // expected result + } TESTATAN2; + +LOCAL_D TESTATAN2 testat2[]= + { + {5E-49,7E306,0.0}, // underflow, zero returned + {5E49,7E-306,KPiBy2}, // overflow, pi/2 returned + {0.45,0.5,0.732815101787}, + {0.12,0.3,0.380506377112}, + {0.3,0.0,KPiBy2}, // overflow, pi/2 returned + {-0.3,0.0,-KPiBy2}, // overflow, -pi/2 returned + {0.0,0.3,0.0}, + }; +#pragma warning ( default : 4204 ) + +typedef struct + { + TReal num; // input number + TReal res; // expected result + } INT_TEST; + +LOCAL_D INT_TEST testint1[]= + { + {1.0,1.0}, + {1.47934,1.0}, + {-72.86345,-72.0}, + {-734.9999,-734.0}, + {4855.9974,4855.0}, + {232478.35,232478.0}, + {0.029345,0.0}, + {0.9437,0.0}, + {-0.2634,0.0}, + {-0.98976,0.0}, + {32769.36946,32769.0}, + {-32774.997937,-32774.0}, + {8738465.38749,8738465.0}, + {-2348645.34965,-2348645.0}, + {2147483655.7565,2147483655.0}, + {-2147483657.89453,-2147483657.0}, + {2374843546.34E2,2374843546.34E2}, + {34780656.37643E12,34780656.37643E12}, + {-2374843546.34E2,-2374843546.34E2}, + {-34780656.37643E12,-34780656.37643E12}, + {468650.3874E47,468650.3874E47}, + {-4965.5987636E34,-4965.5987636E34}, + }; + +typedef struct + { + TReal num; // input number + TInt16 res; // expected result + } INTI_TEST; + +LOCAL_D INTI_TEST testint2[]= + { + {1.0,1}, + {1.47934,1}, + {-72.86345,-72}, + {-734.9999,-734}, + {4855.9974,4855}, + {0.029345,0}, + {0.9437,0}, + {-0.2634,0}, + {-0.98976,0}, + {3234.56,3234}, + {4698.435,4698}, + {-32767.47658,-32767}, + {32767.9830857,32767}, + {-32768.47658,-32767-1} + }; + +typedef struct + { + TReal num; // input number + TInt32 res; // expected result + } INTL_TEST; + +LOCAL_D INTL_TEST testint3[]= + { + {1.0,1l}, + {1.47934,1l}, + {-72.86345,-72l}, + {-734.9999,-734l}, + {4855.9974,4855l}, + {0.029345,0l}, + {0.9437,0l}, + {-0.2634,0l}, + {-0.98976,0l}, + {3234.56,3234l}, + {4698.435,4698l}, + {-32767.47658,-32767l}, + {32767.9830857,32767l}, + {32769.36946,32769l}, + {-32774.997937,-32774l}, + {64835903.74605,64835903l}, + {-46652024.393,-46652024l}, + {2147483647.34576,2147483647l}, + {-2147483647.9501,-2147483647l}, + {-2147483648.00,0x80000000l}, + {-2147483648.6843,0x80000000l} + }; + +typedef struct + { + TReal num; // input number + TReal res; // expected result + } FRAC_TEST; + +LOCAL_D FRAC_TEST testfrac[]= + { + {0.0,0.0}, + {KNegZeroTReal64,0.0}, + {1.0,0.0}, + {1.47934,.47934}, + {-72.86345,-.86345}, + {-734.9999,-.9999}, + {4855.9974,.9974}, + {232478.35,.35}, + {0.029345,.029345}, + {0.9437,0.9437}, + {-0.2634,-.2634}, + {-0.98976,-.98976}, + {32769.36946,.36946}, + {-32774.997937,-0.997937}, + {8738465.38749,0.38749}, + {-2348645.34965,-0.34965}, + {2147483655.7565,0.7565}, + {-2147483657.89453,-.89453}, + {2374843546.34E2,0.0}, + {34780656.37643E12,0.0}, + {-2374843546.34E2,0.0}, + {-34780656.37643E12,0.0}, + {468650.3874E47,0.0}, + {-4965.5987636E34,0.0} + }; + +typedef struct + { + TReal num; // input number + TReal mod; // modulo + TReal res; // expected result + } MOD_TEST; + +LOCAL_D MOD_TEST testmod[]= + { + {4.0,2.0,0.0}, + {3.0,2.0,1.0}, + {56.847,2.3,1.647}, + {-65.6478,.65,-.6478}, + {-6858.78432,-87.5323,-31.26492}, + {7665.140215,-34.98,4.520215}, + {.4645,1.0,0.4645}, + {-.246,1.0,-.246}, + {1.0,KPosInfTReal64,1.0}, + {1.0,KNegInfTReal64,1.0}, + {1.0E17,8.0,0.0}, + // + {1.0,3.0,1.0}, //0 + {2.0,3.0,2.0}, + {4.0,3.0,1.0}, + {8.0,3.0,2.0}, + {16.0,3.0,1.0}, + {32.0,3.0,2.0}, + {64.0,3.0,1.0}, + {128.0,3.0,2.0}, + {256.0,3.0,1.0}, + {512.0,3.0,2.0}, + {1024.0,3.0,1.0}, //10 + {2048.0,3.0,2.0}, + {4096.0,3.0,1.0}, + {8192.0,3.0,2.0}, + {16384.0,3.0,1.0}, + {32768.0,3.0,2.0}, + {65536.0,3.0,1.0}, + {131072.0,3.0,2.0}, + {262144.0,3.0,1.0}, + {524288.0,3.0,2.0}, + {1048576.0,3.0,1.0}, //20 + {2097152.0,3.0,2.0}, + {4194304.0,3.0,1.0}, + {8388608.0,3.0,2.0}, + {16777216.0,3.0,1.0}, + {33554432.0,3.0,2.0}, + {67108864.0,3.0,1.0}, + {134217728.0,3.0,2.0}, + {268435456.0,3.0,1.0}, + {536870912.0,3.0,2.0}, + {1073741824.0,3.0,1.0}, //30 + {2147483648.0,3.0,2.0}, + {4294967296.0,3.0,1.0}, + {8589934592.0,3.0,2.0}, + {17179869184.0,3.0,1.0}, + {34359738368.0,3.0,2.0}, + {68719476736.0,3.0,1.0}, + {137438953472.0,3.0,2.0}, + {274877906944.0,3.0,1.0}, + {549755813888.0,3.0,2.0}, + {1099511627776.0,3.0,1.0}, //40 + {2199023255552.0,3.0,2.0}, + {4398046511104.0,3.0,1.0}, + {8796093022208.0,3.0,2.0}, + {17592186044416.0,3.0,1.0}, + {35184372088832.0,3.0,2.0}, + {70368744177664.0,3.0,1.0}, + {140737488355328.0,3.0,2.0}, + {281474976710656.0,3.0,1.0}, + {562949953421312.0,3.0,2.0}, + {1125899906842624.0,3.0,1.0}, //50 + {2251799813685248.0,3.0,2.0}, + {4503599627370496.0,3.0,1.0}, + {9007199254740992.0,3.0,2.0}, + {18014398509481984.0,3.0,1.0}, + {6.626176E-34,299792458.0,6.626176E-34}, + {-1.6022E-19,6.022045E23,-1.6022E-19}, + {0.0,2.71828182845904524,0.0} + }; + +// expected result is unused in following - will be zero in all cases +LOCAL_D MOD_TEST testmod2[]= + { + {1.0E17,7.9,0.0}, + {1.0E100,4.0,0.0}, + {KMaxTReal64,5.0,0.0}, + {-KMaxTReal64,5.0,0.0}, + {0.125,1.0E-17,0.0}, + {36028797019963968.0,2.0,0.0}, // 2**55,2**1 + // + {36028797019963968.0,3.0,0.0}, //55 + {72057594039927936.0,3.0,0.0}, + {144115188079855872.0,3.0,0.0}, + {288230376159711744.0,3.0,0.0}, + }; + +TInt testApprox(TReal aFound,TReal aExpect,TReal aTol) +// +// Tests relative error, i.e. whether (aFound-aExpect)/aFound <= aTol +// + { + + TRealX diff,check,l,r,t; + l.Set(aFound); + r.Set(aExpect); + t.Set(aTol); + if (l.Mult(check,t)==KErrUnderflow) + { + l*=TRealX(1.0E20); + r*=TRealX(1.0E20); + } + diff=l-r; + if (diff.IsZero()) + return ETrue; + if (!l.IsZero()) + diff.DivEq(l); + if (Abs(TReal(diff))<=aTol) + return ETrue; + return EFalse; + } + +LOCAL_C void randrng(TReal& pret,TReal& llim,TReal& ulim) +/* +Returns a random number in the range [llim,ulim] +*/ + { + + pret=Math::FRand(rseed); + pret*=ulim-llim; + pret+=llim; + } + +LOCAL_C TReal taylor(TReal x,TInt k) +/* +Evaluate the Taylor series approximation to arc sine up to terms of order k +*/ + //TReal x; // argument + //TInt k; // Highest order term + { + + TInt i,j; + TReal den,num,res,term,di; + + den=1; + num=1; + term=0; + for (i=1;i<=k;i+=2) + { + for (j=2;j0;i--) + { + tot+=TRealX(sign)/TRealX(i); + tot*=xx; + sign=-sign; + } + TReal tot2=(TReal)tot; + test(Math::Ln(res,x)==KErrNone); + test(testApprox(res,tot2,1.0E-15)); + } + } + +LOCAL_C void lntest3() +/* +Test numbers in the range sqrt(.5) to 15/16, using the identity +ln(x)=ln(17x/16)-ln(17/16) +*/ + { + + TReal x,cnstln,cnstlnx,res; + + TReal low=KSqhf; + TReal upp=15.0/16.0; + TReal cnst=17.0/16.0; + test(Math::Ln(cnstln,cnst)==KErrNone); + for (TInt j=0;j<10;j++) + { + randrng(x,low,upp); + test(Math::Ln(res,x)==KErrNone); + TReal num=cnst*x; + test(Math::Ln(cnstlnx,num)==KErrNone); + test(testApprox(res,(cnstlnx-cnstln),1.0E-15)); + } + } + +LOCAL_C void lntest4() +/* +Test numbers in the range 16 to 240 using the identity ln(x*x)=2ln(x) +*/ + { + + TReal cnstlnx,res; + + TReal low=16.0; + TReal upp=240.0; + TReal x=16.0; + test(Math::Ln(res,-1)==KErrArgument); + for (TInt j=0;j<10;j++) + { + randrng(x,low,upp); + TReal num=x*x; + test(Math::Ln(res,num)==KErrNone); + test(Math::Ln(cnstlnx,x)==KErrNone); + test(testApprox(res,2*cnstlnx,1.0E-15)); + } + } + +LOCAL_C void exptest1() +/* +To test exponent for specific values +*/ + { + + TReal res; + + // test errors + test(Math::Exp(res,KNaNTReal64)==KErrArgument); + test(Math::IsNaN(res)); + test(Math::Exp(res,KPosInfTReal64)==KErrOverflow); + test(res==KPosInfTReal64); + test(Math::Exp(res,709.8)==KErrOverflow); + test(res==KPosInfTReal64); + test(Math::Exp(res,KNegInfTReal64)==KErrUnderflow); + test(Math::IsZero(res)); + test(Math::Exp(res,-745.2)==KErrUnderflow); + test(Math::IsZero(res)); + + TInt i=sizeof(testexp)/sizeof(EXP); + for (TInt j=0;j0); + } + +LOCAL_C void tantest3() +/* +To test the identity tan(-x)=-tan(x) on the range [-1.5,1.5] +*/ + { + + TReal x,res,rres; + + TReal low=(-1.5); + TReal upp=1.5; + for (TInt j=0;j<10;j++) + { + randrng(x,low,upp); + test(Math::Tan(res,x)==KErrNone); + x*=(-1); + test(Math::Tan(rres,x)==KErrNone); + test(testApprox(rres,-res,1.0E-15)); + } + } + +LOCAL_C void tantest4() +/* +To test the identity tan(x)=x for x<<1 +*/ + { + + TReal x,res; + + TReal low=1E-90; + TReal upp=1E-10; + for (TInt j=0;j<10;j++) + { + randrng(x,low,upp); + test(Math::Tan(res,x)==KErrNone); + test(testApprox(res,x,1.0E-15)); + } + + // Check some denormals + test(Math::Tan(res,5E-324)==KErrNone); + test(res==5E-324); + test(Math::Tan(res,-1.234567891234E-315)==KErrNone); + test(res==-1.234567891234E-315); + } +/* +LOCAL_C void tantest5() + +// To test that exact results are given for multiples of KPi +// Added by AnnW, October 1996 + + { + + TReal res; + TInt j; + TInt mult=101; // can use up to 32768 + + test(Math::Tan(res,KNegZeroTReal64)==KErrNone); + test(res==KNegZeroTReal64); + + for (j=-(mult-1); j