From: vnie-hj@mella.ee.up.ac.za (Hennie van Niekerk)
Subject: Re: C code to convert DEC floating pt to IEEE floating pt
Date: Wed, 31 Aug 1994 07:13:07 GMT [thread overview]
Message-ID: <vnie-hj.4.2E642D83@mella.ee.up.ac.za> (raw)
In-Reply-To: mehl.778198445@biner3.ameslab.gov
>We're interested in some C code to convert DEC floating pt (VAX & PDP)
>to IEEE floating point format (PCes).
>I would rather not convert these solutions to C if someone has
>already done so. :-) Please direct me to some C sources.
Here's some code I use to convert floats generated on a PDP 11/23 to IEEE
format.
This was written for a 32 bit compiler on the PC. There is a problem with
passing the argument as *float. It seems to me that sometimes the compiler's
run-time checking causes problems (NaN's etc.) Rather change the routine to
something like float vax2pcfloat( unsigned *vax ) . I have done this
somewhere, but can't find the code at this moment.
/*------------------------------------------------------------------- *
vax2pcFloat() * Convert VAX format float*2 to IEEE format float*2
*-------------------------------------------------------------------*/
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;
}
/*-------------------------------------------------------------------
Hope this helps
Hennie
next prev parent reply other threads:[~1994-08-31 7:13 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 [this message]
1994-09-01 22:52 ` Mark M Mehl
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