tru64-unix-managers (formerly alpha-osf-managers) (1994-2012)
 help / color / mirror / Atom feed
* Summary: Conversion of VMS floating point format to IEEE floatingpoint
@ 1999-01-15 10:35 Neil Higson
  0 siblings, 0 replies; only message in thread
From: Neil Higson @ 1999-01-15 10:35 UTC (permalink / raw)
  To: tru64-unix-managers

Thanks to all who responded to this request for help.
The soultion that suited my application best came from
Tom Leitner and is enclosed: Many Thanks Tom.

Thanks also to:
Dr Tom Blinn
Eugene Chu
Roddy McColl
Lucio Chiappetti

Original message:

Does anyone have a 'C' routine to convert floating point data stored as =
a binary file from a VMS machine to the IEEE format recognised by gcc on =
DEC Unix that they could let me have.


These routines successfully converted the floats generated on VMS to the =
IEEE unix format.


#include <stdio.h>
typedef unsigned char u_char;
#include <math.h>
#endif

/* =
------------------------------------------------------------------------ =
*/
/*                         local constants and variables                 =
   */
/* =
------------------------------------------------------------------------ =
*/

/* IEEE single precision floating point */

struct    ieee_single {
    unsigned int    mantissa: 23;
    unsigned int    exp     : 8;
    unsigned int    sign    : 1;
};

/* VAX single precision floating point */

struct    vax_single {
    unsigned int    mantissa1 : 7;
    unsigned int    exp       : 8;
    unsigned int    sign      : 1;
    unsigned int    mantissa2 : 16;
};

#define VAX_SNG_BIAS     0x81
#define IEEE_SNG_BIAS    0x7f

static struct sgl_limits {
    struct vax_single s;
    struct ieee_single ieee;
} sgl_limits[2] =3D {
    {{ 0x7f, 0xff, 0x0, 0xffff },    /* Max Vax */
    { 0x0, 0xff, 0x0 }},        /* Max IEEE */
    {{ 0x0, 0x0, 0x0, 0x0 },    /* Min Vax */
    { 0x0, 0x0, 0x0 }}        /* Min IEEE */
};
#endif

/*#----------------------------------------------------------------------=
--#*/

u_char *vax_to_ieee(float *f)
/*
    Description:=20
        Converts a float from VAX to (IEEE) format

    Parameters:
    *fp:          pointer to the float to be converted
    return value: converted float
*/
{
    struct ieee_single is;
    struct vax_single vs;
    struct sgl_limits *lim;
    int i;

    vs =3D *((struct vax_single *) f);
    for (i =3D 0, lim =3D sgl_limits;
            i < sizeof(sgl_limits) / sizeof(struct sgl_limits); i++, =
lim++) {
        if ((vs.mantissa2 =3D=3D lim->s.mantissa2) &&
            (vs.exp =3D=3D lim->s.exp) &&
            (vs.mantissa1 =3D=3D lim->s.mantissa1)) {
            is =3D lim->ieee;
            goto shipit;
        }
    }
    is.exp =3D vs.exp - VAX_SNG_BIAS + IEEE_SNG_BIAS;
    is.mantissa =3D (vs.mantissa1 << 16) | vs.mantissa2;
shipit:
    is.sign =3D vs.sign;
    memcpy((void*) f, &is, sizeof(float));
    return (u_char*) f;
    return (u_char*) f;
}

/* End of File */
--=20
-------------------------------------------------------------------------=
-



*****************************
Dr Neil Higson
WX1 System Manager
Weapon Systems
Room 1009 A2 Building
DERA Farnborough
Tel: 01252 396977
Fax: 01252 394720
*****************************

"The Information contained in this e-mail and any=20
subsequent correspondence is private and is intended
solely for the intended recipient(s).  For those
other than the intended recipient any disclosure,
copying, distribution, or any action taken or=20
omitted to be taken in reliance on such information
is prohibited and may be unlawful."

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~1999-01-15 10:35 UTC | newest]

Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
1999-01-15 10:35 Summary: Conversion of VMS floating point format to IEEE floatingpoint Neil Higson

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox