www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1998/04/05/06:16:39

From: "Ingo Ruhnke" <grumbel AT gmx DOT de>
Newsgroups: comp.os.msdos.djgpp
Subject: Re: Converting pascal 6-byte reals to C 8-byte doubles
Date: Sun, 5 Apr 1998 00:19:50 +0200
Organization: Telemedia News Server
Lines: 59
Message-ID: <3527590a.0@news1.cityweb.de>
References: <1998040312181401 DOT HAA20698 AT ladder03 DOT news DOT aol DOT com>
NNTP-Posting-Host: demdwu36.bertelsmann.de
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp

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 -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019