Board index » delphi » REAL (borland pascal 7) -> FLOAT or DOUBLE

REAL (borland pascal 7) -> FLOAT or DOUBLE

I need to know if anyone out there has ever had to deal with converting
a 6 byte binary real (used in fixed-length binary record file) to either
a 4-byte float or 8-byte double.

I've found the format of the REAL type:
Sign - Fraction - Exponent
1 bit - 39 bits   - 8 bits

I thought I could pad with leading or trailing zeros to come up with the
double format, but haven't had any luck yet.

The real problem is that I'm writing Perl code to generate the binary
file that Pascal code will later read (hence the need for the 6 byte
real).

Much appreciated

 

Re:REAL (borland pascal 7) -> FLOAT or DOUBLE


In article <3B0C0583.6F9B7...@collins.rockwell.com>,
Ryan J. Hesseltine <rjhes...@collins.rockwell.com> wrote:

Quote

>The real problem is that I'm writing Perl code to generate the binary
>file that Pascal code will later read (hence the need for the 6 byte
>real).

TP can use the standard types: Single and Double. In fact you should use
them as they utilize the coprocessor fully.

Osmo

Re:REAL (borland pascal 7) -> FLOAT or DOUBLE


"Ryan J. Hesseltine" schreef:

Quote

> I need to know if anyone out there has ever had to deal with converting
> a 6 byte binary real (used in fixed-length binary record file) to either
> a 4-byte float or 8-byte double.

> I've found the format of the REAL type:
> Sign - Fraction - Exponent
> 1 bit - 39 bits   - 8 bits

> I thought I could pad with leading or trailing zeros to come up with the
> double format, but haven't had any luck yet.

> The real problem is that I'm writing Perl code to generate the binary
> file that Pascal code will later read (hence the need for the 6 byte
> real).

> Much appreciated

Hope this helps:

I don't know about Perl, but you can use typecasting in TP:

program convert_real;
{$N+, $E+}
var r:real;
    d:double;

begin
  d:=double(r);
end.

Greetings. Huub.

Re:REAL (borland pascal 7) -> FLOAT or DOUBLE


"Ryan J. Hesseltine" schreef:

Quote

> I need to know if anyone out there has ever had to deal with converting
> a 6 byte binary real (used in fixed-length binary record file) to either
> a 4-byte float or 8-byte double.

> I've found the format of the REAL type:
> Sign - Fraction - Exponent
> 1 bit - 39 bits   - 8 bits

> I thought I could pad with leading or trailing zeros to come up with the
> double format, but haven't had any luck yet.

> The real problem is that I'm writing Perl code to generate the binary
> file that Pascal code will later read (hence the need for the 6 byte
> real).

> Much appreciated

Hope this helps:

I don't know about Perl, but you can use typecasting in TP:

program convert_real;
{$N+, $E+}
var r:real;
    d:double;

begin
  d:=double(r);
end.

Greetings. Huub.

Re:REAL (borland pascal 7) -> FLOAT or DOUBLE


"Ryan J. Hesseltine" schreef:

Quote

> I need to know if anyone out there has ever had to deal with converting
> a 6 byte binary real (used in fixed-length binary record file) to either
> a 4-byte float or 8-byte double.

> I've found the format of the REAL type:
> Sign - Fraction - Exponent
> 1 bit - 39 bits   - 8 bits

> I thought I could pad with leading or trailing zeros to come up with the
> double format, but haven't had any luck yet.

> The real problem is that I'm writing Perl code to generate the binary
> file that Pascal code will later read (hence the need for the 6 byte
> real).

> Much appreciated

Hope this helps:

I don't know about Perl, but you can use typecasting in TP:

program convert_real;
{$N+, $E+}
var r:real;
    d:double;

begin
  d:=double(r);
end.

Greetings. Huub.

Re:REAL (borland pascal 7) -> FLOAT or DOUBLE


Huub van Dooren <hvdoo...@iae.nl> wrote:

Quote
>> I need to know if anyone out there has ever had to deal with converting
>> a 6 byte binary real (used in fixed-length binary record file) to either
>> a 4-byte float or 8-byte double.
>program convert_real;
>{$N+, $E+}
>var r:real;
>    d:double;

>begin
>  d:=double(r);
>end.

That won't do it!  Just use d := r;

Re:REAL (borland pascal 7) -> FLOAT or DOUBLE


I have no choice about the types I'm using in Pascal.  I HAVE to use a
6-byte real representation.  I'm writing to a binary file that a fixed
pascal program will read.
Quote
Osmo Ronkanen wrote:
> In article <3B0C0583.6F9B7...@collins.rockwell.com>,
> Ryan J. Hesseltine <rjhes...@collins.rockwell.com> wrote:

> >The real problem is that I'm writing Perl code to generate the binary
> >file that Pascal code will later read (hence the need for the 6 byte
> >real).

> TP can use the standard types: Single and Double. In fact you should use
> them as they utilize the coprocessor fully.

> Osmo

Re:REAL (borland pascal 7) -> FLOAT or DOUBLE


Quote
"Ryan J. Hesseltine" wrote:

> I need to know if anyone out there has ever had to deal with converting
> a 6 byte binary real (used in fixed-length binary record file) to either
> a 4-byte float or 8-byte double.

> I've found the format of the REAL type:
> Sign - Fraction - Exponent
> 1 bit - 39 bits   - 8 bits

> I thought I could pad with leading or trailing zeros to come up with the
> double format, but haven't had any luck yet.
> ...

No. The way a double is stored is completely different than a 6 byte
real.
Double:
| s | e | f |
| 1 | 11 | 52 |
    msb       lsb

Real: As above
| s | f | e|
| 1 | 39 | 8 |
    msb      lsb

Single:
| s | e | f |
| 1 | 11 | 52 |
    msb       lsb

Assuming your problem is to take a double in Perl and convert it to a
6 byte real (since I know nothing of Perl I don't know if you can do
this in Perl)

D = double to be converted. w is a word size variable.

1. Create a six byte buffer(B), all bits zeroed.
2. move the sign bit of D into the most significant bit of B.
3. Store the next eleven bits in a word w (to be used later).
4. move 39 of the next 52 bits into the next 39 bits of B from msb to
lsb.
5. w := w - 1023 + 127   There are special things that happen if w = 0
or 255.
   if w > 255 the conversion is invalid. To find out look up IEEE
number
   types.
6. Copy the 8 least significant bits of w to the 8 least significant
bits of
   B, keeping the bits in the same order.

This should work of course you will have to test it.

Regards, Hanford

Re:REAL (borland pascal 7) -> FLOAT or DOUBLE


JRS:  In article <3B0C0583.6F9B7...@collins.rockwell.com>, seen in
news:comp.lang.pascal.borland, Ryan J. Hesseltine <rjhes...@collins.rock
well.com> wrote at Wed, 23 May 2001 13:46:27 :-

Quote
>I need to know if anyone out there has ever had to deal with converting
>a 6 byte binary real (used in fixed-length binary record file) to either
>a 4-byte float or 8-byte double.

>I've found the format of the REAL type:
>Sign - Fraction - Exponent
>1 bit - 39 bits   - 8 bits

>I thought I could pad with leading or trailing zeros to come up with the
>double format, but haven't had any luck yet.

>The real problem is that I'm writing Perl code to generate the binary
>file that Pascal code will later read (hence the need for the 6 byte
>real).

You should (almost) never use the 6-byte real type.  You should I think
be able to generate any of the other formats without much difficulty;
choose according to the resolution required.

See <URL: http://www.merlyn.demon.co.uk/pas-real.htm> etc.

Pedt: perhaps the mFAQ should have an anti-real remark.

TSFAQP#133 refers; but, while the anchor given therein,
http://www.merlyn.demon.co.uk/pas-real.htm#FloatTypes, is still valid
and IMHO appropriate, the table itself is now in pas-type.htm  (Timo :
simplest to change "at" to "via" in the line immediately after your
table.)

--
? John Stockton, Surrey, UK.  j...@merlyn.demon.co.uk   Turnpike v4.00   MIME. ?
 <URL: http://www.merlyn.demon.co.uk/> TP/BP/Delphi/&c., FAQqy topics & links;
 <URL: http://www.merlyn.demon.co.uk/clpb-faq.txt> Pedt Scragg: c.l.p.b. mFAQ;
 <URL: ftp://garbo.uwasa.fi/pc/link/tsfaqp.zip> Timo Salmi's Turbo Pascal FAQ.

Re:REAL (borland pascal 7) -> FLOAT or DOUBLE


In article <3B0D2EE8.A8C01...@collins.rockwell.com>,
Ryan J. Hesseltine <rjhes...@collins.rockwell.com> wrote:

Quote
>I have no choice about the types I'm using in Pascal.  I HAVE to use a
>6-byte real representation.  I'm writing to a binary file that a fixed
>pascal program will read.

You mean you do not have source for the TP program?

Osmo

Re:REAL (borland pascal 7) -> FLOAT or DOUBLE


Dr John Stockton <s...@merlyn.demon.co.uk> said the following:
Quote
>JRS:  In article <3B0C0583.6F9B7...@collins.rockwell.com>, seen in
[..]

>Pedt: perhaps the mFAQ should have an anti-real remark.

Noted.

--
Pedt

Other Threads