[Coco] Convert floating point formats

Walter Zambotti zambotti at iinet.net.au
Tue Aug 20 19:55:22 EDT 2019


My manual says:

This compiler follows the PDP-1 implementation and format in that CHARs are converted to INTs by sign extension, "SHORT" or "SHORT INT"
means INT, "LONG INT" means LONG, and "LONG FLOAT" means DOUBLE. The format of DOUBLE values is as follows:

-----Original Message-----
From: Coco [mailto:coco-bounces at maltedmedia.com] On Behalf Of Alex Evans
Sent: Wednesday, 21 August 2019 6:22 AM
To: CoCoList for Color Computer Enthusiasts <coco at maltedmedia.com>
Subject: Re: [Coco] Convert floating point formats

The OS-9 C Compiler Manual page 1-5

This compiler follows the PDP-11 implementation and format in that CHARs are converted to INTs by sign extension, "SHORT" or "SHORT INT"
means INT, "LONG INT" means LONG, and "LONG FLOAT" means DOUBLE. The format of DOUBLE values is as follows:

<figure removed>

The form of the mantissa is sign and magnitude with an implied "1" bit at the sign bit position. The exponent is biased by 128. The format of the FLOAT is identical, except that the mantissa is only three bytes long. Conversion from DOUBLE to FLOAT is carried out by truncating the least significant (right-most) four bytes of the mantissa. The reverse conversion is done by padding the least significant our mantissa bytes with zeros.

On Tue, Aug 20, 2019 at 6:25 AM Joel Rees <joel.rees at gmail.com> wrote:
>
> 2019年8月20日(火) 17:02 Walter Zambotti <zambotti at iinet.net.au>:
>
> > Not sure why it is PDP1 but that is how it is documented in the C manual!
> >
>
> Which C manual?
>
>
> > Walter
> >
> > -----Original Message-----
> > From: Coco [mailto:coco-bounces at maltedmedia.com] On Behalf Of James 
> > Jones
> > Sent: Tuesday, 20 August 2019 12:13 PM
> > To: CoCoList for Color Computer Enthusiasts <coco at maltedmedia.com>
> > Subject: Re: [Coco] Convert floating point formats
> >
> > I'm a little confused by the name PDP1data; the PDP-1 had an 18-bit 
> > word, did one's complement arithmetic, and the floating point 
> > library referenced in 
> > https://web.archive.org/web/20110514105011/http://www.dbit.com/~gree
> > ng3/pdp1/pdp1.html
> > used
> > two words for a value, with one word for mantissa (and presumably 
> > sign
> > bit) and one for the exponent.
> >
> > On Tue, Aug 13, 2019 at 11:12 PM Walter Zambotti 
> > <zambotti at iinet.net.au>
> > wrote:
> >
> > > Here is the PC side code that I ended up making to convert CoCo 
> > > OS9 C
> > > PDP1 floating point numbers to modern PC IEEE754 floating point 
> > > and visa
> > versa.
> > >
> > > union _Data
> > > {
> > >   unsigned long long llval;
> > >   double dval;
> > >   unsigned int lval;
> > >   unsigned char bytes[8];
> > >   unsigned short words[4];
> > >   unsigned int dwords[2];
> > > };
> > >
> > > typedef union _Data PDP1data;
> > > typedef union _Data IEEE754data;
> > >
> > > double ConvertDBLPDP1toIEEE754(PDP1data PDP1data) {
> > >         IEEE754data iee754;
> > >         unsigned long long signbit, exp, mantissa;
> > >
> > >         if (PDP1data.llval == 0)
> > >         {
> > >                 return 0.0;
> > >         }
> > >
> > >         signbit  =  PDP1data.llval & 0x8000000000000000;
> > >         exp  = (PDP1data.llval & 0x00000000000000ff) + 0x37e;
> > >         mantissa =  PDP1data.llval & 0x7fffffffffffff00;
> > >
> > >         iee754.llval = signbit | (exp<<52) | (mantissa>>11);
> > >
> > >         return iee754.dval;
> > > }
> > >
> > > PDP1data ConvertDblIEEE754toPDP1(double dvalue) {
> > >         PDP1data PDP1data;
> > >         IEEE754data IEEE754data;
> > >         unsigned long long signbit, exp, mantissa;
> > >
> > >         IEEE754data.dval = dvalue;
> > >
> > >         // IEEE floats can have a negative zero that PDP1 floats 
> > > cannot have
> > >         // if the value is zero then we make it a good zero
> > >
> > >         if (IEEE754data.dval == 0.0)
> > >         {
> > >                 IEEE754data.llval = 0;
> > >                 return IEEE754data;
> > >         }
> > >
> > >         signbit  =   IEEE754data.llval & 0x8000000000000000;
> > >         exp   = ((IEEE754data.llval & 0x7ff0000000000000)>>52) - 0x37e;
> > >         mantissa =   IEEE754data.llval & 0x000fffffffffffff;
> > >
> > >         PDP1data.llval = signbit | (exp) | (mantissa<<11);
> > >
> > >         return PDP1data;
> > > }
> > >
> > > -----Original Message-----
> > > From: Coco [mailto:coco-bounces at maltedmedia.com] On Behalf Of 
> > > James Jones
> > > Sent: Thursday, 4 July 2019 7:38 PM
> > > To: CoCoList for Color Computer Enthusiasts <coco at maltedmedia.com>
> > > Subject: Re: [Coco] Convert floating point formats
> > >
> > > On Fri, May 24, 2019 at 9:30 AM Alex Evans <varmfskii at gmail.com> wrote:
> > >
> > > > I don't have a line to a particular solution (though they should 
> > > > be easy to implement), but do you mean IEEE double precision as 
> > > > is used on current x86 CPUs, or are you saying that there was 
> > > > some other floating point format used by x86 FPUs such as the 
> > > > 8087 sometime in the past that you are interested in converting 
> > > > to/from. I also was under the impression that the Microware C 
> > > > Compiler used IEEE floating point in which case no conversion 
> > > > needs to be made, it is already in the right format.
> > > >
> > >
> > > The switch to IEEE 754 floating point came with OS-9/68000.
> > >
> > > --
> > > Coco mailing list
> > > Coco at maltedmedia.com
> > > https://pairlist5.pair.net/mailman/listinfo/coco
> > >
> > >
> > > --
> > > Coco mailing list
> > > Coco at maltedmedia.com
> > > https://pairlist5.pair.net/mailman/listinfo/coco
> > >
> >
> > --
> > Coco mailing list
> > Coco at maltedmedia.com
> > https://pairlist5.pair.net/mailman/listinfo/coco
> >
> >
> > --
> > Coco mailing list
> > Coco at maltedmedia.com
> > https://pairlist5.pair.net/mailman/listinfo/coco
> >
>
> --
> Coco mailing list
> Coco at maltedmedia.com
> https://pairlist5.pair.net/mailman/listinfo/coco

--
Coco mailing list
Coco at maltedmedia.com
https://pairlist5.pair.net/mailman/listinfo/coco



More information about the Coco mailing list