Symbian3/PDK/Source/GUID-AC99E9ED-2C02-561A-ABA4-DCDD415E8653.dita
changeset 1 25a17d01db0c
child 3 46218c8b8afa
equal deleted inserted replaced
0:89d6a7a84779 1:25a17d01db0c
       
     1 <?xml version="1.0" encoding="utf-8"?>
       
     2 <!-- Copyright (c) 2007-2010 Nokia Corporation and/or its subsidiary(-ies) All rights reserved. -->
       
     3 <!-- This component and the accompanying materials are made available under the terms of the License 
       
     4 "Eclipse Public License v1.0" which accompanies this distribution, 
       
     5 and is available at the URL "http://www.eclipse.org/legal/epl-v10.html". -->
       
     6 <!-- Initial Contributors:
       
     7     Nokia Corporation - initial contribution.
       
     8 Contributors: 
       
     9 -->
       
    10 <!DOCTYPE concept
       
    11   PUBLIC "-//OASIS//DTD DITA Concept//EN" "concept.dtd">
       
    12 <concept id="GUID-AC99E9ED-2C02-561A-ABA4-DCDD415E8653" xml:lang="en"><title>Math
       
    13 functions</title><shortdesc>Describes the maths functions used by application programs.</shortdesc><prolog><metadata><keywords/></metadata></prolog><conbody>
       
    14 <section id="GUID-965ABD80-2C30-43D1-8F40-7BF573301630"><title>Calling syntax</title> <p>Math functions are designed for
       
    15 use by application programs which must be able firstly to do the desired calculation
       
    16 and secondly to handle error conditions arising from the calculations. Thus,
       
    17 the ANSI-style functions of the form</p> <codeblock id="GUID-C277F9D8-5FDD-5460-B059-DF02E36B4948" xml:space="preserve">double sin(double); // typical declaration</codeblock> <codeblock id="GUID-8A9C44FE-7EDF-59DB-AFE0-B48148CBE0C8" xml:space="preserve">double x=1; // argument
       
    18 double a; // result
       
    19 a=sin(x); // typical use</codeblock> <p>are not implemented by the Symbian
       
    20 software platform. Rather, all functions return error information explicitly.</p> <p>All
       
    21 functions are provided as static member functions of the <codeph>Math</codeph> class.
       
    22 This is a convenient packaging mechanism. A typical math function is thus
       
    23 declared like this:</p> <codeblock id="GUID-C363CF23-CE56-59FA-A4EB-2DA2AD886C0D" xml:space="preserve">class Math
       
    24     {
       
    25 public:
       
    26     // ...
       
    27     static TInt Sin(TReal &amp;aTrg,const TReal &amp;aSrc);
       
    28     // ...
       
    29     };</codeblock> <p>and used like this:</p> <codeblock id="GUID-EA13F019-D473-5757-B036-8461BD3B0143" xml:space="preserve">TReal x=1; // argument
       
    30 TReal a; // result
       
    31 TInt matherror; // error indication
       
    32 matherror=Math::ASin(a,x); // get result and error
       
    33 User::LeaveIfError(matherror); // handle error</codeblock> <p>This syntax
       
    34 is unusual for those used to the ANSI library. However, the ANSI library functions
       
    35 are designed for speed, and for users whose programs control the valid range
       
    36 of the arguments, and can thus reasonably ensure that they are within range.
       
    37 The <codeph>Math</codeph> class, however, provides direct support to expression
       
    38 interpreters acting on numbers entered by users. In this context, error checking
       
    39 is a vital part of the process.</p> <p>In most cases, the same variable may
       
    40 be used for both argument and result, i.e., <codeph>Math::Sin(x,x)</codeph> will
       
    41 work as expected, because the function has finished with the argument by the
       
    42 time the result is written to.</p> </section>
       
    43 <section id="GUID-8633E2E3-316D-40AE-9F88-77E6CF7FA041"><title>Precision</title> <p>The <codeph>TReal</codeph> type is equated
       
    44 to <codeph>double</codeph>. With an IEEE754 floating-point implementation,
       
    45 this gives a range from about 2.225074 × 10<sup>–</sup> <sup>308</sup> to
       
    46 about 1.797693 × 10<sup>+308</sup>, and an accuracy of 15 decimal places.</p> </section>
       
    47 <section id="GUID-2D26DDD3-FE18-4D0A-AC10-F445708750BB"><title>Error indications</title> <p>All functions return a standard
       
    48 error code. </p> </section>
       
    49 </conbody></concept>