- Marcar como nuevo
- Favorito
- Suscribir
- Silenciar
- Suscribirse a un feed RSS
- Resaltar
- Imprimir
- Informe de contenido inapropiado
Dear All,
I have a problem with a real number conversion. I would like to convert a single precision real number into a double precision. I wrote a simple program which uses DBLE() function.
% cat conversion.f
program conversion
real(4) sx1
real(8) dx1
sx1=1.000010
dx1=dble(sx1)
write(*,*) sx1,dx1
end
When I run the program I get the following result:
% ./conversion
1.000010 1.00001001358032
I wish that the result of conversion is 1.00001000000000 (or perhaps 1.00001000000001 or. 1.00000999999999).
With Best Regards,
Zoran
- Etiquetas:
- Intel® Fortran Compiler
Enlace copiado
- Marcar como nuevo
- Favorito
- Suscribir
- Silenciar
- Suscribirse a un feed RSS
- Resaltar
- Imprimir
- Informe de contenido inapropiado
dx1 = 1.00001d0
The conversion you have written performs an exact binary extension. As 1.00001d0 is not exactly representable in single precision, it is different from 1.00001, as you showed.
- Marcar como nuevo
- Favorito
- Suscribir
- Silenciar
- Suscribirse a un feed RSS
- Resaltar
- Imprimir
- Informe de contenido inapropiado
Dear Tim,
thanks for the answer. Yes, I was serious with this question, but I was thinking decimaly and not binary :-) .
Here is the listing of the expanded test:
% cat conversion.f
program conversion
real(4) sx1
real(8) dx1
character string*15
sx1=1.00001
dx1=dble(sx1)
write(*,*) sx1,dx1
write(string,*) sx1
read(string,*) dx1
write(*,*) sx1,dx1
end
% ./conversion
1.000010 1.00001001358032
1.000010 1.00001000000000
Regards, Zoran
- Marcar como nuevo
- Favorito
- Suscribir
- Silenciar
- Suscribirse a un feed RSS
- Resaltar
- Imprimir
- Informe de contenido inapropiado

- Suscribirse a un feed RSS
- Marcar tema como nuevo
- Marcar tema como leído
- Flotar este Tema para el usuario actual
- Favorito
- Suscribir
- Página de impresión sencilla