Re: Routine for converting 80x87 doubles to XDR (IEEE) format? [message #1171 is a reply to message #1169] |
Wed, 07 July 1993 07:33  |
thompson
Messages: 584 Registered: August 1991
|
Senior Member |
|
|
ryba@ll.mit.edu (Marty Ryba) writes:
> I'd like to read in some data dumped from a PC that includes some
> 8-byte reals. BYTEORDER only does byte swaps for shorts (2 bytes) and
> longs (4 bytes). If I recall, the 80x87 uses IEEE format, but with the
> "little endian" format of the Intel chip. Is that correct? If so, I just
> need an extended byte-order to do an 8-byte swap. If not, a canned routine
> to do the conversion would be nice.
You are correct about how Intel 80x87 chips store floating point numbers. If
you're doing the conversion between Intel and IEEE formats on the PC itself,
then all you have to do is to use
BYTEORDER,DATA,/XDRTOD ;IEEE --> Host
BYTEORDER,DATA,/DTOXDR ;Host --> IEEE
There are also /FTOXDR and /XDRTOF keywords for single precision floating point
numbers. These work for any platform that IDL runs on (except for a bug in
some versions of IDL when converting double precision numbers on MIPS platforms
that is discussed in the release notes.)
If you want to do the conversion on some platform other than the PC, say a Sun
workstation which uses the IEEE format, then try this:
N_DATA = N_ELEMENTS(DATA) ;DATA is double precision (REAL*8)
TEMP = LONG(DATA,0,2,N_DATA) ;Convert to longwords
BYTEORDER,TEMP,/LSWAP ;Swap bytes
TEMP = REVERSE(TEMP,1) ;Swap longwords
DATA(0) = DOUBLE(TEMP,0,N_DATA) ;Convert back to double precision.
This should reverse the order of all eight bytes.
Bill Thompson
|
|
|