-
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
-
The generic library package Numerics.Generic_Elementary_Functions has
the following declaration:
-
generic
type Float_Type is digits <>;
package Ada.Numerics.Generic_Elementary_Functions is
pragma Pure(Generic_Elementary_Functions);
-
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;
-
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;
-
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;
-
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;
-
end Ada.Numerics.Generic_Elementary_Functions;
-
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.
-
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.
-
The computed results of the mathematically multivalued functions are
rendered single-valued by the following conventions, which are meant to
imply the principal branch:
-
The results of the Sqrt and Arccosh functions and that of the
exponentiation operator are nonnegative.
-
The result of the Arcsin function is in the quadrant containing the
point (1.0, x), where x is the value of the parameter X. This quadrant
is I or IV; thus, the range of the Arcsin function is approximately
-Pi/2.0 to Pi/2.0 (-Cycle/4.0 to Cycle/4.0, if the parameter Cycle is
specified).
-
The result of the Arccos function is in the quadrant containing the
point (x, 1.0), where x is the value of the parameter X. This quadrant
is I or II; thus, the Arccos function ranges from 0.0 to approximately
Pi (Cycle/2.0, if the parameter Cycle is specified).
-
The results of the Arctan and Arccot functions are in the quadrant
containing the point (x, y), where x and y are the values of the
parameters X and Y, respectively. This may be any quadrant (I through
IV) when the parameter X (resp., Y) of Arctan (resp., Arccot) is
specified, but it is restricted to quadrants I and IV (resp., I and II)
when that parameter is omitted. Thus, the range when that parameter is
specified is approximately -Pi to Pi (-Cycle/2.0 to Cycle/2.0, if the
parameter Cycle is specified); when omitted, the range of Arctan (resp.,
Arccot) is that of Arcsin (resp., Arccos), as given above. When the
point (x, y) lies on the negative x-axis, the result approximates
-
Pi (resp., -Pi) when the sign of the parameter Y is positive (resp.,
negative), if Float_Type'Signed_Zeros is True;
-
Pi, if Float_Type'Signed_Zeros is False.