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