____ | Up | Next | Back | Forward
TOC -- / --.-- / --.--.-- | Index | Search | Syntax | Help


A.5.1 Elementary Functions

(1)
Implementation-defined approximations to the mathematical functions known as the ``elementary functions'' are provided by the subprograms in Numerics.Generic_Elementary_Functions. Nongeneric equivalents of this generic package for each of the predefined floating point types are also provided as children of Numerics.
Static Semantics
(2)
The generic library package Numerics.Generic_Elementary_Functions has the following declaration:
(3)
       generic
          type Float_Type is digits <>;
       package Ada.Numerics.Generic_Elementary_Functions is
          pragma Pure(Generic_Elementary_Functions);
(4)
          function Sqrt    (X           : Float_Type'Base)        return Float_Type'Base;
          function Log     (X           : Float_Type'Base)        return Float_Type'Base;
          function Log     (X, Base     : Float_Type'Base)        return Float_Type'Base;
          function Exp     (X           : Float_Type'Base)        return Float_Type'Base;
          function "**"    (Left, Right : Float_Type'Base)        return Float_Type'Base;
(5)
          function Sin     (X           : Float_Type'Base)        return Float_Type'Base;
          function Sin     (X, Cycle    : Float_Type'Base)        return Float_Type'Base;
          function Cos     (X           : Float_Type'Base)        return Float_Type'Base;
          function Cos     (X, Cycle    : Float_Type'Base)        return Float_Type'Base;
          function Tan     (X           : Float_Type'Base)        return Float_Type'Base;
          function Tan     (X, Cycle    : Float_Type'Base)        return Float_Type'Base;
          function Cot     (X           : Float_Type'Base)        return Float_Type'Base;
          function Cot     (X, Cycle    : Float_Type'Base)        return Float_Type'Base;
(6)
          function Arcsin  (X           : Float_Type'Base)        return Float_Type'Base;
          function Arcsin  (X, Cycle    : Float_Type'Base)        return Float_Type'Base;
          function Arccos  (X           : Float_Type'Base)        return Float_Type'Base;
          function Arccos  (X, Cycle    : Float_Type'Base)        return Float_Type'Base;
          function Arctan  (Y           : Float_Type'Base;
                            X           : Float_Type'Base := 1.0) return Float_Type'Base;
          function Arctan  (Y           : Float_Type'Base;
                            X           : Float_Type'Base := 1.0;
                            Cycle       : Float_Type'Base)        return Float_Type'Base;
          function Arccot  (X           : Float_Type'Base;
                            Y           : Float_Type'Base := 1.0) return Float_Type'Base;
          function Arccot  (X           : Float_Type'Base;
                            Y           : Float_Type'Base := 1.0;
                            Cycle       : Float_Type'Base)        return Float_Type'Base;
(7)
          function Sinh    (X           : Float_Type'Base)        return Float_Type'Base;
          function Cosh    (X           : Float_Type'Base)        return Float_Type'Base;
          function Tanh    (X           : Float_Type'Base)        return Float_Type'Base;
          function Coth    (X           : Float_Type'Base)        return Float_Type'Base;
          function Arcsinh (X           : Float_Type'Base)        return Float_Type'Base;
          function Arccosh (X           : Float_Type'Base)        return Float_Type'Base;
          function Arctanh (X           : Float_Type'Base)        return Float_Type'Base;
          function Arccoth (X           : Float_Type'Base)        return Float_Type'Base;
(8)
       end Ada.Numerics.Generic_Elementary_Functions;
(9)
The library package Numerics.Elementary_Functions defines the same subprograms as Numerics.Generic_Elementary_Functions, except that the predefined type Float is systematically substituted for Float_Type'Base throughout. Nongeneric equivalents of Numerics.Generic_Elementary_Functions for each of the other predefined floating point types are defined similarly, with the names Numerics.Short_Elementary_Functions, Numerics.Long_Elementary_Functions, etc.
(10)
The functions have their usual mathematical meanings. When the Base parameter is specified, the Log function computes the logarithm to the given base; otherwise, it computes the natural logarithm. When the Cycle parameter is specified, the parameter X of the forward trigonometric functions (Sin, Cos, Tan, and Cot) and the results of the inverse trigonometric functions (Arcsin, Arccos, Arctan, and Arccot) are measured in units such that a full cycle of revolution has the given value; otherwise, they are measured in radians.
(11)
The computed results of the mathematically multivalued functions are rendered single-valued by the following conventions, which are meant to imply the principal branch:
(12)
(13)
(14)
(15)
(16)
(17)
(18)
(In the case of the inverse trigonometric functions, in which a result lying on or near one of the axes may not be exactly representable, the approximation inherent in computing the result may place it in an adjacent quadrant, close to but on the wrong side of the axis.)
Dynamic Semantics
(19)
The exception Numerics.Argument_Error is raised, signaling a parameter value outside the domain of the corresponding mathematical function, in the following cases:
(20)
(21)
(22)
(23)
(24)
(25)
(26)
(27)
(28)
The exception Constraint_Error is raised, signaling a pole of the mathematical function (analogous to dividing by zero), in the following cases, provided that Float_Type'Machine_Overflows is True:
(29)
(30)
(31)
(32)
(33)
(34)
Constraint_Error can also be raised when a finite result overflows (see G.2.4); this may occur for parameter values sufficiently near poles, and, in the case of some of the functions, for parameter values with sufficiently large magnitudes. When Float_Type'Machine_Overflows is False, the result at poles is unspecified.
(35)
When one parameter of a function with multiple parameters represents a pole and another is outside the function's domain, the latter takes precedence (i.e., Numerics.Argument_Error is raised).
Implementation Requirements
(36)
In the implementation of Numerics.Generic_Elementary_Functions, the range of intermediate values allowed during the calculation of a final result shall not be affected by any range constraint of the subtype Float_Type.
(37)
In the following cases, evaluation of an elementary function shall yield the prescribed result, provided that the preceding rules do not call for an exception to be raised:
(38)
(39)
(40)
(41)
(42)
(43)
Other accuracy requirements for the elementary functions, which apply only in implementations conforming to the Numerics Annex, and then only in the ``strict'' mode defined there (see G.2), are given in G.2.4.
(44)
When Float_Type'Signed_Zeros is True, the sign of a zero result shall be as follows:
(45)
(46)
(47)
Implementation Permissions
(48)
The nongeneric equivalent packages may, but need not, be actual instantiations of the generic package for the appropriate predefined type.

____ | Up | Next | Back | Forward
TOC -- / --.-- / --.--.-- | Index | Search | Syntax | Help

Ada WWW Home -- Email comments, additions, corrections, gripes, kudos, etc. to:

Magnus Kempe -- Magnus.Kempe@di.epfl.ch
Copyright statement
Page last generated: 95-03-12