From: Steve Atkins <steve@blighty.com>
Subject: Re: VAX D-Float format
Date: 1997/10/30 [thread overview]
Message-ID: <3458B45F.167E@blighty.com> (raw)
In-Reply-To: 34575f82.182344367@serve.installshield.com
Chieh Cheng wrote:
>
> 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.
>
> Can someone help me with this format? How can I convert this binary
> data to a double float?
Ugly, ugly, ugly untested code. This should all be done
with structures. This is a really good example as to how
not to write bit twiddling code.
--------------
uint16 *A; // pointer to float_d
uint64 frac; // fraction
uint64 s; // sign
uint64 exp; // exponent
uint64 tfloat; // IEEE double format number
double result;
s = (*A) >> 15;
exp = ((*A) >> 7) & 0xff;
frac = ((*A++) & 0x7f) << 16;
frac = (frac | (*A++)) << 16;
frac = (frac | (*A++)) << 16;
frac |= (*A++);
tfloat = s << 63;
// exp is excess128 for d_floats and excess1023 for t_floats
tfloat |= (exp + 1023 - 128) << 48;
// You lose three bits of precision
tfloat |= frac >> 3;
result = *(double*)(&tfloat);
--------------
Use at your own risk.
--
-- Steve Atkins -- steve@blighty.com
-- 'Play that funky music....'
next prev parent reply other threads:[~1997-10-30 5:00 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
1997-10-29 5:00 VAX D-Float format Chieh Cheng
1997-10-30 5:00 ` Steve Atkins [this message]
1997-10-31 5:00 ` Pedasmith
1997-10-30 5:00 ` Hoff Hoffman
1997-10-30 5:00 ` Steve Lionel
1997-10-31 5:00 ` Dik T. Winter
1997-10-31 5:00 ` John Wilson
1997-11-03 5:00 ` Dik T. Winter
1997-11-03 5:00 ` Chieh Cheng
1997-11-05 5:00 ` Steve Lionel
1997-11-06 5:00 ` Philippe Pouliquen
1997-11-10 5:00 ` John Laird
1997-10-30 5:00 ` Gregg E Economou
1997-10-31 5:00 ` Chieh Cheng
1997-11-05 5:00 ` WTB: Iomega Zip Drive Jerome Fine
[not found] ` <199711051454.JAA02820@dbit.dbit.com>
1997-11-05 5:00 ` Jerome Fine
1997-10-30 5:00 ` VAX D-Float format John Laird
1997-11-05 5:00 ` John Foust
read-only archive
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox