home *** CD-ROM | disk | FTP | other *** search
/ Power-Programmierung / CD1.mdf / modula2 / tutorial / programs / realmath.mod < prev    next >
Text File  |  1993-03-14  |  2KB  |  48 lines

  1.                                          (* Chapter 3 - Program 4 *)
  2. MODULE RealMath;
  3.  
  4. FROM InOut IMPORT WriteString, WriteLn;
  5. FROM RealInOut IMPORT WriteReal;
  6. FROM MathLib0 IMPORT sin, cos; (* Your system may use a different
  7.                                   name for either the module or the
  8.                                   trig functions.                   *)
  9.  
  10. VAR Sum, Diff, Product, Div : REAL;
  11.     A, B    : REAL;
  12.     Inumber : INTEGER;
  13.     Cnumber : CARDINAL;
  14.  
  15. BEGIN
  16.    A := 3.234;                      (* Assigns a value          *)
  17.    B := A + 1.0123;                 (* Add a constant           *)
  18.    Sum := A + B;                    (* Add two variables        *)
  19.    Product := A * B;                (* Multiplication           *)
  20.    Div := A / B;                    (* Division                 *)
  21.    Diff := A - B;                   (* Subtraction              *)
  22.    A := (A + B)/(12.345 * A - B);   (* Multiple math expression *)
  23.    B := sin(A)*cos(B);
  24.  
  25.    WriteString("The REAL values are");
  26.    WriteReal(Sum,12);
  27.    WriteString("  ");
  28.    WriteReal(Diff,12);
  29.    WriteString("  ");
  30.    WriteReal(Product,12);
  31.    WriteString("  ");
  32.    WriteReal(Div,12);
  33.    WriteLn;
  34.  
  35.          (* Conversion between data types - illustration  *)
  36.  
  37.    Inumber := 15;          (* This is an INTEGER              *)
  38.    Cnumber := 333;         (* This is a CARDINAL              *)
  39.    A := FLOAT(Inumber);    (* INTEGER to REAL                 *)
  40.    B := FLOAT(Cnumber);    (* CARDINAL to REAL                *)
  41.    Inumber := TRUNC(Sum);  (* REAL to INTEGER                 *)
  42.    Cnumber := TRUNC(Sum);  (* REAL to CARDINAL                *)
  43.  
  44.    A := MIN(REAL);   (* This produces the smallest REAL *)
  45.    A := MAX(REAL);   (* This produces the largest REAL  *)
  46.  
  47. END RealMath.
  48.