Original Symbian headers
Selected EUSER, Window Server, networking, graphics and device declarations
Loading...
Searching...
No Matches
e32math.h
Go to the documentation of this file.
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".
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
27const TInt KMaxPrecision=15;
28
36const TInt KPrecisionLimit=12;
37
52
57const TInt KMantissaBits=53;
62const TInt KMaxExponent=1023;
67const TInt KExponentBias=1022;
72const TInt KSpecialExponent=2047;
73//
74
75
82const TInt KTReal32MaxExponent=128; // changed from 127
83
84
91const TInt KTReal32MinExponent=-125;
96const TInt KTReal32ExponentBias=126;
101const TInt KTReal32SpecialExponent=255; // changed from KTReal32ExponentBad
102
103
110const TInt KTReal32ZeroExponent=0;
111//
112
113
120const TInt KTReal64MaxExponent=1024; // changed from 1023
121
122
129const TInt KTReal64MinExponent=-1021;
130
131
136const TInt KTReal64ExponentBias=1022;
137
138
143const TInt KTReal64SpecialExponent=2047; // changed from KTReal64BadExponent
144
145
152const TInt KTReal64ZeroExponent=0;
153//
154
155
162const TReal KMinTReal=2.2250738585072015E-308; // changed from TReal64
163
164
171const TReal KMaxTReal=1.7976931348623157E+308; //
172//
173
174
181const TReal32 KMinTReal32=1.17549435E-38f;
182
183
190const TReal32 KMaxTReal32=3.4028234663852885981170418348452e+38f;
191//
192
193
200const TReal64 KMinTReal64=2.2250738585072015E-308;
201
202
209const TReal64 KMaxTReal64=1.7976931348623157E+308;
210//
211
212
217const TReal KSqhf=0.70710678118654752440;
218
219
226const TReal KRln2=1.4426950408889634;
227
228
235const TReal KRln10=0.4342944819032518;
236
237
244const TReal KRlg2=0.3010299956639812;
245
246
253const TReal KPi=3.1415926535897932;
254
262const TReal KPiInv=0.3183098861837907;
263
264
271const TReal KPiBy2=1.5707963267948966;
272
273
280const TReal KDrpi=0.6366197723675813;
281
282
289const TReal KSqt3=1.7320508075688773;
290
291
296const TReal KMsq3=0.2679491924311227;
297
305const TReal KRadToDeg=57.29577951308232;
306
307
314const TReal KDegToRad=0.017453292519943296;
315
316
317
318
319class TRealX
329 {
330public:
332public:
333 IMPORT_C TRealX();
334 IMPORT_C TRealX(TInt aInt);
335 IMPORT_C TRealX(TUint aInt);
336 IMPORT_C TRealX(TUint aExp, TUint aMantHi, TUint aMantLo);
337 IMPORT_C TRealX(const TInt64 &aInt);
338 IMPORT_C TRealX(TReal32 aReal) __SOFTFP;
339 IMPORT_C TRealX(TReal64 aReal) __SOFTFP;
340 IMPORT_C TRealX &operator=(TInt aInt);
341 IMPORT_C TRealX &operator=(TUint aInt);
342 IMPORT_C TRealX &operator=(const TInt64& aInt);
343 IMPORT_C TRealX &operator=(TReal32 aReal) __SOFTFP;
344 IMPORT_C TRealX &operator=(TReal64 aReal) __SOFTFP;
345 IMPORT_C TInt Set(TInt aInt);
346 IMPORT_C TInt Set(TUint aInt);
347 IMPORT_C TInt Set(const TInt64& aInt);
348 IMPORT_C TInt Set(TReal32 aReal) __SOFTFP;
349 IMPORT_C TInt Set(TReal64 aReal) __SOFTFP;
350 IMPORT_C operator TInt() const;
351 IMPORT_C operator TUint() const;
352 IMPORT_C operator TInt64() const;
353 IMPORT_C operator TReal32() const __SOFTFP;
354 IMPORT_C operator TReal64() const __SOFTFP;
355 IMPORT_C TInt GetTReal(TReal32 &aVal) const;
356 IMPORT_C TInt GetTReal(TReal64 &aVal) const;
357 IMPORT_C void SetZero(TBool aNegative=EFalse);
358 IMPORT_C void SetNaN();
359 IMPORT_C void SetInfinite(TBool aNegative);
360 IMPORT_C TBool IsZero() const;
361 IMPORT_C TBool IsNaN() const;
362 IMPORT_C TBool IsInfinite() const;
363 IMPORT_C TBool IsFinite() const;
364 IMPORT_C const TRealX &operator+=(const TRealX &aVal);
365 IMPORT_C const TRealX &operator-=(const TRealX &aVal);
366 IMPORT_C const TRealX &operator*=(const TRealX &aVal);
367 IMPORT_C const TRealX &operator/=(const TRealX &aVal);
368 IMPORT_C const TRealX &operator%=(const TRealX &aVal);
369 IMPORT_C TInt AddEq(const TRealX &aVal);
370 IMPORT_C TInt SubEq(const TRealX &aVal);
371 IMPORT_C TInt MultEq(const TRealX &aVal);
372 IMPORT_C TInt DivEq(const TRealX &aVal);
373 IMPORT_C TInt ModEq(const TRealX &aVal);
374 IMPORT_C TRealX operator+() const;
375 IMPORT_C TRealX operator-() const;
376 IMPORT_C TRealX &operator++();
377 IMPORT_C TRealX operator++(TInt);
378 IMPORT_C TRealX &operator--();
379 IMPORT_C TRealX operator--(TInt);
380 IMPORT_C TRealX operator+(const TRealX &aVal) const;
381 IMPORT_C TRealX operator-(const TRealX &aVal) const;
382 IMPORT_C TRealX operator*(const TRealX &aVal) const;
383 IMPORT_C TRealX operator/(const TRealX &aVal) const;
384 IMPORT_C TRealX operator%(const TRealX &aVal) const;
385 IMPORT_C TInt Add(TRealX& aResult,const TRealX &aVal) const;
386 IMPORT_C TInt Sub(TRealX& aResult,const TRealX &aVal) const;
387 IMPORT_C TInt Mult(TRealX& aResult,const TRealX &aVal) const;
388 IMPORT_C TInt Div(TRealX& aResult,const TRealX &aVal) const;
389 IMPORT_C TInt Mod(TRealX& aResult,const TRealX &aVal) const;
390 IMPORT_C TRealXOrder Compare(const TRealX& aVal) const;
391 inline TBool operator==(const TRealX &aVal) const;
392 inline TBool operator!=(const TRealX &aVal) const;
393 inline TBool operator>=(const TRealX &aVal) const;
394 inline TBool operator<=(const TRealX &aVal) const;
395 inline TBool operator>(const TRealX &aVal) const;
396 inline TBool operator<(const TRealX &aVal) const;
397public:
401 // Represented as two adjacent 32 bit values, rather than one 64 value.
402 // This is to avoid EABI introduced padding overheads and BC breakages.
403 // This representation works because the mantissa is always accessed from
404 // assembler code as two 32 bit quantities. The C++ code that accesses it
405 // now constructs an automatic TInt64 with the two components.
406 TUint32 iMantLo;
407 TUint32 iMantHi;
412 TInt8 iSign;
417 TUint8 iFlag;
422 TUint16 iExp;
423 };
428struct SPoly
438 TInt num;
439 TReal c[1];
440 };
445class Math
453public:
454 IMPORT_C static TInt ACos(TReal &aTrg,const TReal &aSrc);
455 IMPORT_C static TInt ASin(TReal &aTrg,const TReal &aSrc);
456 IMPORT_C static TInt ATan(TReal &aTrg,const TReal &aSrc);
457 IMPORT_C static TInt ATan(TReal &aTrg,const TReal &aSrcY,const TReal &aSrcX);
458 IMPORT_C static TInt Cos(TReal &aTrg,const TReal &aSrc);
459 IMPORT_C static TInt Exp(TReal &aTrg,const TReal &aSrc);
460 IMPORT_C static TInt Frac(TReal &aTrg,const TReal &aSrc);
461 IMPORT_C static TInt Int(TReal &aTrg,const TReal &aSrc);
462 IMPORT_C static TInt Int(TInt16 &aTrg,const TReal &aSrc);
463 IMPORT_C static TInt Int(TInt32 &aTrg,const TReal &aSrc);
464 IMPORT_C static TInt Log(TReal &aTrg,const TReal &aSrc);
465 IMPORT_C static TInt Ln(TReal &aTrg,const TReal &aSrc);
466 IMPORT_C static TInt Mod(TReal &aTrg,const TReal &aSrc,const TReal &aModulus);
467 IMPORT_C static TReal Poly(TReal aVal,const SPoly *aPoly) __SOFTFP;
468 IMPORT_C static TInt Pow(TReal &aTrg,const TReal &aSrc,const TReal &aPower);
469 IMPORT_C static TInt Pow10(TReal &aTrg,const TInt exp);
470 IMPORT_C static TInt Rand(TInt64 &aSeed);
471 IMPORT_C static TReal FRand(TInt64 &aSeed) __SOFTFP;
472 IMPORT_C static TUint32 Random();
473 IMPORT_C static void Random(TDes8& aRandomValue);
474 IMPORT_C static void RandomL(TDes8& aRandomValue);
475 IMPORT_C static TUint32 RandomL();
476 IMPORT_C static TInt Round(TReal &aTrg,const TReal &aSrc,TInt aDecimalPlaces);
477 IMPORT_C static TInt Sin(TReal &aTrg,const TReal &aSrc);
478 IMPORT_C static TInt Sqrt(TReal &aTrg,const TReal &aSrc);
479 IMPORT_C static TInt Tan(TReal &aTrg,const TReal &aSrc);
480 IMPORT_C static TBool IsZero(const TReal &aVal);
481 IMPORT_C static TBool IsNaN(const TReal &aVal);
482 IMPORT_C static TBool IsInfinite(const TReal &aVal);
483 IMPORT_C static TBool IsFinite(const TReal &aVal);
484 IMPORT_C static void PolyX(TRealX& aY, const TRealX& aX, TInt aDeg, const TRealX *aCoef);
485 static TInt MultPow10X(TRealX& aTrg, TInt aPower);
486 IMPORT_C static void Mul64(Int64 aX, Int64 aY, Int64& aOutH, Uint64& aOutL);
487 IMPORT_C static void UMul64(Uint64 aX, Uint64 aY, Uint64& aOutH, Uint64& aOutL);
488 IMPORT_C static Int64 DivMod64(Int64 aDividend, Int64 aDivisor, Int64& aRemainder);
489 IMPORT_C static Uint64 UDivMod64(Uint64 aDividend, Uint64 aDivisor, Uint64& aRemainder);
490private:
491 IMPORT_C static void SetZero(TReal &aVal,TInt aSign=0);
492 IMPORT_C static void SetNaN(TReal &aVal);
493 IMPORT_C static void SetInfinite(TReal &aVal,TInt aSign);
494 };
495
496#include <e32math.inl>
497
498#endif // __E32MATH_H__
A collection of mathematical functions.
Definition e32math.h:528
A class encapsulating an extended precision real value.
Definition e32math.h:401
IMPORT_C TInt AddEq(const TRealX &aVal)
Adds an extended precision value to this extended precision number.
IMPORT_C TInt GetTReal(TReal32 &aVal) const
Extracts the extended precision value as a single precision floating point value.
IMPORT_C TInt Add(TRealX &aResult, const TRealX &aVal) const
Adds an extended precision value to this extended precision number.
IMPORT_C TInt MultEq(const TRealX &aVal)
Multiplies this extended precision number by an extended precision value.
IMPORT_C TInt DivEq(const TRealX &aVal)
Divides this extended precision number by an extended precision value.
TRealXOrder
Definition e32math.h:403
@ EEqual
Definition e32math.h:403
@ EUnordered
Definition e32math.h:403
@ EGreaterThan
Definition e32math.h:403
@ ELessThan
Definition e32math.h:403
TUint8 iFlag
Flags: 0 for exact, 1 for rounded down, 2 for rounded up.
Definition e32math.h:489
TUint16 iExp
Exponent: biased by 32767, iExp=0 => zero, +65535 => infinity or NaN.
Definition e32math.h:494
IMPORT_C TRealX()
Constructs a default extended precision object.
IMPORT_C TInt ModEq(const TRealX &aVal)
Modulo-divides this extended precision number by an extended precision value.
IMPORT_C void SetZero(TBool aNegative=EFalse)
Sets the value of this extended precision object to zero.
IMPORT_C void SetNaN()
Sets the value of this extended precision object to 'not a number'.
IMPORT_C TInt Sub(TRealX &aResult, const TRealX &aVal) const
Subtracts an extended precision value from this extended precision number.
TUint32 iMantLo
The mantissa.
Definition e32math.h:478
IMPORT_C TInt Mult(TRealX &aResult, const TRealX &aVal) const
Multiplies this extended precision number by an extended precision value.
TInt8 iSign
The sign: 0 for +, 1 for -.
Definition e32math.h:484
IMPORT_C TInt Mod(TRealX &aResult, const TRealX &aVal) const
Modulo-divides this extended precision number by an extended precision value.
IMPORT_C TBool IsInfinite() const
Determines whether the extended precision value has a finite value.
IMPORT_C TInt SubEq(const TRealX &aVal)
Subtracts an extended precision value from this extended precision number.
IMPORT_C TInt Div(TRealX &aResult, const TRealX &aVal) const
Divides this extended precision number by an extended precision value.
IMPORT_C TBool IsFinite() const
Determines whether the extended precision value has a finite value.
IMPORT_C TBool IsZero() const
Determines whether the extended precision value is zero.
TUint32 iMantHi
Definition e32math.h:479
IMPORT_C TRealX & operator=(TInt aInt)
Assigns the specified signed integer value to this extended precision object.
IMPORT_C TInt Set(TInt aInt)
Gives this extended precision object a new value taken from a signed integer.
IMPORT_C void SetInfinite(TBool aNegative)
Sets the value of this extended precision object to infinity.
IMPORT_C TRealXOrder Compare(const TRealX &aVal) const
IMPORT_C TBool IsNaN() const
Determines whether the extended precision value is 'not a number'.
const TReal32 KMinTReal32
The minimum value of a 32-bit floating point number.
Definition e32math.h:221
const TInt KTReal64MaxExponent
The maximum exponent for a 64-bit floating point number.
Definition e32math.h:146
const TReal KRadToDeg
The multiplying factor to convert radians to degrees.
Definition e32math.h:373
const TInt KExponentBias
Definition e32math.h:79
const TInt KTReal64MinExponent
The minimum exponent for a 64-bit floating point number.
Definition e32math.h:157
const TReal KMinTReal
The minimum value of a 64-bit floating point number.
Definition e32math.h:198
const TReal KPi
The mathematical constant Pi.
Definition e32math.h:309
const TReal KMaxTReal
The maximum value of a 64-bit floating point number.
Definition e32math.h:209
const TInt KTReal32ExponentBias
Definition e32math.h:116
const TReal KPiInv
The reciprocal of the mathematical constant Pi.
Definition e32math.h:320
const TReal64 KMinTReal64
The minimum value of a 64-bit floating point number.
Definition e32math.h:244
const TInt KMaxExponent
Definition e32math.h:72
const TInt KMantissaBits
Definition e32math.h:65
const TReal KRln2
Log 2 to the base "e".
Definition e32math.h:276
const TInt KTReal32SpecialExponent
Definition e32math.h:123
const TInt KTReal32MaxExponent
The maximum exponent for a 32-bit floating point number.
Definition e32math.h:98
const TInt KIEEEDoubleInjectivePrecision
Let D be the set of real numbers exactly representable by an IEEE-754 'double' For any positive integ...
Definition e32math.h:57
const TInt KMaxPrecision
Definition e32math.h:29
const TReal KMsq3
Definition e32math.h:362
const TInt KTReal64SpecialExponent
Definition e32math.h:175
const TInt KTReal64ZeroExponent
A zero exponent value for a 64-bit floating point number.
Definition e32math.h:186
const TReal KSqt3
The square root of 3.
Definition e32math.h:353
const TInt KTReal32MinExponent
The minimum exponent for a 32-bit floating point number.
Definition e32math.h:109
const TReal32 KMaxTReal32
The maximum value of a 32-bit floating point number.
Definition e32math.h:232
const TReal KDegToRad
The multiplying factor to convert degrees to radians.
Definition e32math.h:384
const TReal KPiBy2
The mathematical constant Pi divided by 2.
Definition e32math.h:331
const TReal64 KMaxTReal64
The maximum value of a 64-bit floating point number.
Definition e32math.h:255
const TReal KSqhf
Definition e32math.h:265
const TInt KSpecialExponent
Definition e32math.h:86
const TInt KTReal32ZeroExponent
A zero exponent value for a 32-bit floating point number.
Definition e32math.h:134
const TReal KRlg2
Log 2 to the base 10.
Definition e32math.h:298
const TInt KTReal64ExponentBias
Definition e32math.h:166
const TReal KRln10
Log 10 to the base "e".
Definition e32math.h:287
const TReal KDrpi
Not used.
Definition e32math.h:342
const TInt KPrecisionLimit
This constant specifies the maximum number of significant digits available with floating point comput...
Definition e32math.h:40
A structure containing the set of coefficients for a polynomial.
Definition e32math.h:511