epoc32/include/e32math.h
author William Roberts <williamr@symbian.org>
Tue, 16 Mar 2010 16:12:26 +0000
branchSymbian2
changeset 2 2fe1408b6811
parent 0 061f57f2323e
child 4 837f303aceeb
permissions -rw-r--r--
Final list of Symbian^2 public API header files
     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 "Symbian Foundation License v1.0" to Symbian Foundation members and "Symbian Foundation End User License Agreement v1.0" to non-members
     5 // which accompanies this distribution, and is available
     6 // at the URL "http://www.symbianfoundation.org/legal/licencesv10.html".
     7 //
     8 // Initial Contributors:
     9 // Nokia Corporation - initial contribution.
    10 //
    11 // Contributors:
    12 //
    13 // Description:
    14 // e32\include\e32math.h
    15 // 
    16 //
    17 
    18 #ifndef __E32MATH_H__
    19 #define __E32MATH_H__
    20 #include <e32std.h>
    21 
    22 
    23 /**
    24 @publishedAll
    25 @released
    26 */
    27 const TInt KMaxPrecision=15;
    28 /**
    29 @publishedAll
    30 @released
    31 */
    32 const TInt KPrecisionLimit=12;
    33 /**
    34 @publishedAll
    35 @released
    36 */
    37 const TInt KMantissaBits=53;
    38 /**
    39 @publishedAll
    40 @released
    41 */
    42 const TInt KMaxExponent=1023;
    43 /**
    44 @publishedAll
    45 @released
    46 */
    47 const TInt KExponentBias=1022;
    48 /**
    49 @publishedAll
    50 @released
    51 */
    52 const TInt KSpecialExponent=2047;
    53 //
    54 
    55 
    56 /**
    57 @publishedAll
    58 @released
    59 
    60 The maximum exponent for a 32-bit floating point number.
    61 */
    62 const TInt KTReal32MaxExponent=128;			// changed from 127
    63 
    64 
    65 /**
    66 @publishedAll
    67 @released
    68 
    69 The minimum exponent for a 32-bit floating point number.
    70 */
    71 const TInt KTReal32MinExponent=-125;
    72 /**
    73 @publishedAll
    74 @released
    75 */
    76 const TInt KTReal32ExponentBias=126;
    77 /**
    78 @publishedAll
    79 @released
    80 */
    81 const TInt KTReal32SpecialExponent=255;		// changed from KTReal32ExponentBad
    82 
    83 
    84 /**
    85 @publishedAll
    86 @released
    87 
    88 A zero exponent value for a 32-bit floating point number. 
    89 */
    90 const TInt KTReal32ZeroExponent=0;
    91 //
    92 
    93 
    94 /**
    95 @publishedAll
    96 @released
    97 
    98 The maximum exponent for a 64-bit floating point number.
    99 */
   100 const TInt KTReal64MaxExponent=1024;		// changed from 1023
   101 
   102 
   103 /**
   104 @publishedAll
   105 @released
   106 
   107 The minimum exponent for a 64-bit floating point number.
   108 */
   109 const TInt KTReal64MinExponent=-1021;
   110 
   111 
   112 /**
   113 @publishedAll
   114 @released
   115 */
   116 const TInt KTReal64ExponentBias=1022;
   117 
   118 
   119 /**
   120 @publishedAll
   121 @released
   122 */
   123 const TInt KTReal64SpecialExponent=2047;	// changed from KTReal64BadExponent
   124 
   125 
   126 /**
   127 @publishedAll
   128 @released
   129 
   130 A zero exponent value for a 64-bit floating point number. 
   131 */
   132 const TInt KTReal64ZeroExponent=0;
   133 //
   134 
   135 
   136 /**
   137 @publishedAll
   138 @released
   139 
   140 The minimum value of a 64-bit floating point number.
   141 */
   142 const TReal KMinTReal=2.2250738585072015E-308;	// changed from TReal64
   143 
   144 
   145 /**
   146 @publishedAll
   147 @released
   148 
   149 The maximum value of a 64-bit floating point number.
   150 */
   151 const TReal KMaxTReal=1.7976931348623157E+308;	//
   152 //
   153 
   154 
   155 /**
   156 @publishedAll
   157 @released
   158 
   159 The minimum value of a 32-bit floating point number.
   160 */
   161 const TReal32 KMinTReal32=1.17549435E-38f;
   162 
   163 
   164 /**
   165 @publishedAll
   166 @released
   167 
   168 The maximum value of a 32-bit floating point number.
   169 */
   170 const TReal32 KMaxTReal32=3.4028234663852885981170418348452e+38f;
   171 //
   172 
   173 
   174 /**
   175 @publishedAll
   176 @released
   177 
   178 The minimum value of a 64-bit floating point number.
   179 */
   180 const TReal64 KMinTReal64=2.2250738585072015E-308;
   181 
   182 
   183 /**
   184 @publishedAll
   185 @released
   186 
   187 The maximum value of a 64-bit floating point number.
   188 */
   189 const TReal64 KMaxTReal64=1.7976931348623157E+308;
   190 //
   191 
   192 
   193 /**
   194 @publishedAll
   195 @released
   196 */
   197 const TReal KSqhf=0.70710678118654752440;
   198 
   199 
   200 /**
   201 @publishedAll
   202 @released
   203 
   204 Log 2 to the base "e".
   205 */
   206 const TReal KRln2=1.4426950408889634;
   207 
   208 
   209 /**
   210 @publishedAll
   211 @released
   212 
   213 Log 10 to the base "e".
   214 */
   215 const TReal KRln10=0.4342944819032518;
   216 
   217 
   218 /**
   219 @publishedAll
   220 @released
   221 
   222 Log 2 to the base 10.
   223 */
   224 const TReal KRlg2=0.3010299956639812;
   225 
   226 
   227 /**
   228 @publishedAll
   229 @released
   230 
   231 The mathematical constant Pi.
   232 */
   233 const TReal KPi=3.1415926535897932;
   234 
   235 
   236 /**
   237 @publishedAll
   238 @released
   239 
   240 The reciprocal of the mathematical constant Pi. 
   241 */
   242 const TReal KPiInv=0.3183098861837907;
   243 
   244 
   245 /**
   246 @publishedAll
   247 @released
   248 
   249 The mathematical constant Pi divided by 2.
   250 */
   251 const TReal KPiBy2=1.5707963267948966;
   252 
   253 
   254 /**
   255 @publishedAll
   256 @released
   257 
   258 Not used.
   259 */
   260 const TReal KDrpi=0.6366197723675813;
   261 
   262 
   263 /**
   264 @publishedAll
   265 @released
   266 
   267 The square root of 3.
   268 */
   269 const TReal KSqt3=1.7320508075688773;
   270 
   271 
   272 /**
   273 @publishedAll
   274 @released
   275 */
   276 const TReal KMsq3=0.2679491924311227;
   277 
   278 
   279 /**
   280 @publishedAll
   281 @released
   282 
   283 The multiplying factor to convert radians to degrees.
   284 */
   285 const TReal KRadToDeg=57.29577951308232;
   286 
   287 
   288 /**
   289 @publishedAll
   290 @released
   291 
   292 The multiplying factor to convert degrees to radians.
   293 */
   294 const TReal KDegToRad=0.017453292519943296;
   295 
   296 
   297 
   298 
   299 class TRealX
   300 /**
   301 @publishedAll
   302 @released
   303 
   304 A class encapsulating an extended precision real value.
   305 
   306 This class provides 64 bit precision and a dynamic range of approximately
   307 1E-9863 to 1E+9863. All member functions are optimized for speed.
   308 */
   309 	{
   310 public:
   311 	enum TRealXOrder {ELessThan=1,EEqual=2,EGreaterThan=4,EUnordered=8};
   312 public:
   313 	IMPORT_C TRealX();
   314 	IMPORT_C TRealX(TInt aInt);
   315 	IMPORT_C TRealX(TUint aInt);
   316 	IMPORT_C TRealX(TUint aExp, TUint aMantHi, TUint aMantLo);
   317 	IMPORT_C TRealX(const TInt64 &aInt);
   318 	IMPORT_C TRealX(TReal32 aReal) __SOFTFP;
   319 	IMPORT_C TRealX(TReal64 aReal) __SOFTFP;
   320 	IMPORT_C TRealX &operator=(TInt aInt);
   321 	IMPORT_C TRealX &operator=(TUint aInt);
   322 	IMPORT_C TRealX &operator=(const TInt64& aInt);
   323 	IMPORT_C TRealX &operator=(TReal32 aReal) __SOFTFP;
   324 	IMPORT_C TRealX &operator=(TReal64 aReal) __SOFTFP;
   325 	IMPORT_C TInt Set(TInt aInt);
   326 	IMPORT_C TInt Set(TUint aInt);
   327 	IMPORT_C TInt Set(const TInt64& aInt);
   328 	IMPORT_C TInt Set(TReal32 aReal) __SOFTFP;
   329 	IMPORT_C TInt Set(TReal64 aReal) __SOFTFP;
   330 	IMPORT_C operator TInt() const;
   331 	IMPORT_C operator TUint() const;
   332 	IMPORT_C operator TInt64() const;
   333 	IMPORT_C operator TReal32() const __SOFTFP;
   334 	IMPORT_C operator TReal64() const __SOFTFP;
   335 	IMPORT_C TInt GetTReal(TReal32 &aVal) const;
   336 	IMPORT_C TInt GetTReal(TReal64 &aVal) const;
   337 	IMPORT_C void SetZero(TBool aNegative=EFalse);
   338 	IMPORT_C void SetNaN();
   339 	IMPORT_C void SetInfinite(TBool aNegative);
   340 	IMPORT_C TBool IsZero() const;
   341 	IMPORT_C TBool IsNaN() const;
   342 	IMPORT_C TBool IsInfinite() const;
   343 	IMPORT_C TBool IsFinite() const;
   344 	IMPORT_C const TRealX &operator+=(const TRealX &aVal);
   345 	IMPORT_C const TRealX &operator-=(const TRealX &aVal);
   346 	IMPORT_C const TRealX &operator*=(const TRealX &aVal);
   347 	IMPORT_C const TRealX &operator/=(const TRealX &aVal);
   348 	IMPORT_C const TRealX &operator%=(const TRealX &aVal);
   349 	IMPORT_C TInt AddEq(const TRealX &aVal);
   350 	IMPORT_C TInt SubEq(const TRealX &aVal);
   351 	IMPORT_C TInt MultEq(const TRealX &aVal);
   352 	IMPORT_C TInt DivEq(const TRealX &aVal);
   353 	IMPORT_C TInt ModEq(const TRealX &aVal);
   354 	IMPORT_C TRealX operator+() const;
   355 	IMPORT_C TRealX operator-() const;
   356 	IMPORT_C TRealX &operator++();
   357 	IMPORT_C TRealX operator++(TInt);
   358 	IMPORT_C TRealX &operator--();
   359 	IMPORT_C TRealX operator--(TInt);
   360 	IMPORT_C TRealX operator+(const TRealX &aVal) const;
   361 	IMPORT_C TRealX operator-(const TRealX &aVal) const;
   362 	IMPORT_C TRealX operator*(const TRealX &aVal) const;
   363 	IMPORT_C TRealX operator/(const TRealX &aVal) const;
   364 	IMPORT_C TRealX operator%(const TRealX &aVal) const;
   365 	IMPORT_C TInt Add(TRealX& aResult,const TRealX &aVal) const;
   366 	IMPORT_C TInt Sub(TRealX& aResult,const TRealX &aVal) const;
   367 	IMPORT_C TInt Mult(TRealX& aResult,const TRealX &aVal) const;
   368 	IMPORT_C TInt Div(TRealX& aResult,const TRealX &aVal) const;
   369 	IMPORT_C TInt Mod(TRealX& aResult,const TRealX &aVal) const;
   370 	IMPORT_C TRealXOrder Compare(const TRealX& aVal) const;
   371 	inline TBool operator==(const TRealX &aVal) const;
   372 	inline TBool operator!=(const TRealX &aVal) const;
   373 	inline TBool operator>=(const TRealX &aVal) const;
   374 	inline TBool operator<=(const TRealX &aVal) const;
   375 	inline TBool operator>(const TRealX &aVal) const;
   376 	inline TBool operator<(const TRealX &aVal) const;
   377 public:
   378     /**
   379 	The mantissa.
   380 	*/
   381 	// Represented as two adjacent 32 bit values, rather than one 64 value.
   382 	// This is to avoid EABI introduced padding overheads and BC breakages. 
   383 	// This representation works because the mantissa is always accessed from
   384 	// assembler code as two 32 bit quantities. The C++ code that accesses it
   385 	// now constructs an automatic TInt64 with the two components.
   386 	TUint32 iMantLo;
   387 	TUint32 iMantHi;
   388 	
   389 	/**
   390 	The sign: 0 for +, 1 for -
   391 	*/
   392 	TInt8 iSign;	
   393 	
   394 	/**
   395 	Flags: 0 for exact, 1 for rounded down, 2 for rounded up
   396 	*/ 
   397 	TUint8 iFlag;
   398 	
   399 	/**
   400 	Exponent: biased by 32767, iExp=0 => zero, +65535 => infinity or NaN
   401 	*/
   402 	TUint16 iExp;
   403 	};
   404 
   405 
   406 
   407 
   408 struct SPoly
   409 /**
   410 @publishedAll
   411 @released
   412 
   413 A structure containing the set of coefficients for a polynomial.
   414 
   415 @see Math::Poly
   416 */
   417     {
   418     TInt num;
   419 	TReal c[1];
   420     };
   421 
   422 
   423 
   424 
   425 class Math
   426 /**
   427 @publishedAll
   428 @released
   429 
   430 A collection of mathematical functions.
   431 */
   432 	{
   433 public:
   434 	IMPORT_C static TInt ACos(TReal &aTrg,const TReal &aSrc);
   435 	IMPORT_C static TInt ASin(TReal &aTrg,const TReal &aSrc);
   436 	IMPORT_C static TInt ATan(TReal &aTrg,const TReal &aSrc);
   437 	IMPORT_C static TInt ATan(TReal &aTrg,const TReal &aSrcY,const TReal &aSrcX);
   438 	IMPORT_C static TInt Cos(TReal &aTrg,const TReal &aSrc);
   439 	
   440 	/**
   441 	This function is not implemented by Symbian OS.
   442 	*/
   443 	IMPORT_C static TInt DtoR(TReal &aTrg,const TDesC &aSrc,TInt &aPos,const TChar aPoint);
   444 	IMPORT_C static TInt Exp(TReal &aTrg,const TReal &aSrc);
   445 	IMPORT_C static TInt Frac(TReal &aTrg,const TReal &aSrc);
   446 	IMPORT_C static TInt Int(TReal &aTrg,const TReal &aSrc);
   447 	IMPORT_C static TInt Int(TInt16 &aTrg,const TReal &aSrc);
   448 	IMPORT_C static TInt Int(TInt32 &aTrg,const TReal &aSrc);
   449 	IMPORT_C static TInt Log(TReal &aTrg,const TReal &aSrc);
   450 	IMPORT_C static TInt Ln(TReal &aTrg,const TReal &aSrc);
   451 	IMPORT_C static TInt Mod(TReal &aTrg,const TReal &aSrc,const TReal &aModulus);
   452 	IMPORT_C static TReal Poly(TReal aVal,const SPoly *aPoly) __SOFTFP;
   453 	IMPORT_C static TInt Pow(TReal &aTrg,const TReal &aSrc,const TReal &aPower);
   454 	IMPORT_C static TInt Pow10(TReal &aTrg,const TInt exp);
   455 	IMPORT_C static TInt Rand(TInt64 &aSeed);
   456 	IMPORT_C static TReal FRand(TInt64 &aSeed) __SOFTFP;
   457 	IMPORT_C static TUint32 Random();
   458 	IMPORT_C static TInt Round(TReal &aTrg,const TReal &aSrc,TInt aDecimalPlaces);
   459 	IMPORT_C static TInt Sin(TReal &aTrg,const TReal &aSrc); 
   460 	IMPORT_C static TInt Sqrt(TReal &aTrg,const TReal &aSrc);
   461 	IMPORT_C static TInt Tan(TReal &aTrg,const TReal &aSrc);
   462 	IMPORT_C static TBool IsZero(const TReal &aVal);
   463 	IMPORT_C static TBool IsNaN(const TReal &aVal);
   464 	IMPORT_C static TBool IsInfinite(const TReal &aVal);
   465 	IMPORT_C static TBool IsFinite(const TReal &aVal);
   466 	IMPORT_C static void PolyX(TRealX& aY, const TRealX& aX, TInt aDeg, const TRealX *aCoef);
   467 	static TInt MultPow10X(TRealX& aTrg, TInt aPower);
   468 	IMPORT_C static void Mul64(Int64 aX, Int64 aY, Int64& aOutH, Uint64& aOutL);
   469 	IMPORT_C static void UMul64(Uint64 aX, Uint64 aY, Uint64& aOutH, Uint64& aOutL);
   470 	IMPORT_C static Int64 DivMod64(Int64 aDividend, Int64 aDivisor, Int64& aRemainder);
   471 	IMPORT_C static Uint64 UDivMod64(Uint64 aDividend, Uint64 aDivisor, Uint64& aRemainder);
   472 private:
   473 	IMPORT_C static void SetZero(TReal &aVal,TInt aSign=0);
   474 	IMPORT_C static void SetNaN(TReal &aVal);
   475 	IMPORT_C static void SetInfinite(TReal &aVal,TInt aSign);
   476 	};
   477 
   478 #include <e32math.inl>
   479 
   480 #endif // __E32MATH_H__