From mboxrd@z Thu Jan 1 00:00:00 1970 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 10239c,895b65025d75f836 X-Google-Attributes: gid10239c,public X-Google-Thread: 1164f8,895b65025d75f836 X-Google-Attributes: gid1164f8,public X-Google-ArrivalTime: 1994-09-01 17:34:26 PST Path: bga.com!news.sprintlink.net!hookup!yeshua.marcam.com!MathWorks.Com!europa.eng.gtefsd.com!howland.reston.ans.net!vixen.cso.uiuc.edu!newsrelay.iastate.edu!news.iastate.edu!biner3.ameslab.gov!mehl From: mehl@iastate.edu (Mark M Mehl) Newsgroups: comp.sys.dec,vmsnet.sources.d Subject: Re: C code to convert DEC floating pt to IEEE floating pt Date: 1 Sep 94 22:52:03 GMT Organization: Ames Laboratory -- IOWA STATE UNIV Message-ID: References: NNTP-Posting-Host: biner3.ameslab.gov Keywords: DEC, floating-point, IEEE, format Xref: bga.com comp.sys.dec:5605 vmsnet.sources.d:530 In 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?