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,46 @@
(* Library Interface *)
DEFINITION MODULE Exponentiation;
PROCEDURE IntExp(base, exp : INTEGER) : INTEGER;
(* Raises base to the power of exp and returns the result
both base and exp must be of type INTEGER *)
PROCEDURE RealExp(base : REAL; exp : INTEGER) : REAL;
(* Raises base to the power of exp and returns the result
base must be of type REAL, exp of type INTEGER *)
END Exponentiation.
(* Library Implementation *)
IMPLEMENTATION MODULE Exponentiation;
PROCEDURE IntExp(base, exp : INTEGER) : INTEGER;
VAR
i, res : INTEGER;
BEGIN
res := 1;
FOR i := 1 TO exp DO
res := res * base;
END;
RETURN res;
END IntExp;
PROCEDURE RealExp(base: REAL; exp: INTEGER) : REAL;
VAR
i : INTEGER;
res : REAL;
BEGIN
res := 1.0;
IF exp < 0 THEN
FOR i := exp TO -1 DO
res := res / base;
END;
ELSE (* exp >= 0 *)
FOR i := 1 TO exp DO
res := res * base;
END;
END;
RETURN res;
END RealExp;
END Exponentiation.