Usenet comp.sys.dec (1990-2013)
 help / color / mirror / Atom feed
From: mehl@iastate.edu (Mark M Mehl)
Subject: Re: C code to convert DEC floating pt to IEEE floating pt
Date: 1 Sep 94 22:52:03 GMT	[thread overview]
Message-ID: <mehl.778459923@biner3.ameslab.gov> (raw)
In-Reply-To: vnie-hj.4.2E642D83@mella.ee.up.ac.za


In <vnie-hj.4.2E642D83@mella.ee.up.ac.za> vnie-hj@mella.ee.up.ac.za (Hennie van Niekerk) writes:
>>We're interested in some C code to convert DEC floating pt (VAX & PDP)
>>to IEEE floating point format (PCes).

Thanks for everyone's solutions.  I've just finished saving them.
BTW, most of the numbers are begin generated on TSX/PDP-11 and then
converted to IEEE on the PC (via C code written for LabView).
(We're converting some of our PDP-11 application code to LabView.)
As a result, the VMS library solution won't work for most of our
cases.  Everything is in single precision float.

>/*------------------------------------------------------------------- * 
>vax2pcFloat() * Convert VAX format float*2 to IEEE format float*2 
>*-------------------------------------------------------------------*/

I'm a little confused by the float*2 terminology above.  It looks
from the code below that everything is in 32-bit (single) float
rather than 64-bit "double float".  I guess I just don't understand
the "float*2" terminology.

|void vax2pcFloat( float *vax ){
|	union	{
|		struct	{
|			unsigned ivalue;
|		} ints;
|		float fvalue;
|	} pcFloat;
|	union	{
|		struct	{
|			unsigned short int1,int2;
|		} ints;
|		unsigned lInt;
|	} slInt;
|	unsigned char sign;
|	short exponent;
|	unsigned mantissa;
|	unsigned short indx;

|	pcFloat.fvalue = *vax;
|	slInt.lInt = pcFloat.ints.ivalue;
|	indx = slInt.ints.int1;
|	slInt.ints.int1 = slInt.ints.int2;
|	slInt.ints.int2 = indx;
|	pcFloat.ints.ivalue = slInt.lInt;
|	sign = pcFloat.ints.ivalue >> 31;
|	exponent = ((pcFloat.ints.ivalue & 0x7F800000uL) >> 23);
|	mantissa = pcFloat.ints.ivalue & 0x7FFFFFuL;
|	if( exponent ) pcFloat.fvalue = 1.; else pcFloat.fvalue = 0.;
|	for( indx=0; indx < 23; indx++ )
|		if( mantissa & ( 1uL << indx ) )
|			pcFloat.fvalue += pow(2., (double)(indx - 23.));
|	pcFloat.fvalue = pcFloat.fvalue * pow(2., (double)(exponent-129.));
|	if( sign ) pcFloat.fvalue = -pcFloat.fvalue;
|	*vax = pcFloat.fvalue;
|}

Thanks again for the help.  --Mark
-- 
 /\ Mark M Mehl, alias Superticker (Supertickler to some)
<><> Internet: mehl@IAstate.edu
 \/ Preferred UUCP: uunet!iastate.edu!mehl
Disclaimer: You got to be kidding; who would want to claim anything I said?


  reply	other threads:[~1994-09-01 22:52 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1994-08-29 22:14 C code to convert DEC floating pt to IEEE floating pt Mark M Mehl
1994-08-30 13:31 ` o\bBob Schaefer
1994-08-30 13:43 ` Bob Koehler
1994-08-31  7:13 ` Hennie van Niekerk
1994-09-01 22:52   ` Mark M Mehl [this message]
1994-09-07 15:46   ` Realtime Data Aquisition Software Joe Stam
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