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

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