From mboxrd@z Thu Jan 1 00:00:00 1970 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 1164f8,c164973412164e0 X-Google-Attributes: gid1164f8,public From: fairfield@sldb6.slac.stanford.edu Subject: Re: VAX double-precision format Date: 1995/07/03 Message-ID: <1995Jul2.205817.1@sldb6.slac.stanford.edu>#1/1 X-Deja-AN: 105520527 sender: news@unixhub.SLAC.Stanford.EDU references: <3t15tm$43t@westie.mid.net> <3t76s0$7mc@camelot.ccs.neu.edu> organization: Stanford Linear Accelerator Center newsgroups: comp.sys.dec In article <3t76s0$7mc@camelot.ccs.neu.edu>, gbcacm@ccs.neu.edu (Peter Sherwood) writes: > Mike Unverferth (mju@tnt) wrote: > : I have some data files containing values in VAX double-precision. > : I need to convert these values to Intel (IEEE) floating-point. > : Can someone provide the format and/or C code to do the conversion? > > The format (D_floating"), is on page 35 of the VAX Architecture Handbook, > and also available in other publications that describe the VAX instruction > set, possibly even in on-line HELP MACRO. The 64-bit data is stored in 4 > 16-bit words as > > sign | 8-bit excess-128 2's exponent | 7-bit ms fraction with 'hidden' bit > 16-bit ms-1 fraction > 16-bit ms-2 fraction > 16-bit ls fraction It should be noted that, in addition to the exponent having a bias of 128, the VAX _normalization_ of the fraction (mantissa) is such that 0.5 <= fraction < 1.0. IEEE is different. _Single_ precision IEEE has a bias of 127 and the normalixation is 1.0 <= frac < 2.0. The difference in normalization means that once the VAX exponent has been extracted to a _signed_ value, it needs to be reduced by 1 before applying the IEEE bias. I assume Mike would want to convert his VAX doubles to IEEE double precision, in which case he needs to know that the IEEE Double exponent field is 11 bits wide (cf. 8 bits for VAX F_float and D_float, and IEEE Single), that the exponent bias is 1023, and the normalization of the fraction is the same as for IEEE Single, 1.0 <= frac < 2.0. In all cases, the most significant binary "digit" of the fraction is omitted, but need not be considered in the conversion. Note that there is a 3-bit loss of precision in converting from D_float to IEEE Double due to the difference in exponent and fraction widths. The IEEE formats are: 1 8 23 width +---+-------------+------------------------+ | s | exp | fraction | Single +---+-------------+------------------------+ ______ msb lsb msb lsb order 1 11 52 width +---+---------------+-----------------------------+ | s | exp | fraction | Double +---+---------------+-----------------------------+ ------ msb lsb msb lsb order On little-endian architectures (VAX, Alpha, Intel), the least significant bit is bit 0, the most significant bit is bit 31 (for a 32-bit word size), and thus the sign bit is bit 31. On VAX hardware, the least significant 32 bits of a 64 bit double _follow_ at the next address. That is, if you think of the double as being a dimension 2 array of 32 bit words, the 2nd array index holds the least significant bits of the fraction. I would _guess_ that Intel architecture does the same, but I have no way to verify that... Finally, is those VAX double precision data happened to be VAX G_float format, then a different conversion will need to be applied. -Ken -- Kenneth H. Fairfield | Internet: Fairfield@Slac.Stanford.Edu SLAC, P.O.Box 4349, MS 46 | DECnet: 45537::FAIRFIELD (45537=SLACVX) Stanford, CA 94309 | Voice: 415-926-2924 FAX: 415-926-3515 ------------------------------------------------------------------------- These opinions are mine, not SLAC's, Stanford's, nor the DOE's...