[net.sources] OSSI: SIMathLib

biagioni@unc.UUCP (Edoardo Biagioni) (11/06/86)

(***************************************************************************)
(***                                                                     ***)
(***                                                                     ***)
(***                     O  S  S  I                                      ***)
(***                     ==========                                      ***)
(***                                                                     ***)
(**)               DEFINITION MODULE SIMathLib;                          (**)
(***               ===========================                           ***)
(***                                                                     ***)
(***   Mathematical Library                                              ***)
(***                                                                     ***)
(***---------------------------------------------------------------------***)
(***                                                                     ***)
(***   Hardware:          independent                                    ***)
(***   Operating System:  independent                                    ***)
(***   Compiler:          independent                                    ***)
(***                                                                     ***)
(***   Version:      3.0                                                 ***)
(***   Implemented:  gh                                                  ***)
(***   Date:         1986-02-06                                          ***)
(***                                                                     ***)
(***---------------------------------------------------------------------***)
(***                                                                     ***)
(***   Copyright 1986 by                                                 ***)
(***      E. S. Biagioni                                                 ***)
(***      G. Heiser                                                      ***)
(***      K. Hinrichs                                                    ***)
(***      C. Muller                                                      ***)
(***                                                                     ***)
(***   Institut fuer Informatik                                          ***)
(***   ETH Zuerich                                                       ***)
(***   CH-8092 Zuerich                                                   ***)
(***   Switzerland                                                       ***)
(***                                                                     ***)
(***   Department of Computer Science                                    ***)
(***   University of North Carolina                                      ***)
(***   Chapel Hill, North Carolina 27514                                 ***)
(***   U.S.A.                                                            ***)
(***                                                                     ***)
(*** Permission to copy without fee all of this material is granted      ***)
(*** provided that the copies are not made or distributed for direct     ***)
(*** commercial advantage, that this OSSI copyright notice is            ***)
(*** included in the copy, that the module is not modified in any way    ***)
(*** except where necessary for compilation on a particular system,      ***)
(*** and that the module is always distributed in its original form.     ***)
(*** Distribution of this module in a modified form without including    ***)
(*** the original version is a violation of this copyright notice.       ***)
(***                                                                     ***)
(***---------------------------------------------------------------------***)
(***                                                                     ***)
(***   Updates:                                                          ***)
(***      1: 1986-04-03 gh:  Version 3.0                                 ***)
(***                                                                     ***)
(***************************************************************************)


FROM SISystem IMPORT
   BitsPerByte,
   BYTE;


EXPORT QUALIFIED
   SeedLength,            (* CONSTants *)
   pi,
   e,
   sqrt2,
   ln2,
   RandomSeed,            (* TYPEs *)
   CardMax,               (* Functions/PROCEDUREs *)
   CardMin,
   IntMax,
   IntMin,
   RealMax,
   RealMin,
   sqrt,
   exp,
   ln,
   log,
   power,
   sin,
   cos,
   tan,
   arcsin,
   arccos,
   arctan,
   arctan2,
   sinh,
   cosh,
   tanh,
   arsinh,
   arcosh,
   artanh,
   Degree,
   Radian,
   random,
   GetSeed,
   PutSeed;



(* The following are often needed mathematical constants  *)

CONST pi    = 3.14159265358979323846264338327950288;
      e     = 2.71828182845904523536028747135266250;
      sqrt2 = 1.41421356237309504880168872420969808;
      ln2   = 0.69314718055994530941723212145817657;


       (*  Min and Max functions  *)
       (*  =====================  *)

PROCEDURE CardMax (i, j: CARDINAL): CARDINAL;

PROCEDURE CardMin (i, j: CARDINAL): CARDINAL;

PROCEDURE IntMax  (i, j: INTEGER): INTEGER;

PROCEDURE IntMin  (i, j: INTEGER): INTEGER;

PROCEDURE RealMax (x, y: REAL): REAL;

PROCEDURE RealMin (x, y: REAL): REAL;


       (*  basic mathematical functions  *)
       (*  ============================  *)

PROCEDURE sqrt (x: REAL): REAL;

PROCEDURE exp  (x: REAL): REAL;

PROCEDURE ln   (x: REAL): REAL;  (*  natural logarithm  *)

PROCEDURE log  (x: REAL): REAL;  (*  decadic logarithm  *)

PROCEDURE power (x: REAL; i: INTEGER): REAL;    (*  x**i  *)


       (*  trigonometric functions, angles are in radians  *)
       (*  =======================                         *)

PROCEDURE sin (x: REAL): REAL;

PROCEDURE cos (x: REAL): REAL;

PROCEDURE tan (x: REAL): REAL;

PROCEDURE arcsin (x: REAL): REAL;

PROCEDURE arccos (x: REAL): REAL;

PROCEDURE arctan (x: REAL): REAL;

PROCEDURE arctan2 (x, y: REAL): REAL;    (*  arctan (y/x) in (-pi,pi]  *)


       (*  hyperbolic functions  *)
       (*  ====================  *)

PROCEDURE sinh (x: REAL): REAL;

PROCEDURE cosh (x: REAL): REAL;

PROCEDURE tanh (x: REAL): REAL;

PROCEDURE arsinh (x: REAL): REAL;

PROCEDURE arcosh (x: REAL): REAL;

PROCEDURE artanh (x: REAL): REAL;


       (*  angle conversion functions  *)
       (*  ==========================  *)

PROCEDURE Degree (radian: REAL): REAL;   (*  converts radians to degrees  *)

PROCEDURE Radian (degree: REAL): REAL;   (*  converts degrees to radians  *)


       (*  random number functions  *)
       (*  =======================  *)

CONST SeedLength = 32 DIV BitsPerByte;

TYPE RandomSeed = ARRAY [0..SeedLength-1] OF BYTE;

(* The seed is logically a CARDINAL, however it must be at least
   32 bits long in order to meet the specified period of the
   renadom number generator. The above type was choosen for the seed
   so it can be handeled in the same way on all machines irrespective
   of the word length.
   The only purpose of the seed is to enable a program to re-initialize
   the random number generator so it produces always the same sequence
   of numbers. At module initialization time, the generator is always
   initialized with the same seed.                                   *)

PROCEDURE random (): REAL;
      (*  return pseudo random number in [0,1).
          The random numbers are uniformly distributed,
          the period is at least 2**29 (using the default seed)  *)

PROCEDURE GetSeed (VAR seed: RandomSeed);
      (*  return the current value of the random seed  *)

PROCEDURE PutSeed (seed: RandomSeed);
      (*  set the value of the random seed  *)


END SIMathLib.