Subject: Re: DEC single precision format

From: [email-masked] (Marcelino Bernardo)
Date: Mon, 19 Jul 1993 16:12:51 GMT

In article <[email-masked]>, [email-masked] (Steven
Intolubbe) wrote:
> 
> I am trying to make some DEC formatted single and double
> precision floating point numbers usable on the Macintosh.
> Can anyone tell me what the structure of DEC floating point
> numbers is?
> 

Here's a code I wrote to convert single precision DEC (real*4) to Mac IEEE
488 (float).

/*	afloat = FixVaxFloat(arealnum, dec2Mac)

	Fixes Dec's float format to IEEE float by Swapping bytes 0 and 1,
	and 2 and 3 of a float and dividing by 4.

*/

void FixVaxFloat(float *avaxnum, Boolean dec2Mac)

{
	char tmpchr;
	char *charPtr;
	charPtr = (char *) avaxnum;
	
	if (!dec2Mac) *avaxnum *= 4;	/* this is a conversion from Mac to Dec	*/
	tmpchr = *charPtr;
	*charPtr = *(charPtr+1);
	*(charPtr+1) = tmpchr;
	tmpchr = *(charPtr+2);
	*(charPtr+2) = *(charPtr+3);
	*(charPtr+3) = tmpchr;
	if (dec2Mac) *avaxnum /= 4;		/* this is a conversion from Dec to Mac	*/
}

Marcelino Bernardo    /* Views expressed are mine, not Exxon's. */
[email-masked]

---

From: [email-masked] (Quincey Koziol)
Date: Sat, 17 Jul 1993 21:56:05 GMT

In article <[email-masked]> [email-masked] (Steven Intolubbe) writes:
>				       Thanks,
>				       Steve

Take a look at the number conversion routines in NCSA's HDF library.
They can convert from any of six different machine architechtures to
little and big-endian IEEE floating point numbers (the Mac is a big-endian
IEEE floating point machine).  HDF is located on: ftp.ncsa.uiuc.edu,
in the /HDF directory.

	Quincey Koziol
	HDF Developer
	[email-masked]

---

From: [email-masked] (Joe Smith)
Date: 20 Jul 93 01:13:31 GMT

In article <[email-masked]> [email-masked] (Steven Intolubbe) writes:

>I am trying to make some DEC formatted single and double precision floating
>point numbers usable on the Macintosh.  Can anyone tell me what the
>structure of DEC floating point numbers is?

		"Ambiguous question; insufficient data."

Single precision numbers have the sign bit in bit 0, an excess-128 exponent
in bits 1-8, and a 27-bit mantisa in bits 9 through 35, for a range of
1.5E-39 to 1.7E+38.  (The high-order bit of the mantissa is always on, except
for unnormalized numbers or zero, which means that same instructions can be
used to compare integer and floating point numbers.)  Double precision
numbers use a second 36-bit word, in which bit 0 is always zero and bits
1-35 extend the mantissa to 62 bits (over 18 decimal digits).

For KL10 systems running microcode version 271 or greater, the extended-range
"G format" numbers use bits 1-11 for an excess 1024 exponent, bits 12-35
and 1-35 for a 59-bit mantissa, and have range of 2.8E-308 to 9.0E+309.

DEC's lesser powered computers have formats that differ from the PDP-10.
You'll have to ask someone else about the PDP-11 "F" and "D" formats, or the
VAX "G" format.  Not to mention the IEEE format that DEC workstations use.

-- 
Joe Smith (408)922-6220     BTNA GNS Major Programs, TYMNET Global Network
<[email-masked]>     P.O. Box 49019, MS-C51, San Jose, CA 95161-9019
CA license plate: "POPJ P,"    Married to the LB, Quantum Leap's #1 net.fan
PDP-10, 36-bits forever!    Humorous disclaimer: "My Amiga 3000 speaks for me."

---

From: [email-masked] (Peter G. Ford)
Date: 20 Jul 1993 04:59:52 GMT

>structure of DEC floating point numbers is?

The most usual DEC float formats are the VAX F- and D-type fields,
but there are several others.  Here's the information on F and D:

4-byte (float) F-type:

 0 1       8 9                        31      <-- bit number
+-+-------+-+-------+---------+---------+
| |  [1]  | |  [0]  |   [3]   |   [2]   |     <-- byte number
+-+-------+-+-------+---------+---------+

8-byte (double) D-type:

 0 1       8 9                        31      <-- bit number
+-+-------+-+-------+---------+---------+
| |  [1]  | |  [0]  |   [3]   |   [2]   |     <-- byte number
+-+-------+-+-------+---------+---------+
       32                                   63    <-- bit number (contd)
      +---------+---------+---------+---------+
      |   [5]   |   [4]   |   [7]   |   [6]   |   <-- byte number (contd)
      +---------+---------+---------+---------+

VAX single- (double-) precision F-type (D-type) floating point numbers
are stored in four (eight) consecutive bytes.  Bit number 0 contains a
sign indicator, S.  Bits 1 through 8 contain a binary exponent, E.  The
significance increases from bit 8 through bit 1.  Bits 9 through 31
(63) contain a mantissa M, a 23-bit (55-bit) binary fraction whose
binary point lies immediately to the left of bit 9.  The significance
increases from bit 31 (63) through bit 9.  The value of the field is
given by

                              S    E-129
                          (-1)  * 2      * (1+M)

The numbers are stored externally in increasing byte-number order, i.e.
[0], [1], etc.  For example, the float value +1.0 is stored as four
bytes valued 0x80, 0x40, 0x00, 0x00.

NOTE: when comparing this definition with some that have been posted in
response to your thread, you should be warned about some replies from
DEC users, since they often forget that their manuals gloss over the
distinction between bit and byte order on big-endian machines; for
instance, the sign bit (bit 0) is located in the SECOND byte of the 4-
or 8-byte field.

Peter Ford
<[email-masked]>