Convert single precision to double precision 
Author Message
 Convert single precision to double precision

How can I simply convert a float(single precision) into a double(double
precision).
I know I can load a float in the FPU, but if the precision of the FPU is
double, the value isn't correct.
(0.300000(single precision) isn't 0.300000 in double precision, but
something like 0.300001292)

My processor isn't capable of SSE2 instructions.
(SSE2 has instructions for converting from single to double and back again)

Thanks in advance.



Fri, 04 Nov 2005 00:57:50 GMT  
 Convert single precision to double precision
fld dword ptr [flt]
fstp qword ptr [dbl]

Converts from float to double.. However it doesn't solve the precision
problem.

So you could do like this:

fld dword ptr [flt]
fimul dword ptr [mult];
frndint
fidiv dword ptr [mult]
fstp qword ptr [dbl]

"mult" is a large int value (10,000,000 or something). This thing works nice
for your 0.3000 example, and is at least exact for most low values (under 10
or something, didn't really test but when I tested with 333.313 or whatever
it was off a bit..)
It's a hack but it could work if you really need to have exactly
0.3000000000 :)

/Nico


| How can I simply convert a float(single precision) into a double(double
| precision).
| I know I can load a float in the FPU, but if the precision of the FPU is
| double, the value isn't correct.
| (0.300000(single precision) isn't 0.300000 in double precision, but
| something like 0.300001292)
|
| My processor isn't capable of SSE2 instructions.
| (SSE2 has instructions for converting from single to double and back
again)
|
| Thanks in advance.
|
|
|
|



Fri, 04 Nov 2005 03:46:27 GMT  
 Convert single precision to double precision

Quote:

> How can I simply convert a float(single precision) into a double(double
> precision).
> I know I can load a float in the FPU, but if the precision of the FPU is
> double, the value isn't correct.
> (0.300000(single precision) isn't 0.300000 in double precision, but
> something like 0.300001292)
> My processor isn't capable of SSE2 instructions.
> (SSE2 has instructions for converting from single to double and back again)
> Thanks in advance.

The problem is that 0.3 can not be represented exactly in binary
floating point. See the chapter on floating-point math in my tutorial
for the details.

http://www.drpaulcarter.com/pcasm/

--
Paul Carter



Fri, 04 Nov 2005 06:01:29 GMT  
 Convert single precision to double precision
A very interesting document indeed!


Quote:

> > How can I simply convert a float(single precision) into a double(double
> > precision).
> > I know I can load a float in the FPU, but if the precision of the FPU is
> > double, the value isn't correct.
> > (0.300000(single precision) isn't 0.300000 in double precision, but
> > something like 0.300001292)

> > My processor isn't capable of SSE2 instructions.
> > (SSE2 has instructions for converting from single to double and back
again)

> > Thanks in advance.

> The problem is that 0.3 can not be represented exactly in binary
> floating point. See the chapter on floating-point math in my tutorial
> for the details.

> http://www.drpaulcarter.com/pcasm/

> --
> Paul Carter



Fri, 04 Nov 2005 14:13:00 GMT  
 
 [ 4 post ] 

 Relevant Pages 

1. double precision vs. single precision

2. single precision or double precision?

3. Double precision runs fast tan single precision in MS Fortran

4. converting double to single precision

5. Converting code from single to double precision

6. HP Fortran question: precision of double-precision?

7. Single and double precision versions of IMSL routines give different

8. Single and double precision versions of IMSL routines give different results

9. Single / Double Precision Issue

10. single/double precision

11. Single to double precision

12. double precision skiped to single ?

 

 
Powered by phpBB® Forum Software