comp.lang.idl-pvwave archive
Messages from Usenet group comp.lang.idl-pvwave, compiled by Paulo Penteado

Home » Public Forums » archive » Re: Routine for converting 80x87 doubles to XDR (IEEE) format?
Show: Today's Messages :: Show Polls :: Message Navigator
E-mail to friend 
Switch to threaded view of this topic Create a new topic Submit Reply
Re: Routine for converting 80x87 doubles to XDR (IEEE) format? [message #1169] Wed, 07 July 1993 12:53
ryba is currently offline  ryba
Messages: 33
Registered: October 1992
Member
In article <1993Jul6.212653.13279@ll.mit.edu>, 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.

Thanks to Bill Thompson and some other reading, here's the result:

pro dblswap,arr
; Procedure to byte-swap 8-byte reals

sa = size(arr)
atype = sa(sa(0)+1)
if atype ne 5 then message,'Only for double precision numbers!'
npts = sa(sa(0)+2)
temp = byte(arr,0,8,npts) ; Convert to bytes
temp = rotate(temporary(temp),5) ; Matrix rotation
arr(0) = double(temp,0,npts) ; Convert back to double

return
end

--
Dr. Marty Ryba | Generation X:
MIT Lincoln Laboratory | Too young to be cynical,
ryba@ll.mit.edu | too old to be optimistic.
Of course nothing I say here is official policy!!!!
Re: Routine for converting 80x87 doubles to XDR (IEEE) format? [message #1171 is a reply to message #1169] Wed, 07 July 1993 07:33 Go to previous message
thompson is currently offline  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
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: Header,Footer,Etc...
Next Topic: PCX Reader for IDL

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ] [ PDF ]

Current Time: Fri Oct 10 14:02:23 PDT 2025

Total time taken to generate the page: 1.11368 seconds