From:	CSBVAX::MRGATE!info-vax-RELAY@KL.SRI.COM@SMTP 27-JUL-1988 23:33
To:	ARISIA::EVERHART
Subj:	Re: difference between vax floating point representation and IEEE


Received: from ucbvax.berkeley.edu by KL.SRI.COM with TCP; Thu, 21 Jul 88 20:37:37 PDT
Received: by ucbvax.berkeley.edu (5.59/1.28)
	id AA24656; Thu, 21 Jul 88 16:46:53 PDT
Received: from USENET by ucbvax.Berkeley.EDU with netnews
	for info-vax@kl.sri.com (info-vax@kl.sri.com)
	(contact usenet@ucbvax.Berkeley.EDU if you have questions)
Date: 21 Jul 88 22:08:44 GMT
From: woods@handies.ucar.edu  (Greg Woods)
Organization: Scientific Computing Division/NCAR, Boulder CO
Subject: Re: difference between vax floating point representation and IEEE
Message-Id: <462@ncar.ucar.edu>
References: <2256@hubcap.UUCP>
Sender: info-vax-request@kl.sri.com
To: info-vax@kl.sri.com

In article <2256@hubcap.UUCP> ghosh@hubcap.UUCP (Amitava Ghosh) writes:
>does anyone know what the difference is between the IEEE floating
>point representation and the way the VAX stores numbers. If so
>how does one convert from one format to the other.  

  Here's some C subroutines to convert back and forth between VAX and
IEEE format. I use them to convert binary files between VAXes and Suns
and it works fairly well. They all take a pointer to the data and
how many data elements to convert as arguments.

--Greg
-------------------------------------------------------------------------
union  ie3float { char c[4]; int  exp; float f; };
void vf2ie3f(u,n) register union ie3float *u; register int n; {
/* VAX float to IEEE float */
register char tmp;
register int i;
for (i=0; i < n; u++,i++) {
   if (! u->exp) continue;
   tmp=u->c[0]; u->c[0]=u->c[1]-1; u->c[1]=tmp;
   tmp=u->c[2]; u->c[2]=u->c[3];   u->c[3]=tmp;
}
}

void ie3f2vf(u,n) register union ie3float *u; register int n; {
/* IEEE float to VAX float */
register char tmp;
register int i;
for (i=0; i < n; u++,i++) {
   if (! u->exp) continue;
   tmp=u->c[0]+1; u->c[0]=u->c[1]; u->c[1]=tmp;
   tmp=u->c[2]; u->c[2]=u->c[3];   u->c[3]=tmp;
}
}

void i4conv(u,n) union ie3float *u; register int n; {
/* 4-byte integers; self-inverting operation so only one routine needed
   to go both ways */
register char tmp; register int i;
for (i=0; i < n; u++,i++) {
   tmp=u->c[0]; u->c[0]=u->c[3]; u->c[3]=tmp;
   tmp=u->c[1]; u->c[1]=u->c[2]; u->c[2]=tmp;
}
}

void i2conv(u,n) register union ie3float *u; int n; {
   swab(u,2*n); /* included for the hell of it */
}
