DEFINITION MODULE Numerical;

(*
    Title: 	Proper mathematical functions etc.
    LastEdit:	"Tue Aug 20 14:29:29 1985"
    Author: 	ahj
		Cambridge University Computer Laboratory
*)

EXPORT QUALIFIED Power, 
                 Round, RoundToInt, Frac,
                 TrueMOD, TrueDIV,
                 TwoPow, ThreePow,
                 justLessThanOne, realRelativePrecision, 
                 Even,
                 Floor, Ceiling;

VAR TwoPow : ARRAY [0..31] OF CARDINAL ;
    (* TwoPow [i] = 2**i *)
    
    ThreePow : ARRAY [0..20] OF CARDINAL ;
    (* ThreePow [i] = 3**i *)
    
    justLessThanOne, justGreaterThanOne : REAL ;
    (* The closest floating point numbers distinguishable from 1.0 *)
    
    realRelativePrecision : REAL ;
    (* The relative precision of the real representation on this machine,
       measured at 1.0 to within a factor of 2 *)

PROCEDURE Floor (r : REAL) : INTEGER ;

PROCEDURE Ceiling (r : REAL) : INTEGER ;

PROCEDURE Power (n : REAL ;
                 i : INTEGER) : REAL ;
(* Return n raised to the power i *)

PROCEDURE Round (Value : REAL) : REAL ;

PROCEDURE RoundToInt (Value : REAL) : INTEGER ;

PROCEDURE Frac (Value : REAL) : REAL ;
(* The fractional part of Value *)

PROCEDURE TrueMOD (a : INTEGER ; b : CARDINAL) : CARDINAL ;
(* Mathematical definition of MOD *)

PROCEDURE TrueDIV (a : INTEGER ; b : CARDINAL) : INTEGER ;
(* Mathematical definition of integer division *)

PROCEDURE Even (a: INTEGER) : BOOLEAN ;
(* Yet another characteristic of Wirth languages, ODD but no EVEN! *)

END Numerical.
