[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [oc] How to convert integer to single precision floating point



Thanks for clearing that up. The reason I mentioned this technique is I used
this technique 25 years ago in FORTRAN II for a fast conversion from integer
to floating point. This worked because in it's format the msb was present.

However note now the same technique can be used by changing the constent of
the dummy add.

    float    fixup = 2.^32;
    ...
    float result = *yourFPresult - fixup;
    ...

However, in reading (but not fully understanding)
http://http.cs.berkeley.edu/~wkahan/ieee754status/IEEE754.PDF


I found http://www.cs.umass.edu/~weems/CmpSci535/535lecture6.html
interesting as well.

The original question left too many particulars out to answer properly.

Jim

----- Original Message -----
From: "Rudolf Usselmann" <rudi@asics.ws>
To: <cores@opencores.org>
Sent: Friday, August 15, 2003 2:00 PM
Subject: Re: [oc] How to convert integer to single precision floating point


> On Sat, 2003-08-16 at 00:14, Jim Dempsey wrote:
> > The easest way is to copy the 32-bit number into the Mantissa (the
number
> > part) and then set the exponent to 32. The resultant number is not
> > normalized but this should not present you with a problem. On next
> > compuation the result will be normalized. If there is a possibility that
> > this technique would result in a roundoff error (it shouldn't as there
is no
> > real fraction) then processing section (in the C code that may be
running
> > inside or outside your FPGA) do something seemingly benign
> >
> >     float result = *yourFPresult + 0.;
> >
> > Requires compiler optimizatons are off.
> >
> > Jim
>
> Actually this will not quite work. If the exponent is
> non zero, the mantissa is expected to have a hidden bit.
>
> So you really have to shift the integer left until the
> first '1' falls out, and than adjust the exponent
> appropriately.
>
> Further, to be IEEE754 compliant, you will have to
> do rounding, as you can end up with more bits in the
> mantissa than you can represent in a 32 bit float.
>
> Regards,
> rudi
> --------------------------------------------------------
> www.asics.ws  --- Solutions for your ASIC/FPGA needs ---
> ----------------- FPGAs * Full Custom ICs * IP Cores ---
> FREE IP Cores --> http://www.asics.ws/ <-- FREE IP Cores
>
> --
> To unsubscribe from cores mailing list please visit
http://www.opencores.org/mailinglists.shtml

--
To unsubscribe from cores mailing list please visit http://www.opencores.org/mailinglists.shtml