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 02:33:50 PST Path: bga.com!news.sprintlink.net!hookup!news.kei.com!MathWorks.Com!europa.eng.gtefsd.com!howland.reston.ans.net!quagga.ru.ac.za!inet.up.ac.za!mella.ee.up.ac.za!vnie-hj From: vnie-hj@mella.ee.up.ac.za (Hennie van Niekerk) Newsgroups: comp.sys.dec,vmsnet.sources.d Subject: Re: C code to convert DEC floating pt to IEEE floating pt Date: Wed, 31 Aug 1994 07:13:07 GMT Organization: Faculty of Engineering, University of Pretoria Message-ID: References: NNTP-Posting-Host: 137.215.170.26 Keywords: DEC, floating-point, IEEE, format X-Newsreader: Trumpet for Windows [Version 1.0 Rev A] Xref: bga.com comp.sys.dec:5589 vmsnet.sources.d:529 >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