C code to convert DEC floating pt to IEEE floating pt

C code to convert DEC floating pt to IEEE floating pt

Post by Mark M Me » Wed, 31 Aug 1994 07:14:05



We're interested in some C code to convert DEC floating pt (VAX & PDP)
to IEEE floating point format (PCes).

I've ran across a solution in Ada on the DECUS (FLOTFLOT.ADA;1)
for doing this.  I also ran across a partial solution in Fortran
([DECUS]AAAREADME.92A_VAX;2) for doing some of this.  I also know
about the 1991 VAX Professional article.

I would rather not convert these solutions to C if someone has
already done so.  :-)  Please direct me to some C sources.

I've looked on gatekeeper.dec.com for some of this code, but I've
been unable to figure out which files--if any--would have this.

Thanks for your help.
--
 /\ Mark M Mehl, alias Superticker (Supertickler to some)

 \/ Preferred UUCP: uunet!iastate.edu!mehl
Disclaimer: You got to be kidding; who would want to claim anything I said?

 
 
 

C code to convert DEC floating pt to IEEE floating pt

Post by Bob Koehl » Wed, 31 Aug 1994 22:43:00



Quote:

>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.

Does it really have to be source?  VMS has this capability built in.  Look at
CVT$CONVERT_FLOAT in the back of the LIB$ manual, you can call this from any
language.

------------------------------------------------------------------------------
Bob Koehler                     |


 
 
 

C code to convert DEC floating pt to IEEE floating pt

Post by o Bob Schaef » Wed, 31 Aug 1994 22:31:14




Quote:

>We're interested in some C code to convert DEC floating pt (VAX & PDP)
>to IEEE floating point format (PCes).

Mark,
  I believe the following two routines are what you are looking for.  They
go from IEEE to VAX and VAX to IEEE.

ieeetodec(float *ieee_val, float *dec_val))
{
        register unsigned long dec_result;
        register unsigned long ieee;

        ieee = *((unsigned long *)ieee_val);
        dec_result = (ieee >> 16) | (ieee << 16);
        dec_result += 0x00000100;

        *((unsigned long *)dec_val) = dec_result;

Quote:}

dectoieee(float *dec_val, float *ieee_val)
{
        register unsigned long dec;
        register unsigned long ieee_result;

        dec = *((unsigned long *) dec_val);
        ieee_result = (dec >> 16) | (dec << 16);
        ieee_result -= 0x01000000;

        *((unsigned long *)ieee_val) = ieee_result;

Quote:}

hope this helped you out.  I'm not sure if this will get you right to a PC
or not, its from a document about a Motorola controller.

Bob Schaefer

--
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
Launchpad is an experimental internet BBS. The views of its users do not
necessarily represent those of UNC-Chapel Hill, OIT, or the SysOps.
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --

 
 
 

C code to convert DEC floating pt to IEEE floating pt

Post by Hennie van Nieke » Thu, 01 Sep 1994 16:13:07


Quote:>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;

Quote:}

/*-------------------------------------------------------------------

Hope this helps
Hennie

 
 
 

C code to convert DEC floating pt to IEEE floating pt

Post by Mark M Me » Sat, 03 Sep 1994 07:52:03



Quote:>>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.

Quote:>/*------------------------------------------------------------------- *
>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)

 \/ Preferred UUCP: uunet!iastate.edu!mehl
Disclaimer: You got to be kidding; who would want to claim anything I said?

 
 
 

C code to convert DEC floating pt to IEEE floating pt

Post by Joe St » Fri, 09 Sep 1994 00:46:52


I am looking for a software package that will allow me to use a realtime vax, in conjuntion with a entire cluster, as a data aquisiton device.  We currently have all the hardware necessary and can write simple programs to store data aquired by a data aquisition board.  I am looking for a software package that will do this for several channels and display the data graphically, like a digitial oscilliscope.  Several packages exist for PC's to do this and we are using them now.  As our needs increase, however

, we would really like to use our VAX's.  If anyone is familiar with anything that can help me please let me know.

Thanks,

 
 
 

1. IEEE<->DEC floating pt conversion wanted.

        If you have a DECstation or DECsystem there are a
        set of functions in the standard library for doing
        this conversion.  There isn't any documentation that
        I know of though.

        Some of the functions of interest are:

                dtoi - D Float to IEEE
                ftoi - F Float to IEEE
                itod - IEEE to D Float
                itof - IEEE to F Float

        There may also be a set for the G-Float format.  From little
        I've been able to divine they take a point pointer to the
        number and convert it in place.  If it fails it restores
        the original number and returns -1.

        They're in the library, but without documentation or even
        a man page are hard to track down.

        I don't know whether or not these functions are supported.
        Check with the CSC if you have a support contract to see
        what they can find out.
--

2. While loop/ifstream problem

3. conversion algorithm, floating pt formats

4. FP Extensions

5. DEC Unix 4.0 IEEE floating point on Alpha

6. ReInstall After Changing Computer Name and Domain

7. Need routine to convert floating-point from Sun SPARC to DEC MIPS

8. We can get the title of the window by calling win32 API GetWindowText in user mode,but what to do in kernel mode?

9. IEEE Standard for Floating Point

10. HELP ! IEEE functions on floats

11. IEEE floating-point question

12. IEEE floating point conversion needed

13. Vax <-> IEEE Floating Point Conversions?