home *** CD-ROM | disk | FTP | other *** search
- {$A-,B-,D-,E+,F-,I-,L-,N+,O-,R-,S-,V-}
- unit BFLOAT;
- (*
- MicroSoft Binary Float to IEEE format Conversion
- Copyright (c) 1989 J.P. Ritchey
- Version 1.0
-
- This software is released to the public domain. Though
- tested, there could be some errors. Any reports of bugs
- discovered would be appreciated. Send reports to
- Pat Ritchey Compuserve ID 72537,2420
- *)
- interface
-
- type
- bfloat4 = record
- { M'Soft single precision }
- mantissa : array[5..7] of byte;
- exponent : byte;
- end;
-
- Bfloat8 = record
- { M'Soft double precision }
- mantissa : array[1..7] of byte;
- exponent : byte;
- end;
-
-
- Function Bfloat4toExtended(d : bfloat4) : extended;
- Function Bfloat8toExtended(d : Bfloat8): extended;
-
- { These routines will convert a MicroSoft Binary Floating point
- number to IEEE extended format. The extended is large enough
- to store any M'Soft single or double number, so no over/underflow
- problems are encountered. The Mantissa of an extended is large enough
- to hold a BFloatx mantissa, so no truncation is required.
-
- The result can be returned to TP single and double variables and
- TP will handle the conversion. Note that Over/Underflow can occur
- with these types. }
-
- Function HexExt(ep:extended) : string;
-
- { A routine to return the hex representation of an IEEE extended variable
- Left in from debugging, you may find it useful }
-
- Function ExtendedtoBfloat4(ep : extended; var b : bfloat4) : boolean;
- Function ExtendedtoBfloat8(ep : extended; var b : Bfloat8) : boolean;
-
- { These routines are the reverse of the above, that is they convert
- TP extended => M'Soft format. You can use TP singles and doubles
- as the first parameter and TP will do the conversion to extended
- for you.
-
- The Function result returns True if the conversion was succesful,
- and False if not (because of overflow).
-
- Since an extended can have an exponent that will not fit
- in the M'Soft format Over/Underflow is handled in the following
- manner:
- Overflow: Set the Bfloatx to 0 and return a False result.
- Underflow: Set the BFloatx to 0 and return a True Result.
-
- No rounding is done on the mantissa. It is simply truncated to
- fit. }
-
-
- Function BFloat4toReal(b:bfloat4) : Real;
- Function BFloat8toReal(b:bfloat8) : Real;
-
- { These routines will convert a MicroSoft Binary Floating point
- number to Turbo real format. The real is large enough
- to store any M'Soft single or double Exponent, so no over/underflow
- problems are encountered. The Mantissa of an real is large enough
- to hold a BFloat4 mantissa, so no truncation is required. The
- BFloat8 mantissa is truncated (from 7 bytes to 5 bytes) }
-
- Function RealtoBFloat4(rp: real; var b:bfloat4) : Boolean;
- Function RealtoBFloat8(rp : real; var b:bfloat8) : Boolean;
-
- { These routines do the reverse of the above. No Over/Underflow can
- occur, but truncation of the mantissa can occur
- when converting Real to Bfloat4 (5 bytes to 3 bytes).
-
- The function always returns True, and is structured this way to
- function similar to the IEEE formats }