Math functions

Describes the maths functions used by application programs.

Calling syntax

Math functions are designed for use by application programs which must be able firstly to do the desired calculation and secondly to handle error conditions arising from the calculations. Thus, the ANSI-style functions of the form

double sin(double); // typical declaration
double x=1; // argument
double a; // result
a=sin(x); // typical use

are not implemented by the Symbian software platform. Rather, all functions return error information explicitly.

All functions are provided as static member functions of the Math class. This is a convenient packaging mechanism. A typical math function is thus declared like this:

class Math
    {
public:
    // ...
    static TInt Sin(TReal &aTrg,const TReal &aSrc);
    // ...
    };

and used like this:

TReal x=1; // argument
TReal a; // result
TInt matherror; // error indication
matherror=Math::ASin(a,x); // get result and error
User::LeaveIfError(matherror); // handle error

This syntax is unusual for those used to the ANSI library. However, the ANSI library functions are designed for speed, and for users whose programs control the valid range of the arguments, and can thus reasonably ensure that they are within range. The Math class, however, provides direct support to expression interpreters acting on numbers entered by users. In this context, error checking is a vital part of the process.

In most cases, the same variable may be used for both argument and result, i.e., Math::Sin(x,x) will work as expected, because the function has finished with the argument by the time the result is written to.

Precision

The TReal type is equated to double. With an IEEE754 floating-point implementation, this gives a range from about 2.225074 × 10 308 to about 1.797693 × 10+308, and an accuracy of 15 decimal places.

Error indications

All functions return a standard error code.