Trigonometric functions: Difference between revisions

Content deleted Content added
+D
Line 4: Line 4:
=={{header|Ada}}==
=={{header|Ada}}==
Ada provides library trig functions which default to radians along with corresponding library functions for which the cycle can be specified. The examples below specify the cycle for degrees and for radians. The output of the inverse trig functions is in units of the specified cycle (degrees or radians).
Ada provides library trig functions which default to radians along with corresponding library functions for which the cycle can be specified. The examples below specify the cycle for degrees and for radians. The output of the inverse trig functions is in units of the specified cycle (degrees or radians).
<pre>
with Ada.Numerics.Elementary_Functions;
use Ada.Numerics.Elementary_Functions;
with Ada.Numerics.Elementary_Functions;
use Ada.Numerics.Elementary_Functions;
with Ada.Float_Text_Io; use Ada.Float_Text_Io;
with Ada.Text_Io; use Ada.Text_Io;
with Ada.Float_Text_Io; use Ada.Float_Text_Io;
with Ada.Text_IO; use Ada.Text_IO;

procedure Trig is
procedure Trig is
Degrees_Cycle : constant Float := 360.0;
Radians_Cycle : constant Float := 2.0 * Ada.Numerics.Pi;
Degrees_Cycle : constant Float := 360.0;
Angle_Degrees : constant Float := 45.0;
Radians_Cycle : constant Float := 2.0 * Ada.Numerics.Pi;
Angle_Radians : constant Float := Ada.Numerics.Pi / 4.0;
Angle_Degrees : constant Float := 45.0;
Angle_Radians : constant Float := Ada.Numerics.Pi / 4.0;
begin
procedure Put (V1, V2 : Float) is
Put(Item => Sin(Angle_Degrees, Degrees_Cycle), Aft => 5, Exp => 0);
Put(" ");
begin
Put(Item => Sin(Angle_Radians, Radians_Cycle), Aft => 5, Exp => 0);
Put (V1, Aft => 5, Exp => 0);
New_Line;
Put (" ");
Put(Item => Cos(Angle_Degrees, Degrees_Cycle), Aft => 5, Exp => 0);
Put (V2, Aft => 5, Exp => 0);
Put(" ");
New_Line;
end Put;
Put(Item => Cos(Angle_Radians, Radians_Cycle), Aft => 5, Exp => 0);
begin
New_Line;
Put(Item => Tan(Angle_Degrees, Degrees_Cycle), Aft => 5, Exp => 0);
Put (Sin (Angle_Degrees, Degrees_Cycle),
Sin (Angle_Radians, Radians_Cycle));
Put(" ");
Put (Cos (Angle_Degrees, Degrees_Cycle),
Put(Item => Tan(Angle_Radians, Radians_Cycle), Aft => 5, Exp => 0);
Cos (Angle_Radians, Radians_Cycle));
New_Line;
Put(Item => Cot(Angle_Degrees, Degrees_Cycle), Aft => 5, Exp => 0);
Put (Tan (Angle_Degrees, Degrees_Cycle),
Tan (Angle_Radians, Radians_Cycle));
Put(" ");
Put (Cot (Angle_Degrees, Degrees_Cycle),
Put(Item => Cot(Angle_Radians, Radians_Cycle), Aft => 5, Exp => 0);
Cot (Angle_Radians, Radians_Cycle));
New_Line;
Put(Item => ArcSin(Sin(Angle_Degrees, Degrees_Cycle), Degrees_Cycle), Aft => 5, Exp => 0);
Put (ArcSin (Sin (Angle_Degrees, Degrees_Cycle), Degrees_Cycle),
ArcSin (Sin (Angle_Radians, Radians_Cycle), Radians_Cycle));
Put(" ");
Put (Arccos (Cos (Angle_Degrees, Degrees_Cycle), Degrees_Cycle),
Put(Item => ArcSin(Sin(Angle_Radians, Radians_Cycle), Radians_Cycle), Aft => 5, Exp => 0);
Arccos (Cos (Angle_Radians, Radians_Cycle), Radians_Cycle));
New_Line;
Put(Item => Arccos(Cos(Angle_Degrees, Degrees_Cycle), Degrees_Cycle), Aft => 5, Exp => 0);
Put (Arctan (Y => Tan (Angle_Degrees, Degrees_Cycle)),
Arctan (Y => Tan (Angle_Radians, Radians_Cycle)));
Put(" ");
Put (Arccot (X => Cot (Angle_Degrees, Degrees_Cycle)),
Put(Item => Arccos(Cos(Angle_Radians, Radians_Cycle), Radians_Cycle), Aft => 5, Exp => 0);
Arccot (X => Cot (Angle_Degrees, Degrees_Cycle)));
New_Line;
end Trig;
Put(Item => Arctan(Y => Tan(Angle_Degrees, Degrees_Cycle), Cycle => Degrees_Cycle), Aft => 5, Exp => 0);
</pre>
Put(" ");
Put(Item => Arctan(Y => Tan(Angle_Radians, Radians_Cycle), Cycle => Radians_Cycle), Aft => 5, Exp => 0);
New_Line;
Put(Item => Arccot(X => Cot(Angle_Degrees, Degrees_Cycle), Cycle => Degrees_Cycle), Aft => 5, Exp => 0);
Put(" ");
Put(Item => Arccot(X => Cot(Angle_Degrees, Degrees_Cycle), Cycle => Radians_Cycle), Aft => 5, Exp => 0);
New_Line;
end Trig;


Output:
Output: