From mboxrd@z Thu Jan 1 00:00:00 1970 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 1164f8,eb58654c5683eea0 X-Google-Attributes: gid1164f8,public X-Google-Thread: 10cebf,eb58654c5683eea0 X-Google-Attributes: gid10cebf,public From: john@yrl.co.uk (John Laird) Subject: Re: VAX D-Float format Date: 1997/10/30 Message-ID: #1/1 X-Deja-AN: 286860994 X-NNTP-Posting-Host: mailgate.yrl.co.uk [194.159.108.1] References: <34575f82.182344367@serve.installshield.com> Organization: Yezerski Roper Ltd Newsgroups: comp.sys.dec,comp.sys.dec.micro In article <34575f82.182344367@serve.installshield.com>, chiehcheng@geocities.com (Chieh Cheng) writes: > I am trying to decode and decipher Intergraph Microstation's Design > file format. It uses the VAX D-Float format. Although it is also 64 > bit long, it is somewhat different from the IEEE double float format. > The format is as follows: > > bit 15: sign > bit 14 - 7: Exponent > bit 6 - 0: Exponent > > bit 16 to 63 is the fraction. I assume it is one fraction, however, > the diagram in the book divided it into three equal parts. Like the > exponent shown above. > Actually, it is: Bit 15 : sign Bits 14-7 : exponent Bits 6-0 : most significant bits of fraction Bits 31-16: less significant bits of fraction Bits 47-32: lesser significant bits of fraction Bits 63-48: least significant bits of fraction The least significant fraction bit is bit 48, and the most significant bit is bit 6. The layout is apparently illogical in that layed out in ascending memory order, the fraction bits are not contiguous. I think it goes back to PDP-11 days when the two 16-bit words would have been loaded into the FPU separately. (If you swap the 16-bit words around, it all looks much better). You don't say whether you are running on a big-endian or little-endian machine. It is vital that you know this in order to understand how to translate from this (VAX) binary D_floating format to your binary IEEE format. Assuming you are on a big-endian machine, take each 8 bytes and rearrange them into a byte array in the following order: 2 1 4 3 6 5 8 7. The bits will now look like this: 6 3 0 SEEEEEEEEFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF ^^ ^ || - fraction bits, most significant at bit 54 | --------- exponent bits, most significant at bit 62 ---------- sign bit Compare this with your IEEE format, and you should be able to work out how to shift bits about. (If you are using a little-endian machine, most likely Intel, order the bytes 7 8 5 6 3 4 1 2) There are two other very important points: a) The fraction is _normalised_, which is to say it has been represented as a fraction between 0.5 (inclusive) and 1.0 (exclusive), and the most significant fraction bit (now always 1) is _not stored_. In other words, there is a hidden bit between bits 6 and 7 in the D_float format which is _always_ 1, and which is to be considered as part of the fraction. I don't know off-hand whether IEEE uses normalised fractions with a hidden bit or not. b) The exponent is in excess 128 format, meaning that an actual value of N is stored as N+128. Thus the exponent is always apparently positive in the range 0 to 255, and 128 should be subtracted to give the true value in the range -128 to 127. A stored exponent of 0 means one of two things - if the sign bit is 0, the whole number is zero regardless of the fraction bits, while if the sign bit is 1, the whole number is a reserved operand or NaN in some dialects. -- John Laird (john@yrl.co.uk) "I have discovered a truly elegant sig, Yezerski Roper Ltd sadly there is no room here to show it." http://www.yrl.co.uk