Implementation Advice
Static Semantics
generic type Real is digits <>; package Ada.Numerics.Generic_Complex_Types is pragma Pure(Generic_Complex_Types);
type Complex is record Re, Im : Real'Base; end record;
type Imaginary is private;
i : constant Imaginary; j : constant Imaginary;
function Re (X : Complex) return Real'Base; function Im (X : Complex) return Real'Base; function Im (X : Imaginary) return Real'Base;
procedure Set_Re (X : in out Complex; Re : in Real'Base); procedure Set_Im (X : in out Complex; Im : in Real'Base); procedure Set_Im (X : out Imaginary; Im : in Real'Base);
function Compose_From_Cartesian (Re, Im : Real'Base) return Complex; function Compose_From_Cartesian (Re : Real'Base) return Complex; function Compose_From_Cartesian (Im : Imaginary) return Complex;
function Modulus (X : Complex) return Real'Base; function "abs" (Right : Complex) return Real'Base renames Modulus;
function Argument (X : Complex) return Real'Base; function Argument (X : Complex; Cycle : Real'Base) return Real'Base;
function Compose_From_Polar (Modulus, Argument : Real'Base) return Complex; function Compose_From_Polar (Modulus, Argument, Cycle : Real'Base) return Complex;
function "+" (Right : Complex) return Complex; function "-" (Right : Complex) return Complex; function Conjugate (X : Complex) return Complex;
function "+" (Left, Right : Complex) return Complex; function "-" (Left, Right : Complex) return Complex; function "*" (Left, Right : Complex) return Complex; function "/" (Left, Right : Complex) return Complex;
function "**" (Left : Complex; Right : Integer) return Complex;
function "+" (Right : Imaginary) return Imaginary; function "-" (Right : Imaginary) return Imaginary; function Conjugate (X : Imaginary) return Imaginary renames "-"; function "abs" (Right : Imaginary) return Real'Base;
function "+" (Left, Right : Imaginary) return Imaginary; function "-" (Left, Right : Imaginary) return Imaginary; function "*" (Left, Right : Imaginary) return Real'Base; function "/" (Left, Right : Imaginary) return Real'Base;
function "**" (Left : Imaginary; Right : Integer) return Complex;
function "<" (Left, Right : Imaginary) return Boolean; function "<=" (Left, Right : Imaginary) return Boolean; function ">" (Left, Right : Imaginary) return Boolean; function ">=" (Left, Right : Imaginary) return Boolean;
function "+" (Left : Complex; Right : Real'Base) return Complex; function "+" (Left : Real'Base; Right : Complex) return Complex; function "-" (Left : Complex; Right : Real'Base) return Complex; function "-" (Left : Real'Base; Right : Complex) return Complex; function "*" (Left : Complex; Right : Real'Base) return Complex; function "*" (Left : Real'Base; Right : Complex) return Complex; function "/" (Left : Complex; Right : Real'Base) return Complex; function "/" (Left : Real'Base; Right : Complex) return Complex;
function "+" (Left : Complex; Right : Imaginary) return Complex; function "+" (Left : Imaginary; Right : Complex) return Complex; function "-" (Left : Complex; Right : Imaginary) return Complex; function "-" (Left : Imaginary; Right : Complex) return Complex; function "*" (Left : Complex; Right : Imaginary) return Complex; function "*" (Left : Imaginary; Right : Complex) return Complex; function "/" (Left : Complex; Right : Imaginary) return Complex; function "/" (Left : Imaginary; Right : Complex) return Complex;
function "+" (Left : Imaginary; Right : Real'Base) return Complex; function "+" (Left : Real'Base; Right : Imaginary) return Complex; function "-" (Left : Imaginary; Right : Real'Base) return Complex; function "-" (Left : Real'Base; Right : Imaginary) return Complex; function "*" (Left : Imaginary; Right : Real'Base) return Imaginary; function "*" (Left : Real'Base; Right : Imaginary) return Imaginary; function "/" (Left : Imaginary; Right : Real'Base) return Imaginary; function "/" (Left : Real'Base; Right : Imaginary) return Imaginary;
private
type Imaginary is new Real'Base; i : constant Imaginary := 1.0; j : constant Imaginary := 1.0;
end Ada.Numerics.Generic_Complex_Types;
Dynamic Semantics
Static Semantics
with Ada.Numerics.Generic_Complex_Types; generic with package Complex_Types is new Ada.Numerics.Generic_Complex_Types (<>); use Complex_Types; package Ada.Numerics.Generic_Complex_Elementary_Functions is pragma Pure(Generic_Complex_Elementary_Functions);
function Sqrt (X : Complex) return Complex; function Log (X : Complex) return Complex; function Exp (X : Complex) return Complex; function Exp (X : Imaginary) return Complex; function "**" (Left : Complex; Right : Complex) return Complex; function "**" (Left : Complex; Right : Real'Base) return Complex; function "**" (Left : Real'Base; Right : Complex) return Complex;
function Sin (X : Complex) return Complex; function Cos (X : Complex) return Complex; function Tan (X : Complex) return Complex; function Cot (X : Complex) return Complex;
function Arcsin (X : Complex) return Complex; function Arccos (X : Complex) return Complex; function Arctan (X : Complex) return Complex; function Arccot (X : Complex) return Complex;
function Sinh (X : Complex) return Complex; function Cosh (X : Complex) return Complex; function Tanh (X : Complex) return Complex; function Coth (X : Complex) return Complex;
function Arcsinh (X : Complex) return Complex; function Arccosh (X : Complex) return Complex; function Arctanh (X : Complex) return Complex; function Arccoth (X : Complex) return Complex;
end Ada.Numerics.Generic_Complex_Elementary_Functions;
with Ada.Numerics.Generic_Complex_Types; generic with package Complex_Types is new Ada.Numerics.Generic_Complex_Types (<>); package Ada.Text_IO.Complex_IO is
use Complex_Types;
Default_Fore : Field := 2; Default_Aft : Field := Real'Digits - 1; Default_Exp : Field := 3;
procedure Get (File : in File_Type; Item : out Complex; Width : in Field := 0); procedure Get (Item : out Complex; Width : in Field := 0);
procedure Put (File : in File_Type; Item : in Complex; Fore : in Field := Default_Fore; Aft : in Field := Default_Aft; Exp : in Field := Default_Exp); procedure Put (Item : in Complex; Fore : in Field := Default_Fore; Aft : in Field := Default_Aft; Exp : in Field := Default_Exp);
procedure Get (From : in String; Item : out Complex; Last : out Positive); procedure Put (To : out String; Item : in Complex; Aft : in Field := Default_Aft; Exp : in Field := Default_Exp);
end Ada.Text_IO.Complex_IO;
procedure Get (File : in File_Type; Item : out Complex; Width : in Field := 0); procedure Get (Item : out Complex; Width : in Field := 0);
procedure Put (File : in File_Type; Item : in Complex; Fore : in Field := Default_Fore; Aft : in Field := Default_Aft; Exp : in Field := Default_Exp); procedure Put (Item : in Complex; Fore : in Field := Default_Fore; Aft : in Field := Default_Aft; Exp : in Field := Default_Exp);
procedure Get (From : in String; Item : out Complex; Last : out Positive);
procedure Put (To : out String; Item : in Complex; Aft : in Field := Default_Aft; Exp : in Field := Default_Exp);
Implementation Permissions
Static Semantics
Implementation Requirements
Yields the number of digits in the mantissa of the canonical form of the model numbers of T, see section Attributes of Floating Point Types. The value of this attribute shall be greater than or equal to Ceiling(d*log (10)/log (T'Machine_Radix))+1, where d is the requested decimal precision of T. In addition, it shall be less than or equal to the value of T'Machine_Mantissa. This attribute yields a value of the type universal_integer.
Yields the minimum exponent of the canonical form of the model numbers of T, see section Attributes of Floating Point Types. The value of this attribute shall be greater than or equal to the value of T'Machine_Emin. This attribute yields a value of the type universal_integer.
Yields the lower bound of the safe range of T. The value of this attribute shall be a model number of T and greater than or equal to the lower bound of the base range of T. In addition, if T is declared by a floating_point_definition or is derived from such a type, and the floating_point_definition includes a real_range_specification specifying a lower bound of lb, then the value of this attribute shall be less than or equal to lb; otherwise, it shall be less than or equal to -10.0 ** (4*d), where d is the requested decimal precision of T. This attribute yields a value of the type universal_real.
Yields the upper bound of the safe range of T. The value of this attribute shall be a model number of T and less than or equal to the upper bound of the base range of T. In addition, if T is declared by a floating_point_definition or is derived from such a type, and the floating_point_definition includes a real_range_specification specifying an upper bound of ub, then the value of this attribute shall be greater than or equal to ub; otherwise, it shall be greater than or equal to 10.0 ** (4*d), where d is the requested decimal precision of T. This attribute yields a value of the type universal_real.
Denotes a function (of a parameter X) whose specification is given in section Attributes of Floating Point Types. If X is a model number of T, the function yields X; otherwise, it yields the value obtained by rounding or truncating X to either one of the adjacent model numbers of T. Constraint_Error is raised if the resulting model number is outside the safe range of S. A zero result has the sign of X when S'Signed_Zeros is True.
+--------------------------------------------------------------+ | | | Tightly Approximated Elementary Function Results | | | +-----------------+----------+----------+------------+-------- + | | | | | | | | | | Exact | Exact | | | | | Result | Result | | | Value of | Value of | when Cycle | when | | Function | X | Y | Specified | Cycle | | | | | | Omitted | | | | | | | +-----------------+----------+----------+------------+---------+ | | | | | | | Arcsin | 1.0 | n.a. | Cycle/4.0 | Pi/2.0 | | | | | | | | Arcsin | -1.0 | n.a. | -Cycle/4.0 | -Pi/2.0 | | | | | | | | Arccos | 0.0 | n.a. | Cycle/4.0 | Pi/2.0 | | | | | | | | Arccos | -1.0 | n.a. | Cycle/2.0 | Pi | | | | | | | | Arctan & Arccot | 0.0 | positive | Cycle/4.0 | Pi/2.0 | | | | | | | | Arctan & Arccot | 0.0 | negative | -Cycle/4.0 | -Pi/2.0 | | | | | | | | Arctan & Arccot | negative | +0.0 | Cycle/2.0 | Pi | | | | | | | | Arctan & Arccot | negative | -0.0 | -Cycle/2.0 | -Pi | | | | | | | | Arctan & Arccot | negative | 0.0 | Cycle/2.0 | Pi | | | | | | | +-----------------+----------+----------+------------+---------+
Implementation Advice
+-----------------------------------------------------------------+ | | | Error Bounds for Particular Complex Functions | | | +-----------------------------+---------+-----------------+-------+ | | | | | | | Nature | Nature of | Error | | Function or Operator | of | Bound | Bound | | | Result | | | | | | | | +-----------------------------+---------+-----------------+-------+ | | | | | | Modulus | real | max. rel. error | 3.0 | | | | | | | Argument | real | max. rel. error | 4.0 | | | | | | | Compose_From_Polar | complex | max. rel. error | 3.0 | | | | | | | "*" (both operands complex) | complex | max. box error | 5.0 | | | | | | | "/" (right operand complex) | complex | max. box error | 13.0 | | | | | | | Sqrt | complex | max. rel. error | 6.0 | | | | | | | Log | complex | max. box error | 13.0 | | | | | | | Exp (complex parameter) | complex | max. rel. error | 7.0 | | | | | | | Exp (imaginary parameter) | complex | max. rel. error | 2.0 | | | | | | | Sin, Cos, Sinh, and Cosh | complex | max. rel. error | 11.0 | | | | | | | Tan, Cot, Tanh, and Coth | complex | max. rel. error | 35.0 | | | | | | | inverse trigonometric | complex | max. rel. error | 14.0 | | | | | | | inverse hyperbolic | complex | max. rel. error | 14.0 | | | | | | +-----------------------------+---------+-----------------+-------+
Go to the first, previous, next, last section, table of contents.