Mail Archives: djgpp/1998/04/05/06:16:39
Fist1000 wrotes:
>A friend of mine has written a program in TP7 and in it he uses a bunch of
>reals and writes them to disk. I'm helping him port his code to C (Watcom
C),
>but I'm at a loss as to how I read in this data from a C program. For
example,
>I wrote this test in Pascal:
>[...]
>Yet when I run the C prog, I get an output of 0.000000. Does anyone know
how to
>do this?
Here's some source I found in a german newsgroup:
>----------------------------------------------------<
void TP_Real2double(unsigned short real[3], double *d)
/* converts TP REAL to IEEE double assuming
16 bit unsigned short
*/
{
unsigned short *dd = (unsigned short *)d;
if ((real[0]&0xff)==0)
dd[0]=dd[1]=dd[2]=dd[3]=0;
else {
dd[3] = (real[2]&0x8000) | /* sign */
(((real[0]&0xff)+0x37e)<<4) | /* exponent */
((real[2]&0x7fff)>>11); /* mant 35..38 */
dd[2] = (real[1]>>11)+(real[2]<<5); /* mant 19..34 */
dd[1] = (real[0]>>11)+(real[1]<<5); /* mant 03..18 */
dd[0] = (real[0]&0xff00)<<5; /* mant 00..02 */
}
}
#include <stdio.h>
double d0,d1,d2,d3;
unsigned short TP_pi[3] = { 0x2182,0xdaa2,0x490f },
TP_2pi[3] = { 0x2183,0xdaa2,0x490f },
TP_pi2[3] = { 0x2181,0xdaa2,0x490f },
TP_mpi[3] = { 0x2182,0xdaa2,0xc90f };
main()
{
TP_Real2double(TP_pi,&d0);
TP_Real2double(TP_2pi,&d1);
TP_Real2double(TP_pi2,&d2);
TP_Real2double(TP_mpi,&d3);
printf("%15.10f%15.10f%15.10f%15.10f\n",d0,d1,d2,d3);
return 0;
}
>----------------------------------------------------<
Hope it helps
Ingo
--
http://privat.schlund.de/grumbel/
- Raw text -