home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / numana01.zip / DEF / MISCM2.DEF < prev    next >
Text File  |  1996-07-31  |  6KB  |  153 lines

  1. DEFINITION MODULE MiscM2;
  2.  
  3.         (********************************************************)
  4.         (*                                                      *)
  5.         (*          Miscellaneous utility procedures            *)
  6.         (*                                                      *)
  7.         (*  Programmer:         P. Moylan                       *)
  8.         (*  Last edited:        31 July 1996                    *)
  9.         (*  Status:             OK                              *)
  10.         (*                                                      *)
  11.         (*      The purpose of this module is to provide        *)
  12.         (*      the non-portable part of a numerical            *)
  13.         (*      analysis package - i.e. to separate out the     *)
  14.         (*      library dependencies, so that most of the       *)
  15.         (*      work in porting the software to another         *)
  16.         (*      compiler or library lies in rewriting this      *)
  17.         (*      (simple) module.                                *)
  18.         (*                                                      *)
  19.         (*      Many of the procedures here relate to output    *)
  20.         (*      to a screen window.  For use in an environment  *)
  21.         (*      which does not support screen windows, you      *)
  22.         (*      simply have to replace the definition of        *)
  23.         (*      type "Window" by a dummy definition, and let    *)
  24.         (*      the implementation ignore the "Window"          *)
  25.         (*      parameters.                                     *)
  26.         (*                                                      *)
  27.         (*      One catch with the present approach is that     *)
  28.         (*      it requires the concept of the "current         *)
  29.         (*      window".  Do not attempt to use this module     *)
  30.         (*      in multitasking applications, because if        *)
  31.         (*      more than one task is doing screen output       *)
  32.         (*      then there is an ambiguity in what constitutes  *)
  33.         (*      the current window.                             *)
  34.         (*                                                      *)
  35.         (********************************************************)
  36.  
  37. FROM SYSTEM IMPORT (*type*) ADDRESS;
  38. IMPORT LongMath;
  39.  
  40. TYPE Window = CARDINAL; (* in this version, effectively a dummy definition *)
  41.  
  42. (************************************************************************)
  43. (*                      MATHEMATICAL FUNCTIONS                          *)
  44. (************************************************************************)
  45.  
  46. CONST PI = LongMath.pi;
  47.  
  48. PROCEDURE Sqrt (x: LONGREAL): LONGREAL;
  49.  
  50.     (* Square root. *)
  51.  
  52. PROCEDURE Exp (x: LONGREAL): LONGREAL;
  53.  
  54.     (* Exponential. *)
  55.  
  56. PROCEDURE Log (x: LONGREAL): LONGREAL;
  57.  
  58.     (* Natural logarithm. *)
  59.  
  60. PROCEDURE Power (x, y: LONGREAL): LONGREAL;
  61.  
  62.     (* Computes x to the power of y. *)
  63.  
  64. PROCEDURE Sin (x: LONGREAL): LONGREAL;
  65.  
  66.     (* Sine of x (radians). *)
  67.  
  68. PROCEDURE Cos (x: LONGREAL): LONGREAL;
  69.  
  70.     (* Cosine of x (radians). *)
  71.  
  72. PROCEDURE ATan2 (x, y: LONGREAL): LONGREAL;
  73.  
  74.     (* Inverse tangent of y/x.  Result is in range -PI to PI. *)
  75.  
  76. (************************************************************************)
  77. (*                      MISCELLANEOUS UTILITIES                         *)
  78. (************************************************************************)
  79.  
  80. PROCEDURE BlockCopy (source, destination: ADDRESS;  bytecount: CARDINAL);
  81.  
  82.     (* Copies an array of bytes from the source address to the          *)
  83.     (* destination address.                                             *)
  84.  
  85. PROCEDURE AddOffset (A: ADDRESS;  increment: CARDINAL): ADDRESS;
  86.  
  87.     (* Returns a pointer to the memory location whose physical address  *)
  88.     (* is Physical(A)+increment.  It is assumed that the caller will    *)
  89.     (* never try to run off the end of a segment.                       *)
  90.  
  91. PROCEDURE LongRealToString (number: LONGREAL;
  92.                                         VAR (*OUT*) buffer: ARRAY OF CHAR;
  93.                                         fieldsize: CARDINAL);
  94.  
  95.     (* Converts the number to a decimal character string in array       *)
  96.     (* "buffer", right-justified in a field of fieldsize characters.    *)
  97.     (* The format depends on the size of the number relative to the     *)
  98.     (* size of the buffer.                                              *)
  99.  
  100. (************************************************************************)
  101. (*                          SCREEN OUTPUT                               *)
  102. (************************************************************************)
  103.  
  104. PROCEDURE SelectWindow (w: Window);
  105.  
  106.     (* Specifies that all screen output, up until the next call to      *)
  107.     (* SelectWindow, will be to window w.                               *)
  108.  
  109. PROCEDURE WriteString (s: ARRAY OF CHAR);
  110.  
  111.     (* Writes s to the current window. *)
  112.  
  113. PROCEDURE WriteLn;
  114.  
  115.     (* Writes an end-of-line to the current window. *)
  116.  
  117. PROCEDURE PressAnyKey;
  118.  
  119.     (* "Press any key to continue". *)
  120.  
  121. PROCEDURE Error (message: ARRAY OF CHAR);
  122.  
  123.     (* Puts a message to the screen. *)
  124.  
  125. PROCEDURE WriteCard (N: CARDINAL);
  126.  
  127.     (* Writes a cardinal value. *)
  128.  
  129. PROCEDURE WriteRJCard (number, fieldsize: CARDINAL);
  130.  
  131.     (* Like WriteCard, but the result is right justified in a field     *)
  132.     (* of fieldsize characters.                                         *)
  133.  
  134. PROCEDURE WriteReal (x: REAL;  places: CARDINAL);
  135. PROCEDURE WriteLongReal (x: LONGREAL;  places: CARDINAL);
  136.  
  137.     (* Writes x in a field "places" characters wide. *)
  138.  
  139. (************************************************************************)
  140. (*                         KEYBOARD INPUT                               *)
  141. (************************************************************************)
  142.  
  143. PROCEDURE ReadCard (VAR (*OUT*) N: CARDINAL);
  144.  
  145.     (* Reads a cardinal from the keyboard, echoing it to screen. *)
  146.  
  147. PROCEDURE ReadLongReal(): LONGREAL;
  148.  
  149.     (* Reads and converts a numeric string from the keyboard.   *)
  150.  
  151. END MiscM2.
  152.  
  153.