Initial data commit

This commit is contained in:
Ingy döt Net 2023-07-01 11:58:00 -04:00
parent 72d218235f
commit f23f22d71c
199087 changed files with 3378941 additions and 0 deletions

View file

@ -0,0 +1,15 @@
package Integer_Exponentiation is
-- int^int
procedure Exponentiate (Argument : in Integer;
Exponent : in Natural;
Result : out Integer);
function "**" (Left : Integer;
Right : Natural) return Integer;
-- real^int
procedure Exponentiate (Argument : in Float;
Exponent : in Integer;
Result : out Float);
function "**" (Left : Float;
Right : Integer) return Float;
end Integer_Exponentiation;

View file

@ -0,0 +1,19 @@
with Ada.Float_Text_IO, Ada.Integer_Text_IO, Ada.Text_IO;
with Integer_Exponentiation;
procedure Test_Integer_Exponentiation is
use Ada.Float_Text_IO, Ada.Integer_Text_IO, Ada.Text_IO;
use Integer_Exponentiation;
R : Float;
I : Integer;
begin
Exponentiate (Argument => 2.5, Exponent => 3, Result => R);
Put ("2.5 ^ 3 = ");
Put (R, Fore => 2, Aft => 4, Exp => 0);
New_Line;
Exponentiate (Argument => -12, Exponent => 3, Result => I);
Put ("-12 ^ 3 = ");
Put (I, Width => 7);
New_Line;
end Test_Integer_Exponentiation;

View file

@ -0,0 +1,49 @@
package body Integer_Exponentiation is
-- int^int
procedure Exponentiate (Argument : in Integer;
Exponent : in Natural;
Result : out Integer) is
begin
Result := 1;
for Counter in 1 .. Exponent loop
Result := Result * Argument;
end loop;
end Exponentiate;
function "**" (Left : Integer;
Right : Natural) return Integer is
Result : Integer;
begin
Exponentiate (Argument => Left,
Exponent => Right,
Result => Result);
return Result;
end "**";
-- real^int
procedure Exponentiate (Argument : in Float;
Exponent : in Integer;
Result : out Float) is
begin
Result := 1.0;
if Exponent < 0 then
for Counter in Exponent .. -1 loop
Result := Result / Argument;
end loop;
else
for Counter in 1 .. Exponent loop
Result := Result * Argument;
end loop;
end if;
end Exponentiate;
function "**" (Left : Float;
Right : Integer) return Float is
Result : Float;
begin
Exponentiate (Argument => Left,
Exponent => Right,
Result => Result);
return Result;
end "**";
end Integer_Exponentiation;