Math Class Reference

class Math

A collection of mathematical functions.

Public Member Functions
IMPORT_C TIntACos(TReal &, const TReal &)
IMPORT_C TIntASin(TReal &, const TReal &)
IMPORT_C TIntATan(TReal &, const TReal &)
IMPORT_C TIntATan(TReal &, const TReal &, const TReal &)
IMPORT_C TIntCos(TReal &, const TReal &)
IMPORT_C Int64DivMod64(Int64, Int64, Int64 &)
IMPORT_C TIntExp(TReal &, const TReal &)
IMPORT_C TRealFRand(TInt64 &)
IMPORT_C TIntFrac(TReal &, const TReal &)
IMPORT_C TIntInt(TReal &, const TReal &)
IMPORT_C TIntInt(TInt16 &, const TReal &)
IMPORT_C TIntInt(TInt32 &, const TReal &)
IMPORT_C TBoolIsFinite(const TReal &)
IMPORT_C TBoolIsInfinite(const TReal &)
IMPORT_C TBoolIsNaN(const TReal &)
IMPORT_C TBoolIsZero(const TReal &)
IMPORT_C TIntLn(TReal &, const TReal &)
IMPORT_C TIntLog(TReal &, const TReal &)
IMPORT_C TIntMod(TReal &, const TReal &, const TReal &)
IMPORT_C voidMul64(Int64, Int64, Int64 &, Uint64 &)
TInt MultPow10X(TRealX &, TInt)
IMPORT_C TRealPoly(TReal, const SPoly *)
IMPORT_C voidPolyX(TRealX &, const TRealX &, TInt, const TRealX *)
IMPORT_C TIntPow(TReal &, const TReal &, const TReal &)
IMPORT_C TIntPow10(TReal &, const TInt)
IMPORT_C TIntRand(TInt64 &)
IMPORT_C TUint32Random()
IMPORT_C voidRandom(TDes8 &)
IMPORT_C voidRandomL(TDes8 &)
IMPORT_C TUint32RandomL()
IMPORT_C TIntRound(TReal &, const TReal &, TInt)
IMPORT_C TIntSin(TReal &, const TReal &)
IMPORT_C TIntSqrt(TReal &, const TReal &)
IMPORT_C TIntTan(TReal &, const TReal &)
IMPORT_C Uint64UDivMod64(Uint64, Uint64, Uint64 &)
IMPORT_C voidUMul64(Uint64, Uint64, Uint64 &, Uint64 &)
Private Member Functions
IMPORT_C voidSetInfinite(TReal &, TInt)
IMPORT_C voidSetNaN(TReal &)
IMPORT_C voidSetZero(TReal &, TInt)

Member Functions Documentation

ACos(TReal &, const TReal &)

IMPORT_C TIntACos(TReal &aTrg,
const TReal &aSrc
)[static]

Calculates the principal value of the inverse cosine of a number.

Parameters

TReal & aTrgA reference containing the result in radians, a value between 0 and pi.
const TReal & aSrcThe argument of the arccos function, a value between -1 and +1 inclusive.

ASin(TReal &, const TReal &)

IMPORT_C TIntASin(TReal &aTrg,
const TReal &aSrc
)[static]

Calculates the principal value of the inverse sine of a number.

Parameters

TReal & aTrgA reference containing the result in radians, a value between -pi/2 and +pi/2.
const TReal & aSrcThe argument of the arcsin function, a value between -1 and +1 inclusive.

ATan(TReal &, const TReal &)

IMPORT_C TIntATan(TReal &aTrg,
const TReal &aSrc
)[static]

Calculates the principal value of the inverse tangent of a number.

Parameters

TReal & aTrgA reference containing the result in radians, a value between -pi/2 and +pi/2.
const TReal & aSrcThe argument of the arctan function, a value between +infinity and +infinity.

ATan(TReal &, const TReal &, const TReal &)

IMPORT_C TIntATan(TReal &aTrg,
const TReal &aSrcY,
const TReal &aSrcX
)[static]

Calculates the angle between the x-axis and a line drawn from the origin to a point represented by its (x,y) co-ordinates.

The co-ordinates are passed as arguments to the function. This function returns the same result as arctan(y/x), but:

1. it adds +/-pi to the result, if x is negative

2. it sets the result to +/-pi/2, if x is zero but y is non-zero.

Parameters

TReal & aTrgA reference containing the result in radians, a value between -pi exclusive and +pi inclusive.
const TReal & aSrcYThe y argument of the arctan(y/x) function.
const TReal & aSrcXThe x argument of the arctan(y/x) function.

Cos(TReal &, const TReal &)

IMPORT_C TIntCos(TReal &aTrg,
const TReal &aSrc
)[static]

Calculates the cosine of a number.

Parameters

TReal & aTrgA reference containing the result.
const TReal & aSrcThe argument of the cos function in radians

DivMod64(Int64, Int64, Int64 &)

IMPORT_C Int64DivMod64(Int64aDividend,
Int64aDivisor,
Int64 &aRemainder
)[static]

Divides aDividend by aDivisor.

The quotient is returned, and the remainder is stored in aRemainder. The remainder has same sign as the dividend.

Parameters

Int64 aDividendThe 64-bit dividend.
Int64 aDivisorThe 64-bit divisor.
Int64 & aRemainderThe 64-bit remainder.

Exp(TReal &, const TReal &)

IMPORT_C TIntExp(TReal &aTrg,
const TReal &aSrc
)[static]

Calculates the value of e to the power of x.

Parameters

TReal & aTrgA reference containing the result.
const TReal & aSrcThe power to which e is to be raised.

FRand(TInt64 &)

IMPORT_C TRealFRand(TInt64 &aSeed)[static]

Generates a stream of uniformly distributed pseudo-random real numbers in the range, 0 to 1.

Parameters

TInt64 & aSeedA reference to a 64-bit seed, which is updated as a result of the call.

Frac(TReal &, const TReal &)

IMPORT_C TIntFrac(TReal &aTrg,
const TReal &aSrc
)[static]

Calculates the fractional part of a number.

The fractional part is that after a decimal point. Truncation is toward zero, so that Frac(2.4)=0.4, Frac(2)=0, Frac(-1)=0, Frac(-1.4)=0.4.

Parameters

TReal & aTrgA reference containing the result.
const TReal & aSrcThe number whose fractional part is required.

Int(TReal &, const TReal &)

IMPORT_C TIntInt(TReal &aTrg,
const TReal &aSrc
)[static]

Calculates the integer part of a number.

The integer part is that before a decimal point. Truncation is toward zero, so that int(2.4)=2, int(2)=2, int(-1)=-1, int(-1.4)=-1, int(-1.999)=-1.

Parameters

TReal & aTrgA reference containing the result.
const TReal & aSrcThe number whose integer part is required.

Int(TInt16 &, const TReal &)

IMPORT_C TIntInt(TInt16 &aTrg,
const TReal &aSrc
)[static]

Calculates the integer part of a number.

The integer part is that before a decimal point. Truncation is toward zero, so that int(2.4)=2, int(2)=2, int(-1)=-1, int(-1.4)=-1, int(-1.999)=-1.

This function is suitable when the result is known to be small enough for a 16-bit signed integer.

Parameters

TInt16 & aTrgA reference containing the result.
const TReal & aSrcThe number whose integer part is required.

Int(TInt32 &, const TReal &)

IMPORT_C TIntInt(TInt32 &aTrg,
const TReal &aSrc
)[static]

Calculates the integer part of a number.

The integer part is that before a decimal point. Truncation is toward zero, so that int(2.4)=2, int(2)=2, int(-1)=-1, int(-1.4)=-1, int(-1.999)=-1.

This function is suitable when the result is known to be small enough for a 32-bit signed integer.

Parameters

TInt32 & aTrgA reference containing the result.
const TReal & aSrcThe number whose integer part is required.

IsFinite(const TReal &)

IMPORT_C TBoolIsFinite(const TReal &aVal)[static]

Determines whether a value is finite.

In this context, a value is finite if it is a valid number and is not infinite.

Parameters

const TReal & aValA reference to the value to be checked.

IsInfinite(const TReal &)

IMPORT_C TBoolIsInfinite(const TReal &aVal)[static]

Determines whether a value is infinite.

Parameters

const TReal & aValA reference to the value to be checked.

IsNaN(const TReal &)

IMPORT_C TBoolIsNaN(const TReal &aVal)[static]

Determines whether a value is not a number.

Parameters

const TReal & aValA reference to the value to be checked.

IsZero(const TReal &)

IMPORT_C TBoolIsZero(const TReal &aVal)[static]

Determines whether a value is zero.

Parameters

const TReal & aValA reference to the value to be checked.

Ln(TReal &, const TReal &)

IMPORT_C TIntLn(TReal &aTrg,
const TReal &aSrc
)[static]

Calculates the natural logarithm of a number.

Parameters

TReal & aTrgA reference containing the result.
const TReal & aSrcThe number whose natural logarithm is required.

Log(TReal &, const TReal &)

IMPORT_C TIntLog(TReal &aTrg,
const TReal &aSrc
)[static]

Calculates the logarithm to base 10 of a number.

Parameters

TReal & aTrgA reference containing the result.
const TReal & aSrcThe number whose logarithm is required.

Mod(TReal &, const TReal &, const TReal &)

IMPORT_C TIntMod(TReal &aTrg,
const TReal &aSrc,
const TReal &aModulus
)[static]

Calculates the modulo remainder.

This is the value of p mod q, the modulo remainder when dividing p by q. The result is given by p - q int (p/q): it has the same sign as p: thus, 5 mod 3 = 2, -5 mod 3 = -2. No error is raised if non-integer arguments are passed.

Parameters

TReal & aTrgA reference containing the result.
const TReal & aSrcThe p argument to the mod function.
const TReal & aModulusThe q argument to the mod function.

Mul64(Int64, Int64, Int64 &, Uint64 &)

IMPORT_C voidMul64(Int64aX,
Int64aY,
Int64 &aOutH,
Uint64 &aOutL
)[static]

Multiply aX by aY to generate a 128 bit result.

The high order 64 bits of this calculation are stored in aOutH, and the low order 64 bits are stored in aOutL.

Parameters

Int64 aXThe first 64-bit operand.
Int64 aYThe second 64-bit operand.
Int64 & aOutHThe high order 64 bits of the result.
Uint64 & aOutLThe low order 64 bits of the result.

MultPow10X(TRealX &, TInt)

TInt MultPow10X(TRealX &aTrg,
TIntaPower
)[static]

Parameters

TRealX & aTrg
TInt aPower

Poly(TReal, const SPoly *)

IMPORT_C TRealPoly(TRealaVal,
const SPoly *aPoly
)[static]

Evaluates the polynomial: {a[n]X^n + a[n-1]X^(n-1) + ... + a[2]X^2 + a[1]X^1 + a[0]}.

Parameters

TReal aValThe value of the x-variable
const SPoly * aPolyA pointer to the structure containing the set of coefficients in the order: a[0], a[1], ..., a[n-1], a[n].

PolyX(TRealX &, const TRealX &, TInt, const TRealX *)

IMPORT_C voidPolyX(TRealX &aY,
const TRealX &aX,
TIntaDeg,
const TRealX *aCoef
)[static]

Evaluates the polynomial: {a[n]X^n + a[n-1]X^(n-1) + ... + a[2]X^2 + a[1]X^1 + a[0]}.

Parameters

TRealX & aYA reference containing the result.
const TRealX & aXThe value of the x-variable.
TInt aDegThe degree of the polynomial (the highest power of x which is present).
const TRealX * aCoefA pointer to a contiguous set of TRealX values containing the coefficients. They must be in the order: a[0], a[1], ..., a[n-1], a[n].

Pow(TReal &, const TReal &, const TReal &)

IMPORT_C TIntPow(TReal &aTrg,
const TReal &aSrc,
const TReal &aPower
)[static]

Calculates the value of x raised to the power of y.

The behaviour conforms to that specified for pow() in the ISO C Standard ISO/IEC 9899 (Annex F), although floating-point exceptions are not supported.

Parameters

TReal & aTrgA reference containing the result.
const TReal & aSrcThe x argument of the function.
const TReal & aPowerThe y argument of the function.

Pow10(TReal &, const TInt)

IMPORT_C TIntPow10(TReal &aTrg,
const TIntexp
)[static]

Calculates the value of 10 to the power of x.

Parameters

TReal & aTrgA reference containing the result.
const TInt expThe power to which 10 is to be raised.

Rand(TInt64 &)

IMPORT_C TIntRand(TInt64 &aSeed)[static]

Generates a stream of uniformly distributed pseudo-random integers in the range, 0 to KMaxTInt.

For each stream of pseudo-random numbers you wish to generate, you should pass the reference to the same 64-bit seed on each call to this function. You should not change the seed between calls.

Parameters

TInt64 & aSeedA reference to a 64-bit seed, which is updated as a result of the call.

Random()

IMPORT_C TUint32Random()[static]

Gets 32 random bits from the kernel's random number generator.

The returned random data may or may not be cryptographically secure but should be of a high quality for non-cryptographic purposes.

This function uses a cryptographically strong random number generator to generate the random data, which can be slower than insecure generators. If security is not important, a faster generator may be used such as Math::Rand().

Random(TDes8 &)

IMPORT_C voidRandom(TDes8 &aRandomValue)[static]

Fills the provided descriptor with random data up to its current length. The number of random bytes required should be specified by setting the length of the descriptor that is passed to this function.

The returned random data may or may not be cryptographically secure but should be of a high quality for non-cryptographic purposes.

This function uses a cryptographically strong random number generator to generate the random data, which can be slower than insecure generators. If security is not important, a faster generator may be used such as Math::Rand().

Parameters

TDes8 & aRandomValueon return, the descriptor is filled with the requested number of random bytes.

RandomL(TDes8 &)

IMPORT_C voidRandomL(TDes8 &aRandomValue)[static]

Fills the provided descriptor with random data up to its current length. The number of random bytes required should be specified by setting the length of the descriptor that is passed to the function.

If the returned random data cannot be guaranteed to be cryptographically secure, the function will leave with KErrNotReady to indicate that the returned data should not be used for cryptographic purposes.

The security strength of the cryptographically strong random number generator is 256 bits.

leave
KErrNotReady if the returned random data cannot be guaranteed to be cryptographically secure.

Parameters

TDes8 & aRandomValueon return, the descriptor is filled with the requested number of random bytes.

RandomL()

IMPORT_C TUint32RandomL()[static]

Gets 32 random bits from the kernel's random number generator.

If the returned random data could not be guaranteed to be cryptographically secure, the function will instead leave with KErrNotReady to indicate that data was not available.

The security strength of the cryptographically strong random number generator is 256 bits.

leave
KErrNotReady if no data was returned as it could not be guaranteed to be cryptographically secure.

Round(TReal &, const TReal &, TInt)

IMPORT_C TIntRound(TReal &aTrg,
const TReal &aSrc,
TIntaDecimalPlaces
)[static]

Rounds to a specified number of decimal places.

The function rounds a number to a given number, n, of decimal places. Rounding may be thought of as multiplying the number by 10 to the power of n, rounding to the nearest integer, and then dividing the result by 10 to the power of n and returning that as the answer.

In the process of rounding, numbers ending with .5 are rounded away from zero, so that 1.5 becomes 2, 2.5 becomes 3, -1.5 becomes -2, etc.

Parameters

TReal & aTrgA reference containing the result.
const TReal & aSrcThe number to be rounded.
TInt aDecimalPlacesThe number of decimal places to round to: must be zero or positive.

SetInfinite(TReal &, TInt)

IMPORT_C voidSetInfinite(TReal &aVal,
TIntaSign
)[private, static]

Parameters

TReal & aVal
TInt aSign

SetNaN(TReal &)

IMPORT_C voidSetNaN(TReal &aVal)[private, static]

Parameters

TReal & aVal

SetZero(TReal &, TInt)

IMPORT_C voidSetZero(TReal &aVal,
TIntaSign = 0
)[private, static]

Parameters

TReal & aVal
TInt aSign = 0

Sin(TReal &, const TReal &)

IMPORT_C TIntSin(TReal &aTrg,
const TReal &aSrc
)[static]

Calculates the sine of a number.

Parameters

TReal & aTrgA reference containing the result.
const TReal & aSrcThe argument of the sin function in radians.

Sqrt(TReal &, const TReal &)

IMPORT_C TIntSqrt(TReal &aTrg,
const TReal &aSrc
)[static]

Calculates the square root of a number.

Parameters

TReal & aTrgA reference containing the result.
const TReal & aSrcThe number whose square-root is required.

Tan(TReal &, const TReal &)

IMPORT_C TIntTan(TReal &aTrg,
const TReal &aSrc
)[static]

Calculates the tangent of a number.

Parameters

TReal & aTrgA reference containing the result.
const TReal & aSrcThe argument of the tan function in radians.

UDivMod64(Uint64, Uint64, Uint64 &)

IMPORT_C Uint64UDivMod64(Uint64aDividend,
Uint64aDivisor,
Uint64 &aRemainder
)[static]

Divides aDividend by aDivisor.

The quotient is returned, and the remainder is stored in aRemainder.

Parameters

Uint64 aDividendThe 64-bit dividend.
Uint64 aDivisorThe 64-bit divisor.
Uint64 & aRemainderThe 64-bit remainder.

UMul64(Uint64, Uint64, Uint64 &, Uint64 &)

IMPORT_C voidUMul64(Uint64aX,
Uint64aY,
Uint64 &aOutH,
Uint64 &aOutL
)[static]

Multiply aX by aY to generate a 128 bit result.

The high order 64 bits of this calculation are stored in aOutH, and the low order 64 bits are stored in aOutL.

Parameters

Uint64 aXThe first 64-bit operand.
Uint64 aYThe second 64-bit operand.
Uint64 & aOutHThe high order 64 bits of the result.
Uint64 & aOutLThe low order 64 bits of the result.