os/kernelhwsrv/kernel/eka/include/e32math.h
changeset 0 bde4ae8d615e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/os/kernelhwsrv/kernel/eka/include/e32math.h	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,500 @@
     1.4 +// Copyright (c) 1995-2009 Nokia Corporation and/or its subsidiary(-ies).
     1.5 +// All rights reserved.
     1.6 +// This component and the accompanying materials are made available
     1.7 +// under the terms of the License "Eclipse Public License v1.0"
     1.8 +// which accompanies this distribution, and is available
     1.9 +// at the URL "http://www.eclipse.org/legal/epl-v10.html".
    1.10 +//
    1.11 +// Initial Contributors:
    1.12 +// Nokia Corporation - initial contribution.
    1.13 +//
    1.14 +// Contributors:
    1.15 +//
    1.16 +// Description:
    1.17 +// e32\include\e32math.h
    1.18 +// 
    1.19 +//
    1.20 +
    1.21 +#ifndef __E32MATH_H__
    1.22 +#define __E32MATH_H__
    1.23 +#include <e32std.h>
    1.24 +
    1.25 +
    1.26 +/**
    1.27 +@publishedAll
    1.28 +@released
    1.29 +*/
    1.30 +const TInt KMaxPrecision=15;
    1.31 +
    1.32 +/**
    1.33 +@publishedAll
    1.34 +@released
    1.35 +
    1.36 +This constant specifies the maximum number of significant digits available with floating 
    1.37 +point computations. Rounding and string formatting methods will not use more digits than this.
    1.38 +*/
    1.39 +const TInt KPrecisionLimit=12;
    1.40 +
    1.41 +/**
    1.42 +@publishedAll
    1.43 +@released
    1.44 +
    1.45 +Let D be the set of real numbers exactly representable by an IEEE-754 'double'
    1.46 +For any positive integer n let X_n be the set of real numbers with an exact
    1.47 +decimal representation using n significant digits.
    1.48 +Let r_n : D -> X_n be defined by r_n(x)=y such that
    1.49 +|y-x| = inf { |z-x| : z in X_n }
    1.50 +and (in the case where two such y exist) that the last significant digit in the
    1.51 +decimal representation of y is even.
    1.52 +This constant is the least n such that r_n is injective.
    1.53 +*/
    1.54 +const TInt KIEEEDoubleInjectivePrecision=17;
    1.55 +
    1.56 +/**
    1.57 +@publishedAll
    1.58 +@released
    1.59 +*/
    1.60 +const TInt KMantissaBits=53;
    1.61 +/**
    1.62 +@publishedAll
    1.63 +@released
    1.64 +*/
    1.65 +const TInt KMaxExponent=1023;
    1.66 +/**
    1.67 +@publishedAll
    1.68 +@released
    1.69 +*/
    1.70 +const TInt KExponentBias=1022;
    1.71 +/**
    1.72 +@publishedAll
    1.73 +@released
    1.74 +*/
    1.75 +const TInt KSpecialExponent=2047;
    1.76 +//
    1.77 +
    1.78 +
    1.79 +/**
    1.80 +@publishedAll
    1.81 +@released
    1.82 +
    1.83 +The maximum exponent for a 32-bit floating point number.
    1.84 +*/
    1.85 +const TInt KTReal32MaxExponent=128;			// changed from 127
    1.86 +
    1.87 +
    1.88 +/**
    1.89 +@publishedAll
    1.90 +@released
    1.91 +
    1.92 +The minimum exponent for a 32-bit floating point number.
    1.93 +*/
    1.94 +const TInt KTReal32MinExponent=-125;
    1.95 +/**
    1.96 +@publishedAll
    1.97 +@released
    1.98 +*/
    1.99 +const TInt KTReal32ExponentBias=126;
   1.100 +/**
   1.101 +@publishedAll
   1.102 +@released
   1.103 +*/
   1.104 +const TInt KTReal32SpecialExponent=255;		// changed from KTReal32ExponentBad
   1.105 +
   1.106 +
   1.107 +/**
   1.108 +@publishedAll
   1.109 +@released
   1.110 +
   1.111 +A zero exponent value for a 32-bit floating point number. 
   1.112 +*/
   1.113 +const TInt KTReal32ZeroExponent=0;
   1.114 +//
   1.115 +
   1.116 +
   1.117 +/**
   1.118 +@publishedAll
   1.119 +@released
   1.120 +
   1.121 +The maximum exponent for a 64-bit floating point number.
   1.122 +*/
   1.123 +const TInt KTReal64MaxExponent=1024;		// changed from 1023
   1.124 +
   1.125 +
   1.126 +/**
   1.127 +@publishedAll
   1.128 +@released
   1.129 +
   1.130 +The minimum exponent for a 64-bit floating point number.
   1.131 +*/
   1.132 +const TInt KTReal64MinExponent=-1021;
   1.133 +
   1.134 +
   1.135 +/**
   1.136 +@publishedAll
   1.137 +@released
   1.138 +*/
   1.139 +const TInt KTReal64ExponentBias=1022;
   1.140 +
   1.141 +
   1.142 +/**
   1.143 +@publishedAll
   1.144 +@released
   1.145 +*/
   1.146 +const TInt KTReal64SpecialExponent=2047;	// changed from KTReal64BadExponent
   1.147 +
   1.148 +
   1.149 +/**
   1.150 +@publishedAll
   1.151 +@released
   1.152 +
   1.153 +A zero exponent value for a 64-bit floating point number. 
   1.154 +*/
   1.155 +const TInt KTReal64ZeroExponent=0;
   1.156 +//
   1.157 +
   1.158 +
   1.159 +/**
   1.160 +@publishedAll
   1.161 +@released
   1.162 +
   1.163 +The minimum value of a 64-bit floating point number.
   1.164 +*/
   1.165 +const TReal KMinTReal=2.2250738585072015E-308;	// changed from TReal64
   1.166 +
   1.167 +
   1.168 +/**
   1.169 +@publishedAll
   1.170 +@released
   1.171 +
   1.172 +The maximum value of a 64-bit floating point number.
   1.173 +*/
   1.174 +const TReal KMaxTReal=1.7976931348623157E+308;	//
   1.175 +//
   1.176 +
   1.177 +
   1.178 +/**
   1.179 +@publishedAll
   1.180 +@released
   1.181 +
   1.182 +The minimum value of a 32-bit floating point number.
   1.183 +*/
   1.184 +const TReal32 KMinTReal32=1.17549435E-38f;
   1.185 +
   1.186 +
   1.187 +/**
   1.188 +@publishedAll
   1.189 +@released
   1.190 +
   1.191 +The maximum value of a 32-bit floating point number.
   1.192 +*/
   1.193 +const TReal32 KMaxTReal32=3.4028234663852885981170418348452e+38f;
   1.194 +//
   1.195 +
   1.196 +
   1.197 +/**
   1.198 +@publishedAll
   1.199 +@released
   1.200 +
   1.201 +The minimum value of a 64-bit floating point number.
   1.202 +*/
   1.203 +const TReal64 KMinTReal64=2.2250738585072015E-308;
   1.204 +
   1.205 +
   1.206 +/**
   1.207 +@publishedAll
   1.208 +@released
   1.209 +
   1.210 +The maximum value of a 64-bit floating point number.
   1.211 +*/
   1.212 +const TReal64 KMaxTReal64=1.7976931348623157E+308;
   1.213 +//
   1.214 +
   1.215 +
   1.216 +/**
   1.217 +@publishedAll
   1.218 +@released
   1.219 +*/
   1.220 +const TReal KSqhf=0.70710678118654752440;
   1.221 +
   1.222 +
   1.223 +/**
   1.224 +@publishedAll
   1.225 +@released
   1.226 +
   1.227 +Log 2 to the base "e".
   1.228 +*/
   1.229 +const TReal KRln2=1.4426950408889634;
   1.230 +
   1.231 +
   1.232 +/**
   1.233 +@publishedAll
   1.234 +@released
   1.235 +
   1.236 +Log 10 to the base "e".
   1.237 +*/
   1.238 +const TReal KRln10=0.4342944819032518;
   1.239 +
   1.240 +
   1.241 +/**
   1.242 +@publishedAll
   1.243 +@released
   1.244 +
   1.245 +Log 2 to the base 10.
   1.246 +*/
   1.247 +const TReal KRlg2=0.3010299956639812;
   1.248 +
   1.249 +
   1.250 +/**
   1.251 +@publishedAll
   1.252 +@released
   1.253 +
   1.254 +The mathematical constant Pi.
   1.255 +*/
   1.256 +const TReal KPi=3.1415926535897932;
   1.257 +
   1.258 +
   1.259 +/**
   1.260 +@publishedAll
   1.261 +@released
   1.262 +
   1.263 +The reciprocal of the mathematical constant Pi. 
   1.264 +*/
   1.265 +const TReal KPiInv=0.3183098861837907;
   1.266 +
   1.267 +
   1.268 +/**
   1.269 +@publishedAll
   1.270 +@released
   1.271 +
   1.272 +The mathematical constant Pi divided by 2.
   1.273 +*/
   1.274 +const TReal KPiBy2=1.5707963267948966;
   1.275 +
   1.276 +
   1.277 +/**
   1.278 +@publishedAll
   1.279 +@released
   1.280 +
   1.281 +Not used.
   1.282 +*/
   1.283 +const TReal KDrpi=0.6366197723675813;
   1.284 +
   1.285 +
   1.286 +/**
   1.287 +@publishedAll
   1.288 +@released
   1.289 +
   1.290 +The square root of 3.
   1.291 +*/
   1.292 +const TReal KSqt3=1.7320508075688773;
   1.293 +
   1.294 +
   1.295 +/**
   1.296 +@publishedAll
   1.297 +@released
   1.298 +*/
   1.299 +const TReal KMsq3=0.2679491924311227;
   1.300 +
   1.301 +
   1.302 +/**
   1.303 +@publishedAll
   1.304 +@released
   1.305 +
   1.306 +The multiplying factor to convert radians to degrees.
   1.307 +*/
   1.308 +const TReal KRadToDeg=57.29577951308232;
   1.309 +
   1.310 +
   1.311 +/**
   1.312 +@publishedAll
   1.313 +@released
   1.314 +
   1.315 +The multiplying factor to convert degrees to radians.
   1.316 +*/
   1.317 +const TReal KDegToRad=0.017453292519943296;
   1.318 +
   1.319 +
   1.320 +
   1.321 +
   1.322 +class TRealX
   1.323 +/**
   1.324 +@publishedAll
   1.325 +@released
   1.326 +
   1.327 +A class encapsulating an extended precision real value.
   1.328 +
   1.329 +This class provides 64 bit precision and a dynamic range of approximately
   1.330 +1E-9863 to 1E+9863. All member functions are optimized for speed.
   1.331 +*/
   1.332 +	{
   1.333 +public:
   1.334 +	enum TRealXOrder {ELessThan=1,EEqual=2,EGreaterThan=4,EUnordered=8};
   1.335 +public:
   1.336 +	IMPORT_C TRealX();
   1.337 +	IMPORT_C TRealX(TInt aInt);
   1.338 +	IMPORT_C TRealX(TUint aInt);
   1.339 +	IMPORT_C TRealX(TUint aExp, TUint aMantHi, TUint aMantLo);
   1.340 +	IMPORT_C TRealX(const TInt64 &aInt);
   1.341 +	IMPORT_C TRealX(TReal32 aReal) __SOFTFP;
   1.342 +	IMPORT_C TRealX(TReal64 aReal) __SOFTFP;
   1.343 +	IMPORT_C TRealX &operator=(TInt aInt);
   1.344 +	IMPORT_C TRealX &operator=(TUint aInt);
   1.345 +	IMPORT_C TRealX &operator=(const TInt64& aInt);
   1.346 +	IMPORT_C TRealX &operator=(TReal32 aReal) __SOFTFP;
   1.347 +	IMPORT_C TRealX &operator=(TReal64 aReal) __SOFTFP;
   1.348 +	IMPORT_C TInt Set(TInt aInt);
   1.349 +	IMPORT_C TInt Set(TUint aInt);
   1.350 +	IMPORT_C TInt Set(const TInt64& aInt);
   1.351 +	IMPORT_C TInt Set(TReal32 aReal) __SOFTFP;
   1.352 +	IMPORT_C TInt Set(TReal64 aReal) __SOFTFP;
   1.353 +	IMPORT_C operator TInt() const;
   1.354 +	IMPORT_C operator TUint() const;
   1.355 +	IMPORT_C operator TInt64() const;
   1.356 +	IMPORT_C operator TReal32() const __SOFTFP;
   1.357 +	IMPORT_C operator TReal64() const __SOFTFP;
   1.358 +	IMPORT_C TInt GetTReal(TReal32 &aVal) const;
   1.359 +	IMPORT_C TInt GetTReal(TReal64 &aVal) const;
   1.360 +	IMPORT_C void SetZero(TBool aNegative=EFalse);
   1.361 +	IMPORT_C void SetNaN();
   1.362 +	IMPORT_C void SetInfinite(TBool aNegative);
   1.363 +	IMPORT_C TBool IsZero() const;
   1.364 +	IMPORT_C TBool IsNaN() const;
   1.365 +	IMPORT_C TBool IsInfinite() const;
   1.366 +	IMPORT_C TBool IsFinite() const;
   1.367 +	IMPORT_C const TRealX &operator+=(const TRealX &aVal);
   1.368 +	IMPORT_C const TRealX &operator-=(const TRealX &aVal);
   1.369 +	IMPORT_C const TRealX &operator*=(const TRealX &aVal);
   1.370 +	IMPORT_C const TRealX &operator/=(const TRealX &aVal);
   1.371 +	IMPORT_C const TRealX &operator%=(const TRealX &aVal);
   1.372 +	IMPORT_C TInt AddEq(const TRealX &aVal);
   1.373 +	IMPORT_C TInt SubEq(const TRealX &aVal);
   1.374 +	IMPORT_C TInt MultEq(const TRealX &aVal);
   1.375 +	IMPORT_C TInt DivEq(const TRealX &aVal);
   1.376 +	IMPORT_C TInt ModEq(const TRealX &aVal);
   1.377 +	IMPORT_C TRealX operator+() const;
   1.378 +	IMPORT_C TRealX operator-() const;
   1.379 +	IMPORT_C TRealX &operator++();
   1.380 +	IMPORT_C TRealX operator++(TInt);
   1.381 +	IMPORT_C TRealX &operator--();
   1.382 +	IMPORT_C TRealX operator--(TInt);
   1.383 +	IMPORT_C TRealX operator+(const TRealX &aVal) const;
   1.384 +	IMPORT_C TRealX operator-(const TRealX &aVal) const;
   1.385 +	IMPORT_C TRealX operator*(const TRealX &aVal) const;
   1.386 +	IMPORT_C TRealX operator/(const TRealX &aVal) const;
   1.387 +	IMPORT_C TRealX operator%(const TRealX &aVal) const;
   1.388 +	IMPORT_C TInt Add(TRealX& aResult,const TRealX &aVal) const;
   1.389 +	IMPORT_C TInt Sub(TRealX& aResult,const TRealX &aVal) const;
   1.390 +	IMPORT_C TInt Mult(TRealX& aResult,const TRealX &aVal) const;
   1.391 +	IMPORT_C TInt Div(TRealX& aResult,const TRealX &aVal) const;
   1.392 +	IMPORT_C TInt Mod(TRealX& aResult,const TRealX &aVal) const;
   1.393 +	IMPORT_C TRealXOrder Compare(const TRealX& aVal) const;
   1.394 +	inline TBool operator==(const TRealX &aVal) const;
   1.395 +	inline TBool operator!=(const TRealX &aVal) const;
   1.396 +	inline TBool operator>=(const TRealX &aVal) const;
   1.397 +	inline TBool operator<=(const TRealX &aVal) const;
   1.398 +	inline TBool operator>(const TRealX &aVal) const;
   1.399 +	inline TBool operator<(const TRealX &aVal) const;
   1.400 +public:
   1.401 +    /**
   1.402 +	The mantissa.
   1.403 +	*/
   1.404 +	// Represented as two adjacent 32 bit values, rather than one 64 value.
   1.405 +	// This is to avoid EABI introduced padding overheads and BC breakages. 
   1.406 +	// This representation works because the mantissa is always accessed from
   1.407 +	// assembler code as two 32 bit quantities. The C++ code that accesses it
   1.408 +	// now constructs an automatic TInt64 with the two components.
   1.409 +	TUint32 iMantLo;
   1.410 +	TUint32 iMantHi;
   1.411 +	
   1.412 +	/**
   1.413 +	The sign: 0 for +, 1 for -
   1.414 +	*/
   1.415 +	TInt8 iSign;	
   1.416 +	
   1.417 +	/**
   1.418 +	Flags: 0 for exact, 1 for rounded down, 2 for rounded up
   1.419 +	*/ 
   1.420 +	TUint8 iFlag;
   1.421 +	
   1.422 +	/**
   1.423 +	Exponent: biased by 32767, iExp=0 => zero, +65535 => infinity or NaN
   1.424 +	*/
   1.425 +	TUint16 iExp;
   1.426 +	};
   1.427 +
   1.428 +
   1.429 +
   1.430 +
   1.431 +struct SPoly
   1.432 +/**
   1.433 +@publishedAll
   1.434 +@released
   1.435 +
   1.436 +A structure containing the set of coefficients for a polynomial.
   1.437 +
   1.438 +@see Math::Poly
   1.439 +*/
   1.440 +    {
   1.441 +    TInt num;
   1.442 +	TReal c[1];
   1.443 +    };
   1.444 +
   1.445 +
   1.446 +
   1.447 +
   1.448 +class Math
   1.449 +/**
   1.450 +@publishedAll
   1.451 +@released
   1.452 +
   1.453 +A collection of mathematical functions.
   1.454 +*/
   1.455 +	{
   1.456 +public:
   1.457 +	IMPORT_C static TInt ACos(TReal &aTrg,const TReal &aSrc);
   1.458 +	IMPORT_C static TInt ASin(TReal &aTrg,const TReal &aSrc);
   1.459 +	IMPORT_C static TInt ATan(TReal &aTrg,const TReal &aSrc);
   1.460 +	IMPORT_C static TInt ATan(TReal &aTrg,const TReal &aSrcY,const TReal &aSrcX);
   1.461 +	IMPORT_C static TInt Cos(TReal &aTrg,const TReal &aSrc);
   1.462 +	
   1.463 +	/**
   1.464 +	This function is not implemented by Symbian OS.
   1.465 +	*/
   1.466 +	IMPORT_C static TInt DtoR(TReal &aTrg,const TDesC &aSrc,TInt &aPos,const TChar aPoint);
   1.467 +	IMPORT_C static TInt Exp(TReal &aTrg,const TReal &aSrc);
   1.468 +	IMPORT_C static TInt Frac(TReal &aTrg,const TReal &aSrc);
   1.469 +	IMPORT_C static TInt Int(TReal &aTrg,const TReal &aSrc);
   1.470 +	IMPORT_C static TInt Int(TInt16 &aTrg,const TReal &aSrc);
   1.471 +	IMPORT_C static TInt Int(TInt32 &aTrg,const TReal &aSrc);
   1.472 +	IMPORT_C static TInt Log(TReal &aTrg,const TReal &aSrc);
   1.473 +	IMPORT_C static TInt Ln(TReal &aTrg,const TReal &aSrc);
   1.474 +	IMPORT_C static TInt Mod(TReal &aTrg,const TReal &aSrc,const TReal &aModulus);
   1.475 +	IMPORT_C static TReal Poly(TReal aVal,const SPoly *aPoly) __SOFTFP;
   1.476 +	IMPORT_C static TInt Pow(TReal &aTrg,const TReal &aSrc,const TReal &aPower);
   1.477 +	IMPORT_C static TInt Pow10(TReal &aTrg,const TInt exp);
   1.478 +	IMPORT_C static TInt Rand(TInt64 &aSeed);
   1.479 +	IMPORT_C static TReal FRand(TInt64 &aSeed) __SOFTFP;
   1.480 +	IMPORT_C static TUint32 Random();
   1.481 +	IMPORT_C static TInt Round(TReal &aTrg,const TReal &aSrc,TInt aDecimalPlaces);
   1.482 +	IMPORT_C static TInt Sin(TReal &aTrg,const TReal &aSrc); 
   1.483 +	IMPORT_C static TInt Sqrt(TReal &aTrg,const TReal &aSrc);
   1.484 +	IMPORT_C static TInt Tan(TReal &aTrg,const TReal &aSrc);
   1.485 +	IMPORT_C static TBool IsZero(const TReal &aVal);
   1.486 +	IMPORT_C static TBool IsNaN(const TReal &aVal);
   1.487 +	IMPORT_C static TBool IsInfinite(const TReal &aVal);
   1.488 +	IMPORT_C static TBool IsFinite(const TReal &aVal);
   1.489 +	IMPORT_C static void PolyX(TRealX& aY, const TRealX& aX, TInt aDeg, const TRealX *aCoef);
   1.490 +	static TInt MultPow10X(TRealX& aTrg, TInt aPower);
   1.491 +	IMPORT_C static void Mul64(Int64 aX, Int64 aY, Int64& aOutH, Uint64& aOutL);
   1.492 +	IMPORT_C static void UMul64(Uint64 aX, Uint64 aY, Uint64& aOutH, Uint64& aOutL);
   1.493 +	IMPORT_C static Int64 DivMod64(Int64 aDividend, Int64 aDivisor, Int64& aRemainder);
   1.494 +	IMPORT_C static Uint64 UDivMod64(Uint64 aDividend, Uint64 aDivisor, Uint64& aRemainder);
   1.495 +private:
   1.496 +	IMPORT_C static void SetZero(TReal &aVal,TInt aSign=0);
   1.497 +	IMPORT_C static void SetNaN(TReal &aVal);
   1.498 +	IMPORT_C static void SetInfinite(TReal &aVal,TInt aSign);
   1.499 +	};
   1.500 +
   1.501 +#include <e32math.inl>
   1.502 +
   1.503 +#endif // __E32MATH_H__