home *** CD-ROM | disk | FTP | other *** search
/ Programmer 7500 / MAX_PROGRAMMERS.iso / PASCAL / BFLOAT.ZIP / BFLOAT.DOC next >
Encoding:
Text File  |  1989-05-14  |  3.2 KB  |  87 lines

  1. {$A-,B-,D-,E+,F-,I-,L-,N+,O-,R-,S-,V-}
  2. unit BFLOAT;
  3. (*
  4.             MicroSoft Binary Float to IEEE format Conversion
  5.                     Copyright (c) 1989 J.P. Ritchey
  6.                             Version 1.0
  7.  
  8.          This software is released to the public domain.  Though
  9.          tested, there could be some errors.  Any reports of bugs
  10.          discovered would be appreciated. Send reports to
  11.                  Pat Ritchey     Compuserve ID 72537,2420
  12. *)
  13. interface
  14.  
  15. type
  16.   bfloat4 = record
  17.     { M'Soft single precision }
  18.     mantissa : array[5..7] of byte;
  19.     exponent : byte;
  20.     end;
  21.  
  22.   Bfloat8 = record
  23.     { M'Soft double precision }
  24.     mantissa : array[1..7] of byte;
  25.     exponent : byte;
  26.     end;
  27.  
  28.  
  29. Function Bfloat4toExtended(d : bfloat4) : extended;
  30. Function Bfloat8toExtended(d : Bfloat8): extended;
  31.  
  32. { These routines will convert a MicroSoft Binary Floating point
  33.   number to IEEE extended format.  The extended is large enough
  34.   to store any M'Soft single or double number, so no over/underflow
  35.   problems are encountered.  The Mantissa of an extended is large enough
  36.   to hold a BFloatx mantissa, so no truncation is required.
  37.  
  38.   The result can be returned to TP single and double variables and
  39.   TP will handle the conversion.  Note that Over/Underflow can occur
  40.   with these types. }
  41.  
  42. Function HexExt(ep:extended) : string;
  43.  
  44. { A routine to return the hex representation of an IEEE extended variable
  45.   Left in from debugging, you may find it useful }
  46.  
  47. Function ExtendedtoBfloat4(ep : extended; var b : bfloat4) : boolean;
  48. Function ExtendedtoBfloat8(ep : extended; var b : Bfloat8) : boolean;
  49.  
  50. { These routines are the reverse of the above, that is they convert
  51.   TP extended => M'Soft format.  You can use TP singles and doubles
  52.   as the first parameter and TP will do the conversion to extended
  53.   for you.
  54.  
  55.   The Function result returns True if the conversion was succesful,
  56.   and False if not (because of overflow).
  57.  
  58.   Since an extended can have an exponent that will not fit
  59.   in the M'Soft format Over/Underflow is handled in the following
  60.   manner:
  61.     Overflow:  Set the Bfloatx to 0 and return a False result.
  62.     Underflow: Set the BFloatx to 0 and return a True Result.
  63.  
  64.   No rounding is done on the mantissa.  It is simply truncated to
  65.   fit. }
  66.  
  67.  
  68. Function BFloat4toReal(b:bfloat4) : Real;
  69. Function BFloat8toReal(b:bfloat8) : Real;
  70.  
  71. { These routines will convert a MicroSoft Binary Floating point
  72.   number to Turbo real format.  The real is large enough
  73.   to store any M'Soft single or double Exponent, so no over/underflow
  74.   problems are encountered.  The Mantissa of an real is large enough
  75.   to hold a BFloat4 mantissa, so no truncation is required.  The
  76.   BFloat8 mantissa is truncated (from 7 bytes to 5 bytes) }
  77.  
  78. Function RealtoBFloat4(rp: real; var b:bfloat4) : Boolean;
  79. Function RealtoBFloat8(rp : real; var b:bfloat8) : Boolean;
  80.  
  81. { These routines do the reverse of the above.  No Over/Underflow can
  82.   occur, but truncation of the mantissa can occur
  83.   when converting Real to Bfloat4 (5 bytes to 3 bytes).
  84.  
  85.   The function always returns True, and is structured this way to
  86.   function similar to the IEEE formats }
  87.