From mboxrd@z Thu Jan 1 00:00:00 1970 Message-ID: <96079034715602.tru64-unix-managers.marc@archive.invalid> From: Neil Higson Date: Fri, 15 Jan 1999 10:35:33 +0000 To: tru64-unix-managers Subject: Summary: Conversion of VMS floating point format to IEEE floatingpoint X-MARC-Message: https://marc.info/?l=tru64-unix-managers&m=96079034715602 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 typedef unsigned char u_char; #include #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."