home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / numana01.zip / DEF / CONVERSI.DEF next >
Text File  |  1996-07-31  |  4KB  |  83 lines

  1. DEFINITION MODULE Conversions;
  2.  
  3.         (********************************************************)
  4.         (*                                                      *)
  5.         (*              Miscellaneous type conversions          *)
  6.         (*                                                      *)
  7.         (*  Programmer:         P. Moylan                       *)
  8.         (*  Last edited:        30 July 1996                    *)
  9.         (*  Status:             Working                         *)
  10.         (*                                                      *)
  11.         (********************************************************)
  12.  
  13. FROM SYSTEM IMPORT (*TYPE*) CARD8;
  14.  
  15. TYPE HexDigit = [0..15];
  16.      EightChar = ARRAY [0..7] OF CHAR;
  17.  
  18. PROCEDURE atoi (a: LONGREAL;  i: CARDINAL): LONGREAL;
  19.  
  20.     (* Calculates a**i.  This procedure does not really belong in this  *)
  21.     (* module, but it appears to be missing from the system-supplied    *)
  22.     (* library modules, and there's no more logical place to put it.    *)
  23.  
  24. PROCEDURE StringToHex (string: ARRAY OF CHAR): CARDINAL;
  25. PROCEDURE StringToCardinal (string: ARRAY OF CHAR): CARDINAL;
  26. PROCEDURE StringToReal (string: ARRAY OF CHAR): REAL;
  27. PROCEDURE StringToLongReal (string: ARRAY OF CHAR): LONGREAL;
  28.  
  29.     (* Converts a text string to numeric.  Leading blanks are ignored.  *)
  30.     (* The conversion stops at the end of the array or at the first     *)
  31.     (* character which cannot be part of the number, and in the         *)
  32.     (* latter case all subsequent characters are ignored.               *)
  33.  
  34. PROCEDURE HexToChar (number: HexDigit): CHAR;
  35.  
  36.     (* Converts a one-digit hexadecimal number to its readable form.    *)
  37.  
  38. PROCEDURE HexByteToString (value: CARD8;
  39.                         VAR (*OUT*) buffer: ARRAY OF CHAR;  pos: CARDINAL);
  40.  
  41.     (* Converts a byte value to 2-character hexadecimal, with the       *)
  42.     (* result stored at buffer[pos] and buffer[pos+1].                  *)
  43.  
  44. PROCEDURE HexToString (value: CARDINAL;  VAR (*OUT*) buffer: ARRAY OF CHAR);
  45.  
  46.     (* Converts 'value' to a string in hexadecimal notation.    *)
  47.  
  48. PROCEDURE ShortCardToString (number: CARD8;
  49.                                         VAR (*OUT*) buffer: ARRAY OF CHAR;
  50.                                         fieldsize: CARDINAL);
  51. PROCEDURE CardinalToString (number: CARDINAL;
  52.                                         VAR (*OUT*) buffer: ARRAY OF CHAR;
  53.                                         fieldsize: CARDINAL);
  54. PROCEDURE RealToString (number: REAL;  VAR (*OUT*) buffer: ARRAY OF CHAR;
  55.                                         fieldsize: CARDINAL);
  56. PROCEDURE LongRealToString (number: LONGREAL;
  57.                                         VAR (*OUT*) buffer: ARRAY OF CHAR;
  58.                                         fieldsize: CARDINAL);
  59.  
  60.     (* Converts the number to a decimal character string in array       *)
  61.     (* "buffer", right-justified in a field of fieldsize characters.    *)
  62.     (* In the case of reals the format depends on the size of the       *)
  63.     (* number relative to the size of the buffer.                       *)
  64.  
  65. PROCEDURE RealToF (number: REAL;  VAR (*INOUT*) fieldsize: CARDINAL;
  66.                         decimalplaces: CARDINAL;  LeftJustified: BOOLEAN;
  67.                         VAR (*OUT*) buffer: ARRAY OF CHAR);
  68. PROCEDURE LongRealToF (number: LONGREAL;  VAR (*INOUT*) fieldsize: CARDINAL;
  69.                         decimalplaces: CARDINAL;  LeftJustified: BOOLEAN;
  70.                         VAR (*OUT*) buffer: ARRAY OF CHAR);
  71.  
  72.     (* Converts the number to an F-format string, of up to fieldsize    *)
  73.     (* characters with decimalplaces digits after the decimal point.    *)
  74.     (* The result is left justified if LeftJustified = TRUE is          *)
  75.     (* specified by the caller, and right justified with space fill     *)
  76.     (* otherwise.  On return fieldsize gives the number of character    *)
  77.     (* positions actually used.  The result string is terminated with   *)
  78.     (* at least one CHR(0) (which is not counted in fieldsize), except  *)
  79.     (* where the result fills the entire buffer.                        *)
  80.  
  81. END Conversions.
  82.  
  83.